File: vector.c

package info (click to toggle)
hercules 2.17.1-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,972 kB
  • ctags: 10,281
  • sloc: ansic: 89,345; sh: 3,874; makefile: 456; yacc: 316; sed: 16
file content (932 lines) | stat: -rw-r--r-- 26,647 bytes parent folder | download
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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
/* vector.c     S/370 and ESA/390 Vector Operations                  */

/*-------------------------------------------------------------------*/
/* This module implements the Vector Facility instruction execution  */
/* function of the S/370 and ESA/390 architectures, as described in  */
/* SA22-7125-03 Vector Operations (S/370 & ESA/370)                  */
/* SA22-7207-00 Vector Operations (ESA/390)                          */
/*                                             28/05/2000 Jan Jaeger */
/*                                                                   */
/* Instruction decoding rework                 09/07/2000 Jan Jaeger */
/* Interpretive Execution - (c) Copyright Jan Jaeger, 1999-2003      */
/* z/Architecture support - (c) Copyright Jan Jaeger, 1999-2003      */
/*-------------------------------------------------------------------*/

#include "hercules.h"

#include "opcode.h"

#include "inline.h"

#if defined(FEATURE_VECTOR_FACILITY)

/* The vector save area must be aligned on a boundary 8 times the 
   section size, however VM stores at 4 times the section size.
   I do not know if the book or VM is wrong.                     *JJ */
#define VSA_ALIGN       4

/*-------------------------------------------------------------------*/
/* A640 VTVM  - Test VMR                                       [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_test_vmr)
{
int     unused1, unused2;
U32     n, n1;

    RRE(inst, execflag, regs, unused1, unused2);

    VOP_CHECK(regs);
        
    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* cc0 when the vector count is zero */
    if( n == 0)
    {
        regs->psw.cc = 0;
        return;
    }

    /* Preset condition code according to first bit */
    regs->psw.cc = VMR_SET(0, regs) ? 3 : 0;

    /* Check VMR bit to be equal to the first, 
       exit with cc1 if an unequal bit found */
    for(n1 = 1; n1 < n; n1++)
        if((regs->psw.cc == 0) != (VMR_SET(n1, regs) == 0))
        {
            regs->psw.cc = 1;
            return;
        }

}


/*-------------------------------------------------------------------*/
/* A641 VCVM  - Complement VMR                                 [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_complement_vmr)
{
int     unused1, unused2;
U32     n, n1, n2;

    RRE(inst, execflag, regs, unused1, unused2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* Bytes - 1 */
    n1 = n >> 3; 

    /* Complement VMR */
    for(n2 = 0; n2 <= n1; n2++)
        regs->vf->vmr[n2] ^= 0xFF;
    
    /* zeroize remainder */
    regs->vf->vmr[n1] &= 0x7F00 >> (n & 7);
    for(n1++; n1 < sizeof(regs->vf->vmr); n1++)
        regs->vf->vmr[n1] = 0;

}


/*-------------------------------------------------------------------*/
/* A642 VCZVM - Count Left Zeros in VMR                        [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_count_left_zeros_in_vmr)
{
int     gr1, unused2;
U32     n, n1;

    RRE(inst, execflag, regs, gr1, unused2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* cc0 when the vector count is zero */
    if( n == 0)
    {
        regs->psw.cc = 0;
        return;
    }
    
    /* Preset condition code according to first bit */
    regs->psw.cc = VMR_SET(0, regs) ? 3 : 0;

    /* If the VCT is 1 and the first bit is one
       then exit wirh gr1 set to zero */
    regs->GR_L(gr1) = 0;
    if(n == 1 && VMR_SET(0, regs))
        return;

    /* Count left zeros, set cc1 and exit if a one is found */
    regs->GR_L(gr1) = 1;
    for(n1 = 1; n1 < n; n1++)
    {
        if(!VMR_SET(n1, regs))
            regs->GR_L(gr1)++;
        else
        {
            regs->psw.cc = 1;
            return;
        }
    }

}


