forked from SDL-Hercules-390/hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmpsc_2012.c
1303 lines (959 loc) · 39.3 KB
/
cmpsc_2012.c
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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* CMPSC_2012.C (C) Copyright "Fish" (David B. Trout), 2012-2019 */
/* (c) Bernard van der Helm, 2000-2012 */
/* S/390 Compression Call Instruction Functions */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/*-------------------------------------------------------------------*/
/* This module implements ESA/390 Compression Call instruction as */
/* described in SA22-7832-08 zArchitecture Principles of Operation */
/* and in great detail by "SA22-7208-01 ESA/390 Data Compression". */
/* Please also note that it was designed as written for use by both */
/* the primary Hercules instruction engine as well as by a separate */
/* stand alone testing tool utility from outside of Hercules. */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Additional credits and copyrights: */
/* */
/* The technique of expanding symbols until CBN# zero is reached */
/* and then expanding 8 symbols at a time was borrowed from the */
/* previous version of Hercules and is thus Bernard van der Helm's */
/* idea and not mine. Bernard gets all the credit for this technique */
/* and not me. The technique of using a cache of previously expanded */
/* symbols is not my own. It is the exact same technique that the */
/* previous version of Hercules was using and thus was Bernard's */
/* idea as well and not my own. Bernard gets all the credit for this */
/* technique as well. Both techniques are copyrighted by him. */
/* */
/* The basic compression/expansion algorithms which are implemented */
/* however, are the exact algorithms documented by IBM in the manual */
/* SA22-7832-08 zArchitecture Principles of Operation. */
/* */
/* All *OTHER* techniques (bit extraction macros, the index get/put */
/* functions, the dictionary extraction functions and their accom- */
/* panying memory access functions to save a call to MADDR) are all */
/* techniques copyrighted by me and licensed to Hercules. */
/* */
/* -- Fish (David B. Trout), Feb. 2012 */
/*-------------------------------------------------------------------*/
#include "hstdinc.h" // (MUST be first #include in EVERY source file)
DISABLE_GCC_UNUSED_FUNCTION_WARNING;
#define _CMPSC_C_
#define _HENGINE_DLL_
#if !defined( NOT_HERC ) // (building Hercules?)
#include "hercules.h"
#include "opcode.h"
#include "inline.h"
#endif
#include "cmpsc.h" // (Master header for both)
#if defined( FEATURE_CMPSC )
///////////////////////////////////////////////////////////////////////////////
// Symbols Cache Control Entry
#ifndef EXP_ONCE // (we only need to define these once)
#define EXP_ONCE // (we only need to define these once)
#ifdef CMPSC_SYMCACHE // (Symbol caching option)
struct SYMCTL // Symbol Cache Control Entry
{
U16 idx; // Cache index (sym's pos in cache)
U16 len; // Symbol length (sym's expanded len)
};
typedef struct SYMCTL SYMCTL;
#endif // CMPSC_SYMCACHE // (we only need to define this once)
///////////////////////////////////////////////////////////////////////////////
// EXPAND Index Symbol parameters block
struct EXPBLK // EXPAND Index Symbol parameters block
{
#ifdef CMPSC_SYMCACHE // (Symbol caching option)
SYMCTL symcctl[ MAX_DICT_ENTRIES ]; // Symbols cache control entries
U8 symcache[ CMPSC_SYMCACHE_SIZE ]; // Previously expanded symbols
U16 symindex; // Next available cache location
#endif // CMPSC_SYMCACHE // (Symbol caching option)
DCTBLK dctblk; // GetDCT parameters block
ECEBLK eceblk; // GetECE parameters block
MEMBLK op1blk; // Operand-1 memory access control block
MEMBLK op2blk; // Operand-2 memory access control block
ECE ece; // Expansion Character Entry data
U16 symlen; // Working symbol length value
U16 index; // SRC Index value
U8 SRC_bytes; // Number of bytes to adjust the SRC ptr/len by
U8 rc; // TRUE == success (cc), FALSE == failure (pic)
};
typedef struct EXPBLK EXPBLK;
#endif // EXP_ONCE // (we only need to define these once)
///////////////////////////////////////////////////////////////////////////////
// ZeroPadOp1 only if facility was enabled for this build architecture...
#if defined( FEATURE_047_CMPSC_ENH_FACILITY )
#undef ZERO_PAD_OP1
#define ZERO_PAD_OP1( pCMPSCBLK, pOp1MemBlk ) \
if (pCMPSCBLK->zp) /* (do zero padding?) */ \
ARCH_DEP( ZeroPadOp1 )( pCMPSCBLK, pOp1MemBlk );
#else // !defined( FEATURE_047_CMPSC_ENH_FACILITY )
#undef ZERO_PAD_OP1
#define ZERO_PAD_OP1( pCMPSCBLK, pOp1MemBlk ) \
UNREFERENCED( pOp1MemBlk );
#endif // defined( FEATURE_047_CMPSC_ENH_FACILITY )
///////////////////////////////////////////////////////////////////////////////
// Zero-padding
#if defined( FEATURE_047_CMPSC_ENH_FACILITY )
static CMPSC_INLINE void (CMPSC_FASTCALL ARCH_DEP( ZeroPadOp1 ))( CMPSCBLK* pCMPSCBLK, MEMBLK* pOp1MemBlk )
{
U64 pOp1 = pCMPSCBLK->pOp1; // (operand-1 output)
U64 nLen1 = pCMPSCBLK->nLen1; // (operand-1 length)
if (1
&& !(pCMPSCBLK->regs->GR_L(0) & 0x100) // (compression?)
&& pCMPSCBLK->cbn // (partial byte?)
&& nLen1 // (rem >= 1 byte?)
)
{
pOp1++; // (skip past byte)
nLen1--; // (length remaining)
}
pOp1 &= ADDRESS_MAXWRAP( pCMPSCBLK->regs ); // (wrap if needed)
MEMBLK_BUMP( pOp1MemBlk, pOp1 ); // (bump if needed)
if (pOp1 & CMPSC_ZP_MASK) // (is padding needed?)
{
U16 nPadAmt = ((U16)CMPSC_ZP_BYTES - (U16)(pOp1 & CMPSC_ZP_MASK));
if (nLen1 >= (U64) nPadAmt) // (enough room for pad?)
{
static U8 zeroes[ (1 << MAX_CMPSC_ZP_BITS) ] = {0};
store_op_str( zeroes, nPadAmt-1, pOp1, pOp1MemBlk );
}
}
}
#endif // defined( FEATURE_047_CMPSC_ENH_FACILITY )
///////////////////////////////////////////////////////////////////////////////
// Separate return functions for easier debugging... (it's much easier to
// set a breakpoint here and then examine the stack to see where you came
// from than it is to set breakpoints everywhere each function is called)
#if !defined( NOT_HERC ) // (building Hercules?)
#undef CMPSC_RETFUNCS // (rebuild each time)
#endif // (else do only once)
#ifndef CMPSC_RETFUNCS // (one time if Utility, each time if Herc)
#define CMPSC_RETFUNCS // (one time if Utility, each time if Herc)
PUSH_GCC_WARNINGS()
DISABLE_GCC_UNUSED_FUNCTION_WARNING;
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( ERR ))( CMPSCBLK* pCMPSCBLK, MEMBLK* pOp1MemBlk )
{
UNREFERENCED( pOp1MemBlk );
pCMPSCBLK->pic = 7;
return FALSE;
}
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( CC3 ))( CMPSCBLK* pCMPSCBLK, MEMBLK* pOp1MemBlk )
{
ZERO_PAD_OP1( pCMPSCBLK, pOp1MemBlk );
pCMPSCBLK->pic = 0;
pCMPSCBLK->cc = 3;
return TRUE;
}
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( CC1 ))( CMPSCBLK* pCMPSCBLK, MEMBLK* pOp1MemBlk )
{
ZERO_PAD_OP1( pCMPSCBLK, pOp1MemBlk );
pCMPSCBLK->pic = 0;
pCMPSCBLK->cc = 1;
return TRUE;
}
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( CC0 ))( CMPSCBLK* pCMPSCBLK, MEMBLK* pOp1MemBlk )
{
ZERO_PAD_OP1( pCMPSCBLK, pOp1MemBlk );
pCMPSCBLK->pic = 0;
pCMPSCBLK->cc = 0;
return TRUE;
}
//-----------------------------------------------------------------------------
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( EXPOK ))( CMPSCBLK* pCMPSCBLK, EXPBLK* pEXPBLK )
{
UNREFERENCED( pCMPSCBLK );
UNREFERENCED( pEXPBLK );
return TRUE; // (success; keep going)
}
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( EXPERR ))( CMPSCBLK* pCMPSCBLK, EXPBLK* pEXPBLK )
{
pEXPBLK->rc = ARCH_DEP( ERR )( pCMPSCBLK, &pEXPBLK->op1blk ); return FALSE; // (break)
}
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( EXPCC3 ))( CMPSCBLK* pCMPSCBLK, EXPBLK* pEXPBLK )
{
pEXPBLK->rc = ARCH_DEP( CC3 )( pCMPSCBLK, &pEXPBLK->op1blk ); return FALSE; // (break)
}
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( EXPCC1 ))( CMPSCBLK* pCMPSCBLK, EXPBLK* pEXPBLK )
{
pEXPBLK->rc = ARCH_DEP( CC1 )( pCMPSCBLK, &pEXPBLK->op1blk ); return FALSE; // (break)
}
static CMPSC_INLINE U8 (CMPSC_FASTCALL ARCH_DEP( EXPCC0 ))( CMPSCBLK* pCMPSCBLK, EXPBLK* pEXPBLK )
{
pEXPBLK->rc = ARCH_DEP( CC0 )( pCMPSCBLK, &pEXPBLK->op1blk ); return FALSE; // (break)
}
POP_GCC_WARNINGS()
//-----------------------------------------------------------------------------
// (define simpler macros to make calling the return functions much easier)
#undef RETERR
#undef RETCC3
#undef RETCC1
#undef RETCC0
#undef EXP_RETOK
#undef EXP_RETERR
#undef EXP_RETCC3
#undef EXP_RETCC1
#undef EXP_RETCC0
#define RETERR( pOp1MemBlk ) return ARCH_DEP( ERR )( pCMPSCBLK, pOp1MemBlk ) // (failure)
#define RETCC3( pOp1MemBlk ) return ARCH_DEP( CC3 )( pCMPSCBLK, pOp1MemBlk ) // (stop)
#define RETCC1( pOp1MemBlk ) return ARCH_DEP( CC1 )( pCMPSCBLK, pOp1MemBlk ) // (stop)
#define RETCC0( pOp1MemBlk ) return ARCH_DEP( CC0 )( pCMPSCBLK, pOp1MemBlk ) // (stop)
#define EXP_RETOK() return ARCH_DEP( EXPOK )( pCMPSCBLK, pEXPBLK ) // (success; keep going)
#define EXP_RETERR() return ARCH_DEP( EXPERR )( pCMPSCBLK, pEXPBLK ) // (break)
#define EXP_RETCC3() return ARCH_DEP( EXPCC3 )( pCMPSCBLK, pEXPBLK ) // (break)
#define EXP_RETCC1() return ARCH_DEP( EXPCC1 )( pCMPSCBLK, pEXPBLK ) // (break)
#define EXP_RETCC0() return ARCH_DEP( EXPCC0 )( pCMPSCBLK, pEXPBLK ) // (break)
#endif // CMPSC_RETFUNCS
///////////////////////////////////////////////////////////////////////////////
// EXPAND Index Symbol; TRUE == success, FALSE == error; rc == return code
U8 (CMPSC_FASTCALL ARCH_DEP( cmpsc_Expand_Index ))( CMPSCBLK* pCMPSCBLK, EXPBLK* pEXPBLK );
///////////////////////////////////////////////////////////////////////////////
// EXPANSION: TRUE == success (cc), FALSE == failure (pic)
U8 (CMPSC_FASTCALL ARCH_DEP( cmpsc_Expand ))( CMPSCBLK* pCMPSCBLK )
{
U64 nCPUAmt; // CPU determined processing limit
GetIndex** ppGetIndex; // Ptr to GetNextIndex table for this CDSS-1
GetIndex* pGetIndex; // Ptr to GetNextIndex function for this CBN
GIBLK giblk; // GetIndex parameters block
EXPBLK expblk; // EXPAND Index Symbol parameters block
U16 index[8]; // SRC Index values
U8 bits; // Number of bits per index
nCPUAmt = 0;
ppGetIndex = ARCH_DEP( GetIndexCDSSTab )[ pCMPSCBLK->cdss - 1 ];
pGetIndex = ppGetIndex [ pCMPSCBLK->cbn ];
bits = pCMPSCBLK->cdss + 8;
// Initialize GetIndex parameters block
memset( &giblk, 0, sizeof( giblk ));
giblk.pCMPSCBLK = pCMPSCBLK;
giblk.pMEMBLK = &expblk.op2blk; // (we get indexes from op-2)
giblk.pIndex = &index[0];
giblk.ppGetIndex = (void**) &pGetIndex;
// Initialize EXPAND Index Symbol parameters block
memset( &expblk, 0, sizeof( expblk ));
expblk.dctblk.regs = pCMPSCBLK->regs;
expblk.dctblk.arn = pCMPSCBLK->r2;
expblk.dctblk.pkey = pCMPSCBLK->regs->psw.pkey;
expblk.dctblk.pDict = pCMPSCBLK->pDict;
expblk.eceblk.pDCTBLK = &expblk.dctblk;
expblk.eceblk.max_index = 0xFFFF >> (16 - bits);
expblk.eceblk.pECE = &expblk.ece;
expblk.op1blk.arn = pCMPSCBLK->r1;
expblk.op1blk.regs = pCMPSCBLK->regs;
expblk.op1blk.pkey = pCMPSCBLK->regs->psw.pkey;
expblk.op2blk.arn = pCMPSCBLK->r2;
expblk.op2blk.regs = pCMPSCBLK->regs;
expblk.op2blk.pkey = pCMPSCBLK->regs->psw.pkey;
#ifdef CMPSC_EXPAND8
// Expand individual index symbols until CBN==0...
if ((pCMPSCBLK->cbn & 7) != 0)
{
while (nCPUAmt < (U64) pCMPSCBLK->nCPUAmt && (pCMPSCBLK->cbn & 7) != 0)
{
// Get index symbol...
if (unlikely( !(expblk.SRC_bytes = pGetIndex( &giblk ))))
RETCC0( &expblk.op1blk );
// Expand it...
expblk.index = index[0];
if (unlikely( !ARCH_DEP( cmpsc_Expand_Index )( pCMPSCBLK, &expblk )))
return expblk.rc;
// Bump source...
nCPUAmt += expblk.SRC_bytes;
pCMPSCBLK->pOp2 += expblk.SRC_bytes;
pCMPSCBLK->nLen2 -= expblk.SRC_bytes;
pCMPSCBLK->cbn += bits;
MEMBLK_BUMP( &expblk.op2blk, pCMPSCBLK->pOp2 );
// Bump destination...
pCMPSCBLK->pOp1 += expblk.symlen;
pCMPSCBLK->nLen1 -= expblk.symlen;
MEMBLK_BUMP( &expblk.op1blk, pCMPSCBLK->pOp1 );
}
}
// Now expand eight (8) index symbols at a time...
if ((pCMPSCBLK->cbn & 7) == 0)
{
GetIndex** ppGet8Index; // Ptr to GetNext8Index table for this CDSS-1
GetIndex* pGet8Index; // Ptr to GetNext8Index function for this CBN
CMPSCBLK save_cmpsc; // Work context
MEMBLK save_op1blk; // Work context
MEMBLK save_op2blk; // Work context
U8 i; // (work)
ppGet8Index = ARCH_DEP( Get8IndexCDSSTab )[ pCMPSCBLK->cdss - 1 ];
pGet8Index = ppGet8Index[ 0 ]; // (always CBN==0)
// Save context
memcpy( &save_cmpsc, pCMPSCBLK, sizeof( CMPSCBLK ));
memcpy( &save_op1blk, &expblk.op1blk, sizeof( MEMBLK ));
memcpy( &save_op2blk, &expblk.op2blk, sizeof( MEMBLK ));
while (nCPUAmt < (U64) pCMPSCBLK->nCPUAmt)
{
// Retrieve 8 index symbols from operand-2...
if (unlikely( !(expblk.SRC_bytes = pGet8Index( &giblk ))))
break;
// Bump source...
nCPUAmt += expblk.SRC_bytes;
pCMPSCBLK->pOp2 += expblk.SRC_bytes;
pCMPSCBLK->nLen2 -= expblk.SRC_bytes;
MEMBLK_BUMP( &expblk.op2blk, pCMPSCBLK->pOp2 );
// Expand each of the 8 individually into operand-1...
for (i=0; i < 8; i++)
{
expblk.index = index[i];
if (unlikely( !ARCH_DEP( cmpsc_Expand_Index )( pCMPSCBLK, &expblk )))
{
// Restore context
memcpy( pCMPSCBLK, &save_cmpsc, sizeof( CMPSCBLK ));
memcpy( &expblk.op1blk, &save_op1blk, sizeof( MEMBLK ));
memcpy( &expblk.op2blk, &save_op2blk, sizeof( MEMBLK ));
break; // (i < 8)
}
// Bump destination...
pCMPSCBLK->pOp1 += expblk.symlen;
pCMPSCBLK->nLen1 -= expblk.symlen;
// pCMPSCBLK->cbn += bits;
MEMBLK_BUMP( &expblk.op1blk, pCMPSCBLK->pOp1 );
}
if (i < 8)
break;
// Save context
memcpy( &save_cmpsc, pCMPSCBLK, sizeof( CMPSCBLK ));
memcpy( &save_op1blk, &expblk.op1blk, sizeof( MEMBLK ));
memcpy( &save_op2blk, &expblk.op2blk, sizeof( MEMBLK ));
}
}
#endif // CMPSC_EXPAND8
// Finish up any remainder...
while (nCPUAmt < (U64) pCMPSCBLK->nCPUAmt)
{
// Get index symbol...
if (unlikely( !(expblk.SRC_bytes = pGetIndex( &giblk ))))
RETCC0( &expblk.op1blk );
// Expand it...
expblk.index = index[0];
if (unlikely( !ARCH_DEP( cmpsc_Expand_Index )( pCMPSCBLK, &expblk )))
return expblk.rc;
// Bump source...
nCPUAmt += expblk.SRC_bytes;
pCMPSCBLK->pOp2 += expblk.SRC_bytes;
pCMPSCBLK->nLen2 -= expblk.SRC_bytes;
pCMPSCBLK->cbn += bits;
MEMBLK_BUMP( &expblk.op2blk, pCMPSCBLK->pOp2 );
// Bump destination...
pCMPSCBLK->pOp1 += expblk.symlen;
pCMPSCBLK->nLen1 -= expblk.symlen;
MEMBLK_BUMP( &expblk.op1blk, pCMPSCBLK->pOp1 );
}
RETCC3( &expblk.op1blk );
}
///////////////////////////////////////////////////////////////////////////////
// EXPAND Index Symbol; TRUE == success, FALSE == error; rc == return code
U8 (CMPSC_FASTCALL ARCH_DEP( cmpsc_Expand_Index ))( CMPSCBLK* pCMPSCBLK, EXPBLK* pEXPBLK )
{
U8 dicts; // Counts dictionary entries processed
if (unlikely( !pCMPSCBLK->nLen1 ))
EXP_RETCC1();
if (likely( pEXPBLK->index >= 256 ))
{
#ifdef CMPSC_SYMCACHE
// Check our cache of previously expanded index symbols
// to see if we've already expanded this symbol before
// and if we have room in the o/p buffer to expand it.
if (1
&& (pEXPBLK->symlen = pEXPBLK->symcctl[ pEXPBLK->index ].len) > 0
&& pEXPBLK->symlen <= pCMPSCBLK->nLen1
)
{
store_op_str( &pEXPBLK->symcache[ pEXPBLK->symcctl[ pEXPBLK->index ].idx ], pEXPBLK->symlen-1, pCMPSCBLK->pOp1, &pEXPBLK->op1blk );
}
else
#endif // CMPSC_SYMCACHE
{
// We need to expand this index symbol: fetch the ECE...
if (unlikely( !ARCH_DEP( GetECE )( pEXPBLK->index, &pEXPBLK->eceblk )))
EXP_RETERR();
if (pEXPBLK->ece.psl)
{
// Preceded (i.e. partial symbol)...
// Do we have room for the complete symbol?
if (unlikely( pCMPSCBLK->nLen1 < (pEXPBLK->symlen = pEXPBLK->ece.psl + pEXPBLK->ece.ofst)))
EXP_RETCC1();
dicts = 1;
do
{
// Expand this partial ("preceded") chunk of this index symbol...
store_op_str( pEXPBLK->ece.ec, pEXPBLK->ece.psl-1, pCMPSCBLK->pOp1 + pEXPBLK->ece.ofst, &pEXPBLK->op1blk );
// Get the ECE for the next chunk...
if (unlikely( !ARCH_DEP( GetECE )( pEXPBLK->ece.pptr, &pEXPBLK->eceblk )))
EXP_RETERR();
if (unlikely( ++dicts > 127 ))
EXP_RETERR();
}
while (pEXPBLK->ece.psl);
// we're done with the partial ("preceded") part of this
// symbol's expansion. Fall through to the "complete" symbol
// expansion logic to finish up this symbol's expansion...
}
else
{
// Unpreceded (i.e. complete symbol)...
// Do we have room for the complete symbol?
if (unlikely( pCMPSCBLK->nLen1 < (pEXPBLK->symlen = pEXPBLK->ece.csl)))
EXP_RETCC1();
}
// Complete the expansion of this index symbol...
store_op_str( pEXPBLK->ece.ec, pEXPBLK->ece.csl-1, pCMPSCBLK->pOp1, &pEXPBLK->op1blk );
#ifdef CMPSC_SYMCACHE
// If there's room for it, add this symbol to our expanded symbols cache
if (pEXPBLK->symlen <= (sizeof( pEXPBLK->symcache ) - pEXPBLK->symindex))
{
pEXPBLK->symcctl[ pEXPBLK->index ].len = pEXPBLK->symlen;
pEXPBLK->symcctl[ pEXPBLK->index ].idx = pEXPBLK->symindex;
// (add this symbol to our previously expanded symbols cache)
fetch_op_str( &pEXPBLK->symcache[ pEXPBLK->symindex ], pEXPBLK->symlen-1, pCMPSCBLK->pOp1, &pEXPBLK->op1blk );
pEXPBLK->symindex += pEXPBLK->symlen;
}
#endif // CMPSC_SYMCACHE
}
}
else // (pEXPBLK->index < 256)
{
// The index symbol is an alphabet entry (i.e. an index symbol
// corresponding to a one-byte symbol). The expanded symbol it
// represents is the value of the alphabet index symbol itself.
store_op_b( (U8)pEXPBLK->index, pCMPSCBLK->pOp1, &pEXPBLK->op1blk );
pEXPBLK->symlen = 1;
}
EXP_RETOK();
}
///////////////////////////////////////////////////////////////////////////////
// COMPRESSION: TRUE == success (cc), FALSE == failure (pgmck).
U8 (CMPSC_FASTCALL ARCH_DEP( cmpsc_Compress ))( CMPSCBLK* pCMPSCBLK )
{
U64 nCPUAmt; // CPU determined processing limit
U64 pBegOp2; // Ptr to beginning of operand-2
PutGetCBN* pPutGetCBN; // Ptr to PutGetCBN function for this CDSS-1
PutIndex** ppPutIndex; // Ptr to PutNextIndex table for this CDSS-1
PutIndex* pPutIndex; // Ptr to PutNextIndex function for this CBN
U64 pSymTab; // Symbol-Translation Table
GETSD* pGetSD; // Pointer to Get-Sibling-Descriptor function
CCE parent; // Parent Compression Character Entry data
CCE child; // Child Compression Character Entry data
SDE sibling; // Sibling Descriptor Entry data
MEMBLK op1blk; // Operand-1 memory access control block
MEMBLK op2blk; // Operand-2 memory access control block
DCTBLK dctblk; // GetDCT parameters block (cmp dict)
DCTBLK dctblk2; // GetDCT parameters block (exp dict)
CCEBLK cceblk; // GetCCE parameters block
SDEBLK sdeblk; // GetSDn parameters block
PIBLK piblk; // PutIndex parameters block
U16 parent_index; // Parent's CE Index value
U16 child_index; // Child's CE Index value
U16 sibling_index; // Sibling's SDE Index value
U16 max_index; // Maximum Index value
U16 children; // Counts children
U8 ccnum, scnum, byt; // (work variables)
U8 eodst, flag; // (work flags)
U8 bits; // Number of bits per index
U8 wrk[ MAX_SYMLEN ]; // (work buffer)
bits = 8 + pCMPSCBLK->cdss;
max_index = (0xFFFF >> (16 - bits));
pPutGetCBN = ARCH_DEP( PutGetCBNTab )[ pCMPSCBLK->cdss - 1 ];
ppPutIndex = ARCH_DEP( PutIndexCDSSTab )[ pCMPSCBLK->cdss - 1 ];
pPutIndex = ppPutIndex[ pCMPSCBLK->cbn ];
pSymTab = pCMPSCBLK->st ? pCMPSCBLK->pDict + ((U32)pCMPSCBLK->stt << 7) : 0;
pGetSD = pCMPSCBLK->f1 ? ARCH_DEP( GetSD1 ) : ARCH_DEP( GetSD0 );
#define PUTSETCBN() pCMPSCBLK->cbn = pPutGetCBN( pPutIndex )
memset( &dctblk, 0, sizeof( dctblk ) );
memset( &dctblk2, 0, sizeof( dctblk ) );
dctblk.regs = pCMPSCBLK->regs;
dctblk.arn = pCMPSCBLK->r2;
dctblk.pkey = pCMPSCBLK->regs->psw.pkey;
dctblk.pDict = pCMPSCBLK->pDict;
dctblk2.regs = pCMPSCBLK->regs;
dctblk2.arn = pCMPSCBLK->r2;
dctblk2.pkey = pCMPSCBLK->regs->psw.pkey;
dctblk2.pDict = pCMPSCBLK->pDict + g_nDictSize[ pCMPSCBLK->cdss - 1 ];
cceblk.pDCTBLK = &dctblk;
cceblk.max_index = max_index;
cceblk.pCCE = NULL; // (filled in before each call)
memset( &cceblk.cce, 0, sizeof( cceblk.cce ) );
sdeblk.pDCTBLK = &dctblk;
sdeblk.pDCTBLK2 = &dctblk2;
sdeblk.pSDE = &sibling;
sdeblk.pCCE = NULL; // (depends if first sibling)
memset( &sdeblk.sde, 0, sizeof( sdeblk.sde ) );
piblk.ppPutIndex = (void**) &pPutIndex;
piblk.pCMPSCBLK = pCMPSCBLK;
piblk.pMEMBLK = &op1blk; // (we put indexes into op-1)
piblk.index = 0; // (filled in before each call)
op1blk.arn = pCMPSCBLK->r1;
op1blk.regs = pCMPSCBLK->regs;
op1blk.pkey = pCMPSCBLK->regs->psw.pkey;
op1blk.vpagebeg = 0;
op1blk.maddr[0] = 0;
op1blk.maddr[1] = 0;
op2blk.arn = pCMPSCBLK->r2;
op2blk.regs = pCMPSCBLK->regs;
op2blk.pkey = pCMPSCBLK->regs->psw.pkey;
op2blk.vpagebeg = 0;
op2blk.maddr[0] = 0;
op2blk.maddr[1] = 0;
// GET STARTED...
pBegOp2 = pCMPSCBLK->pOp2;
eodst = (pCMPSCBLK->nLen1 < (2 + ((pCMPSCBLK->cbn > (16 - bits)) ? 1 : 0)))
? TRUE : FALSE;
nCPUAmt = 0;
//-------------------------------------------------------------------------
// PROGRAMMING NOTE: the following compression algorithm follows exactly
// the algorithm documented by IBM in their Principles of Operation manual.
// Most labels and all primary comments match the algorithm's flowchart.
//-------------------------------------------------------------------------
cmp1:
// Another SRC char exists?
// No, set CC0 and endop.
if (unlikely( !pCMPSCBLK->nLen2 ))
{
PUTSETCBN();
RETCC0( &op1blk );
}
cmp2:
// Another DST index position exists?
// No, set CC1 and endop.
if (unlikely( eodst ))
{
PUTSETCBN();
RETCC1( &op1blk );
}
if (unlikely( nCPUAmt >= (U64) pCMPSCBLK->nCPUAmt )) // (max bytes processed?)
{
PUTSETCBN();
RETCC3( &op1blk ); // (return cc3 to caller)
}
children = 0;
// Use next SRC char as index of alphabet entry.
// Call this entry the parent.
// Advance 1 byte in SRC.
parent_index = (U16) fetch_op_b( pCMPSCBLK->pOp2, &op2blk );
cceblk.pCCE = &parent;
if (unlikely( !ARCH_DEP( GetCCE )( parent_index, &cceblk )))
{
PUTSETCBN();
RETERR( &op1blk );
}
nCPUAmt++;
pCMPSCBLK->pOp2++;
pCMPSCBLK->nLen2--;
cmp3:
MEMBLK_BUMP( &op1blk, pCMPSCBLK->pOp1 );
MEMBLK_BUMP( &op2blk, pCMPSCBLK->pOp2 );
// CCT=0?
// Yes, goto cmp9;
if (!parent.cct)
goto cmp9;
//cmp4:
ccnum = 0;
// Set flag=1.
flag = TRUE;
// Another SRC char exists?
// No, goto cmp13;
if (unlikely( !pCMPSCBLK->nLen2 ))
goto cmp13;
// (REPEAT FOR EACH CC)...
cmp5:
// ---------------- UNROLL #1 ----------------
// Next SRC char = CC?
// Yes, goto cmp10;
byt = fetch_op_b( pCMPSCBLK->pOp2, &op2blk );
if (byt == parent.cc[ ccnum ])
goto cmp10;
// Set flag=0;
flag = FALSE;
// Another CC?
// Yes, goto cmp5;
if (++ccnum >= parent.cct)
goto cmp5E;
// ---------------- UNROLL #2 ----------------
// Next SRC char = CC?
// Yes, goto cmp10;
if (byt == parent.cc[ ccnum ])
goto cmp10;
// Set flag=0;
// flag = FALSE; // (already done by UNROLL #1)
// Another CC?
// Yes, goto cmp5;
if (++ccnum >= parent.cct)
goto cmp5E;
// ---------------- UNROLL #3 ----------------
// Next SRC char = CC?
// Yes, goto cmp10;
if (byt == parent.cc[ ccnum ])
goto cmp10;
// Set flag=0;
// flag = FALSE; // (already done by UNROLL #1)
// Another CC?
// Yes, goto cmp5;
if (++ccnum >= parent.cct)
goto cmp5E;
// ---------------- UNROLL #4 ----------------
// Next SRC char = CC?
// Yes, goto cmp10;
if (byt == parent.cc[ ccnum ])
goto cmp10;
// Set flag=0;
// flag = FALSE; // (already done by UNROLL #1)
// Another CC?
// Yes, goto cmp5;
if (++ccnum >= parent.cct)
goto cmp5E;
// ---------------- UNROLL #5 ----------------
// Next SRC char = CC?
// Yes, goto cmp10;
if (byt == parent.cc[ ccnum ])
goto cmp10;
// Set flag=0;
// flag = FALSE; // (already done by UNROLL #1)
// Another CC?
// Yes, goto cmp5;
if (++ccnum < parent.cct) // (** last UNROLL **)
goto cmp5;
cmp5E:
// CCT indicates more children?
// No, goto cmp8;
if (!parent.mc)
goto cmp8;
//cmp6:
// Set SD index = CPTR + #of CC's.
sibling_index = (parent.cptr + parent.cct);
sdeblk.pCCE = &parent;
if (unlikely( !pGetSD( sibling_index, &sdeblk )))
{
PUTSETCBN();
RETERR( &op1blk );
}
scnum = 0;
// (REPEAT FOR EACH SC IN SD)...
cmp7:
// ---------------- UNROLL #1 ----------------
// Next SRC char = SC?
// Yes, goto cmp12;
byt = fetch_op_b( pCMPSCBLK->pOp2, &op2blk );
if (byt == sibling.sc[ scnum ])
goto cmp12;
// Another SC?
// Yes, goto cmp7;
if (++scnum >= sibling.sct)
goto cmp7E;
// ---------------- UNROLL #2 ----------------
// Next SRC char = SC?
// Yes, goto cmp12;
if (byt == sibling.sc[ scnum ])
goto cmp12;
// Another SC?
// Yes, goto cmp7;
if (++scnum >= sibling.sct)
goto cmp7E;
// ---------------- UNROLL #3 ----------------
// Next SRC char = SC?
// Yes, goto cmp12;
if (byt == sibling.sc[ scnum ])
goto cmp12;
// Another SC?
// Yes, goto cmp7;
if (++scnum >= sibling.sct)
goto cmp7E;
// ---------------- UNROLL #4 ----------------
// Next SRC char = SC?
// Yes, goto cmp12;
if (byt == sibling.sc[ scnum ])
goto cmp12;
// Another SC?
// Yes, goto cmp7;
if (++scnum >= sibling.sct)
goto cmp7E;
// ---------------- UNROLL #5 ----------------
// Next SRC char = SC?
// Yes, goto cmp12;
if (byt == sibling.sc[ scnum ])
goto cmp12;
// Another SC?
// Yes, goto cmp7;
if (++scnum >= sibling.sct)
goto cmp7E;
// ---------------- UNROLL #6 ----------------
// Next SRC char = SC?
// Yes, goto cmp12;
if (byt == sibling.sc[ scnum ])
goto cmp12;
// Another SC?
// Yes, goto cmp7;
if (++scnum >= sibling.sct)
goto cmp7E;
// ---------------- UNROLL #7 ----------------
// Next SRC char = SC?
// Yes, goto cmp12;
if (byt == sibling.sc[ scnum ])
goto cmp12;
// Another SC?
// Yes, goto cmp7;
if (++scnum < sibling.sct) // (** last UNROLL **)
goto cmp7;
cmp7E:
// SCT indicates more children?
// No, goto cmp8;
if (!sibling.ms)
goto cmp8;
// Set SD index = current SD index + #of SC's + 1.
sibling_index += sibling.sct + 1;
sdeblk.pCCE = NULL;
if (unlikely( !pGetSD( sibling_index, &sdeblk )))
{
PUTSETCBN();
RETERR( &op1blk );
}
scnum = 0;
// goto cmp7;
goto cmp7;
cmp8:
// Store parent index in DST.
// Advance 1 index in DST.
// goto cmp2;
if (unlikely( (pCMPSCBLK->pOp2 - pBegOp2) > MAX_SYMLEN ))
{
PUTSETCBN();
RETERR( &op1blk );
}
pBegOp2 = pCMPSCBLK->pOp2;
piblk.index = (!pCMPSCBLK->st) ? parent_index
: fetch_dct_hw( pSymTab + (parent_index << 1), pCMPSCBLK );
eodst = pPutIndex( &piblk );
goto cmp2;
cmp9:
// Store parent index in DST.
// Advance 1 index in DST.
// goto cmp1;
if (unlikely( (pCMPSCBLK->pOp2 - pBegOp2) > MAX_SYMLEN ))
{
PUTSETCBN();
RETERR( &op1blk );
}
pBegOp2 = pCMPSCBLK->pOp2;
piblk.index = (!pCMPSCBLK->st) ? parent_index
: fetch_dct_hw( pSymTab + (parent_index << 1), pCMPSCBLK );
eodst = pPutIndex( &piblk );