/*-------------------------------------------------------------------*/
/* A643 VCOVM - Count Ones In VMR                              [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_count_ones_in_vmr)
{
int     gr1, unused2;
U32     n, n1;

    RRE(inst, execflag, regs, gr1, unused2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* cc0 when the vector count is zero */
    if( n == 0)
    {
        regs->psw.cc = 0;
        return;
    }
    
    /* Preset condition code according to first bit */
    regs->psw.cc = VMR_SET(0, regs) ? 3 : 0;

    /* Check VMR bit to be equal to the first, 
       Count all ones, set cc1 if a bit is unequal */
    regs->GR_L(gr1) = 0;
    for(n1 = 0; n1 < n; n1++)
    {
        if(VMR_SET(n1, regs))
        {
            regs->GR_L(gr1)++;
            if(!VMR_SET(0, regs))
                regs->psw.cc = 1;
        }
        else
            if(VMR_SET(0, regs))
                regs->psw.cc = 1;
    }

}


/*-------------------------------------------------------------------*/
/* A644 VXVC  - Exctract VCT                                   [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_extract_vct)
{
int     gr1, unused2;

    RRE(inst, execflag, regs, gr1, unused2);

    VOP_CHECK(regs);

    regs->GR_L(gr1) = VECTOR_COUNT(regs);

}


/*-------------------------------------------------------------------*/
/* A646 VXVMM - Extract Vector Modes                           [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_extract_vector_modes)
{
int     gr1, unused2;

    RRE(inst, execflag, regs, gr1, unused2);

    VOP_CHECK(regs);

    regs->GR_L(gr1) = (regs->vf->vsr >> 48);

}


/*-------------------------------------------------------------------*/
/* A648 VRRS  - Restore VR                                     [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_restore_vr)
{
int     gr1, unused2;
U32     n, n1, n2;
U64     d;

    RRE(inst, execflag, regs, gr1, unused2);

    VOP_CHECK(regs);
        
    ODD_CHECK(gr1, regs);

    /* n contrains the current save area address */
    n = regs->GR_L(gr1) & ADDRESS_MAXWRAP(regs);

    /* n1 contains the starting element number */
    if((n1 = regs->GR_L(gr1 + 1) >> 16) >= VECTOR_SECTION_SIZE)
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    /* Starting address must be eight times the section size aligned */
    if((n - (8 * n1)) & ((VECTOR_SECTION_SIZE * VSA_ALIGN) - 1) )
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    /* n2 contains VR pair, which must be an even reg */
    if((n2 = regs->GR_L(gr1 + 1) & 0x0000FFFF) & 0x0000FFF1)
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    if( VR_INUSE(n2, regs) )
    {
        /* Set the vector changed bit if in problem state */
        if( regs->psw.prob )
            SET_VR_CHANGED(n2, regs);

        for(; n1 < VECTOR_SECTION_SIZE; n1++)
        {
            /* Fetch vr pair from central storage */
            d = ARCH_DEP(vfetch8)(n, gr1, regs);    
            regs->vf->vr[n2][n1] = d >> 32;
            regs->vf->vr[n2+1][n1] = d;

            /* Increment element number */
            n1++;
            regs->GR_L(gr1 + 1) &= 0x0000FFFF;
            regs->GR_L(gr1 + 1) |= n1 << 16;
            /* Update savearea address */
            regs->GR_L(gr1) += 8;
#if 0
            /* This is where the instruction may be interrupted */
            regs->psw.IA -= regs->psw.ilc;
            return;
#endif
        }

        /* Indicate vr pair restored */
        regs->psw.cc = 2;
    }
    else
    {
        regs->GR_L(gr1) += 8 * (VECTOR_SECTION_SIZE - n1);
        /* indicate v2 pair not restored */
        regs->psw.cc = 0;
    }

    /* Set CC2 if vr 14 is restored, CC0 if not restored, 
       CC3 and CC1 for other VR's respectively */
    if(n2 != 14) regs->psw.cc++;

    /* Update the vector pair number, and zero element number */
    n2 += 2;
    regs->GR_L(gr1 + 1) = n2;

}


/*-------------------------------------------------------------------*/
/* A649 VRSVC - Save Changed VR                                [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_save_changed_vr)
{
int     gr1, unused2;
U32     n, n1, n2;
U64     d;

    RRE(inst, execflag, regs, gr1, unused2);

    VOP_CHECK(regs);

    PRIV_CHECK(regs);

    ODD_CHECK(gr1, regs);

    /* n contrains the current save area address */
    n = regs->GR_L(gr1) & ADDRESS_MAXWRAP(regs);

    /* n1 contains the starting element number */
    if((n1 = regs->GR_L(gr1 + 1) >> 16) >= VECTOR_SECTION_SIZE)
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    /* Starting address must be eight times the section size aligned */
    if((n - (8 * n1)) & ((VECTOR_SECTION_SIZE * VSA_ALIGN) - 1) )
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    /* n2 contains VR pair, which must be an even reg */
    if((n2 = regs->GR_L(gr1 + 1) & 0x0000FFFF) & 0x0000FFF1)
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    if( VR_CHANGED(n2, regs) )
    {
        for(; n1 < VECTOR_SECTION_SIZE; n1++)
        {
            /* Store vr pair in savearea */
            d = ((U64)regs->vf->vr[n2][n1] << 32)
              | regs->vf->vr[n2+1][n1];
            ARCH_DEP(vstore8)(d, n, gr1, regs);    

            /* Update element number */
            n1++;
            regs->GR_L(gr1 + 1) &= 0x0000FFFF;
            regs->GR_L(gr1 + 1) |= n1 << 16;
            regs->GR_L(gr1) += 8;
#if 0
            /* This is where the instruction may be interrupted */
            regs->psw.IA -= regs->psw.ilc;
            return;
#endif
        }

        /* Indicate vr pair saved */
        regs->psw.cc = 2;

        /* Reset the VR changed bit */
        RESET_VR_CHANGED(n2, regs);
    }
    else
    {
        regs->GR_L(gr1) += 8 * (VECTOR_SECTION_SIZE - n1);
        /* vr pair not saved */
        regs->psw.cc = 0;
    }

    /* Set CC2 if vr 14 is restored, CC0 if not restored, 
       CC3 and CC1 for other VR's respectively */
    if(n2 != 14) regs->psw.cc++;

    /* Update the vector pair number, and zero element number */
    n2 += 2;
    regs->GR_L(gr1 + 1) = n2;

}


/*-------------------------------------------------------------------*/
/* A64A VRSV  - Save VR                                        [RRE] */
/*-------------------------------------------------------------------*/
DEF_INST(v_save_vr)
{
int     gr1, unused2;
U32     n, n1, n2;
U64     d;

    RRE(inst, execflag, regs, gr1, unused2);

    VOP_CHECK(regs);

    ODD_CHECK(gr1, regs);

    /* n contrains the current save area address */
    n = regs->GR_L(gr1) & ADDRESS_MAXWRAP(regs);

    /* n1 contains the starting element number */
    if((n1 = regs->GR_L(gr1 + 1) >> 16) >= VECTOR_SECTION_SIZE)
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    /* Starting address must be eight times the section size aligned */
    if((n - (8 * n1)) & ((VECTOR_SECTION_SIZE * VSA_ALIGN) - 1) )
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    /* n2 contains VR pair, which must be an even reg */
    if((n2 = regs->GR_L(gr1 + 1) & 0x0000FFFF) & 0x0000FFF1)
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);

    if( VR_INUSE(n2, regs) )
    {
        for(; n1 < VECTOR_SECTION_SIZE; n1++)
        {
            /* Store vr pair in savearea */
            d = ((U64)regs->vf->vr[n2][n1] << 32)
              | regs->vf->vr[n2+1][n1];
            ARCH_DEP(vstore8)(d, n, gr1, regs);    

            /* Update element number */
            n1++;
            regs->GR_L(gr1 + 1) &= 0x0000FFFF;
            regs->GR_L(gr1 + 1) |= n1 << 16;
            regs->GR_L(gr1) += 8;
#if 0
            /* This is where the instruction may be interrupted */
            regs->psw.IA -= regs->psw.ilc;
            return;
#endif
        }

        /* Indicate vr pair restored */
        regs->psw.cc = 2;
    }
    else
    {
        regs->GR_L(gr1) += 8 * (VECTOR_SECTION_SIZE - n1);
        /* Indicate vr pair not restored */
        regs->psw.cc = 0;
    }

    /* Set CC2 if vr 14 is restored, CC0 if not restored, 
       CC3 and CC1 for other VR's respectively */
    if(n2 != 14) regs->psw.cc++;

    /* Update the vector pair number, and zero element number */
    n2 += 2;
    regs->GR_L(gr1 + 1) = n2;

}


/*-------------------------------------------------------------------*/
/* A680 VLVM  - Load VMR                                        [VS] */
/*-------------------------------------------------------------------*/
DEF_INST(v_load_vmr)
{
int     rs2;
U32     n, n1;

    VS(inst, execflag, regs, rs2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);
    n1 = n >> 3; 

    ARCH_DEP(vfetchc)(regs->vf->vmr, n1,
        regs->GR_L(rs2) & ADDRESS_MAXWRAP(regs), rs2, regs);

    /* Set the inactive bits to zero */
    regs->vf->vmr[n1] &= 0x7F00 >> (n & 7);
    for(n1++; n1 < sizeof(regs->vf->vmr); n1++)
        regs->vf->vmr[n1] = 0;

}


/*-------------------------------------------------------------------*/
/* A681 VLCVM - Load VMR Complement                             [VS] */
/*-------------------------------------------------------------------*/
DEF_INST(v_load_vmr_complement)
{
int     rs2;
U32     n, n1, n2;

    VS(inst, execflag, regs, rs2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* Number of bytes - 1 */
    n1 = n >> 3; 

    ARCH_DEP(vfetchc)(regs->vf->vmr, n1,
        regs->GR_L(rs2) & ADDRESS_MAXWRAP(regs), rs2, regs);

    /* Complement all bits loaded */
    for(n2 = 0; n2 <= n1; n2++)
        regs->vf->vmr[n2] ^= 0xFF;

    /* Set the inactive bits to zero */
    regs->vf->vmr[n1] &= 0x7F00 >> (n & 7);
    for(n1++; n1 < sizeof(regs->vf->vmr); n1++)
        regs->vf->vmr[n1] = 0;

}


/*-------------------------------------------------------------------*/
/* A682 VSTVM - Store VMR                                       [VS] */
/*-------------------------------------------------------------------*/
DEF_INST(v_store_vmr)
{
int     rs2;
U32     n;

    VS(inst, execflag, regs, rs2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    ARCH_DEP(vstorec)(regs->vf->vmr, n >> 3,
            regs->GR_L(rs2) & ADDRESS_MAXWRAP(regs), rs2, regs);
    
}


/*-------------------------------------------------------------------*/
/* A684 VNVM  - AND To VMR                                      [VS] */
/*-------------------------------------------------------------------*/
DEF_INST(v_and_to_vmr)
{
int     rs2;
U32     n, n1, n2;
BYTE    workvmr[VECTOR_SECTION_SIZE/8];

    VS(inst, execflag, regs, rs2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* Number of bytes - 1 */
    n1 = n >> 3; 

    ARCH_DEP(vfetchc)(workvmr, n1,
        regs->GR_L(rs2) & ADDRESS_MAXWRAP(regs), rs2, regs);

    /* And VMR with workvmr */
    for(n2 = 0; n2 <= n1; n2++)
        regs->vf->vmr[n2] &= workvmr[n2];
    
    /* zeroize remainder */
    regs->vf->vmr[n1] &= 0x7F00 >> (n & 7);
    for(n1++; n1 < sizeof(regs->vf->vmr); n1++)
        regs->vf->vmr[n1] = 0;

}


/*-------------------------------------------------------------------*/
/* A685 VOVM  - OR To VMR                                       [VS] */
/*-------------------------------------------------------------------*/
DEF_INST(v_or_to_vmr)
{
int     rs2;
U32     n, n1, n2;
BYTE    workvmr[VECTOR_SECTION_SIZE/8];

    VS(inst, execflag, regs, rs2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* Number of bytes - 1 */
    n1 = n >> 3; 

    ARCH_DEP(vfetchc)(workvmr, n1,
        regs->GR_L(rs2) & ADDRESS_MAXWRAP(regs), rs2, regs);

    /* OR VMR with workvmr */
    for(n2 = 0; n2 <= n1; n2++)
        regs->vf->vmr[n2] |= workvmr[n2];
    
    /* zeroize remainder */
    regs->vf->vmr[n1] &= 0x7F00 >> (n & 7);
    for(n1++; n1 < sizeof(regs->vf->vmr); n1++)
        regs->vf->vmr[n1] = 0;

}


/*-------------------------------------------------------------------*/
/* A686 VXVM  - Exclusive OR To VMR                             [VS] */
/*-------------------------------------------------------------------*/
DEF_INST(v_exclusive_or_to_vmr)
{
int     rs2;
U32     n, n1, n2;
BYTE    workvmr[VECTOR_SECTION_SIZE/8];

    VS(inst, execflag, regs, rs2);

    VOP_CHECK(regs);

    /* Extract vector count (number of active bits in vmr) */
    n = VECTOR_COUNT(regs);

    /* Number of bytes - 1 */
    n1 = n >> 3; 

    ARCH_DEP(vfetchc)(workvmr, n1,
        regs->GR_L(rs2) & ADDRESS_MAXWRAP(regs), rs2, regs);

    /* OR VMR with workvmr */
    for(n2 = 0; n2 <= n1; n2++)
        regs->vf->vmr[n2] ^= workvmr[n2];
    
    /* zeroize remainder */
    regs->vf->vmr[n1] &= 0x7F00 >> (n & 7);
    for(n1++; n1 < sizeof(regs->vf->vmr); n1++)
        regs->vf->vmr[n1] = 0;

}


/*-------------------------------------------------------------------*/
/* A6C0 VSRSV - Save VSR                                         [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_save_vsr)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    DW_CHECK(effective_addr2, regs);

    ARCH_DEP(vstore8)(regs->vf->vsr, effective_addr2, b2, regs);
    
}


/*-------------------------------------------------------------------*/
/* A6C1 VMRSV - Save VMR                                         [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_save_vmr)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    ARCH_DEP(vstorec)(regs->vf->vmr, sizeof(regs->vf->vmr) - 1,
        effective_addr2, b2, regs);
    
}


/*-------------------------------------------------------------------*/
/* A6C2 VSRRS - Restore VSR                                      [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_restore_vsr)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */
U32     n1, n2;
U64     d;

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    DW_CHECK(effective_addr2, regs);

    /* Fetch operand */
    d = ARCH_DEP(vfetch8)(effective_addr2, b2, regs);

    /* Check for reserved bits nonzero,
       vector count not greater then section size and
       vector interruption index not greater then section size */
    if((d & VSR_RESV)
        || ((d & VSR_VCT) >> 32) > VECTOR_SECTION_SIZE 
        || ((d & VSR_VIX) >> 16) >= VECTOR_SECTION_SIZE)
        ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);
    
    /* In problem state the change bit are set corresponding
       the inuse bits */
    if(regs->psw.prob)
    {
        d &= ~VSR_VCH;
        d |= (d & VSR_VIU) >> 8;
    }

    /* Clear any VRs whose inuse bits are being set to zero */
    for(n1 = 0; n1 < 16; n1 += 2)
    {
        if( VR_INUSE(n1, regs)
            && !((d & VSR_VIU) & (VSR_VCH0 >> (n1 >> 1))) )
            for(n2 = 0; n2 < VECTOR_SECTION_SIZE; n2++)
            {
                regs->vf->vr[n1][n2] = 0;
                regs->vf->vr[n1+1][n2] = 0;
            }
    }

    /* Update the vector status register */
    regs->vf->vsr = d;

}


/*-------------------------------------------------------------------*/
/* A6C3 VMRRS - Restore VMR                                      [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_restore_vmr)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    ARCH_DEP(vfetchc)(regs->vf->vmr, sizeof(regs->vf->vmr) - 1,
        effective_addr2, b2, regs);
    
}


/*-------------------------------------------------------------------*/
/* A6C4 VLVCA - Load VCT from Address                            [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_load_vct_from_address)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */
U32     n;

    S_NW(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    regs->psw.cc = ((S32)effective_addr2 == 0) ? 0 :
                   ((S32)effective_addr2 < 0) ? 1 :
                   ((S32)effective_addr2 > VECTOR_SECTION_SIZE) ? 2 : 3;
           
    n = (S32)effective_addr2 < 0 ? 0 :
        (S32)effective_addr2 > VECTOR_SECTION_SIZE ? 
                 VECTOR_SECTION_SIZE : (S32)effective_addr2;

    regs->vf->vsr &= ~VSR_VCT;
    regs->vf->vsr |= (U64)n << 32;
    
}


/*-------------------------------------------------------------------*/
/* A6C5 VRCL  - Clear VR                                         [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_clear_vr)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */
U32     n, n1, n2;

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    /* Set vector interruption index to zero */
    regs->vf->vsr &= ~VSR_VIX;

    /* Clear vr's identified in the bit mask
       n1 contains the vr number   
       n2 contains the bitmask identifying the vr number
       n contains the element number */
    for(n1 = 0, n2 = 0x80; n1 <= 14; n1 += 2, n2 >>= 1)
        if(effective_addr2 & n2)
        {
            for(n = 0; n < VECTOR_SECTION_SIZE; n++)
            {
                regs->vf->vr[n1][n] = 0;
                regs->vf->vr[n1+1][n] = 0;
            }
            RESET_VR_INUSE(n1, regs);
        }

}


/*-------------------------------------------------------------------*/
/* A6C6 VSVMM - Set Vector Mask Mode                             [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_set_vector_mask_mode)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    if(effective_addr2 & 1)
        regs->vf->vsr |= VSR_M;
    else
        regs->vf->vsr &= ~VSR_M;

}


/*-------------------------------------------------------------------*/
/* A6C7 VLVXA - Load VIX from Address                            [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_load_vix_from_address)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */
U32     n;

    S_NW(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    regs->psw.cc = ((S32)effective_addr2 == 0) ? 0 :
                   ((S32)effective_addr2 < 0) ? 1 :
                   ((S32)effective_addr2 < VECTOR_COUNT(regs)) ? 2 : 3;
           
    n = (S32)effective_addr2 < 0 ? 0 :
        (S32)effective_addr2 > VECTOR_SECTION_SIZE ? 
                 VECTOR_SECTION_SIZE : (S32)effective_addr2;

    regs->vf->vsr &= ~VSR_VIX;
    regs->vf->vsr |= (U64)n << 16;
    
}


/*-------------------------------------------------------------------*/
/* A6C8 VSTVP - Store Vector Parameters                          [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_store_vector_parameters)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    FW_CHECK(effective_addr2, regs);

    /* Store the section size and partial sum number */
    ARCH_DEP(vstore4)(VECTOR_SECTION_SIZE << 16 | VECTOR_PARTIAL_SUM_NUMBER,
                                  effective_addr2, b2, regs);
    
}


/*-------------------------------------------------------------------*/
/* A6CA VACSV - Save VAC                                         [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_save_vac)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    PRIV_CHECK(regs);

    DW_CHECK(effective_addr2, regs);

#if defined(_FEATURE_SIE)
    if(regs->sie_state && (regs->siebk->ic[3] & SIE_IC3_VACSV))
        longjmp(regs->progjmp, SIE_INTERCEPT_INST);
#endif /*defined(_FEATURE_SIE)*/

    ARCH_DEP(vstore8)(regs->vf->vac, effective_addr2, b2, regs);
    
}


/*-------------------------------------------------------------------*/
/* A6CB VACRS - Restore VAC                                      [S] */
/*-------------------------------------------------------------------*/
DEF_INST(v_restore_vac)
{
int     b2;                             /* Base of effective addr    */
VADR    effective_addr2;                /* Effective address         */

    S(inst, execflag, regs, b2, effective_addr2);

    VOP_CHECK(regs);

    PRIV_CHECK(regs);

    DW_CHECK(effective_addr2, regs);

#if defined(_FEATURE_SIE)
    if(regs->sie_state && (regs->siebk->ic[3] & SIE_IC3_VACRS))
        longjmp(regs->progjmp, SIE_INTERCEPT_INST);
#endif /*defined(_FEATURE_SIE)*/

    regs->vf->vac = ARCH_DEP(vfetch8)(effective_addr2, b2, regs) & VAC_MASK;
    
}


#endif /*defined(FEATURE_VECTOR_FACILITY)*/


#if !defined(_GEN_ARCH)

#if defined(_ARCHMODE2)
 #define  _GEN_ARCH _ARCHMODE2
 #include "vector.c"
#endif

#if defined(_ARCHMODE3)
 #undef   _GEN_ARCH
 #define  _GEN_ARCH _ARCHMODE3
 #include "vector.c"
#endif

#endif /*!defined(_GEN_ARCH)*/