forked from SDL-Hercules-390/hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmpsc.c
2062 lines (1834 loc) · 84 KB
/
cmpsc.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.C (c) Bernard van der Helm, 2000-2012 */
/* S/390 compression call instruction */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/*----------------------------------------------------------------------------*/
/* file: cmpsc.c */
/* */
/* Implementation of the S/390 compression call instruction described in */
/* SA22-7208-01: Data Compression within the Hercules S/390 emulator. */
/* This implementation couldn't be done without the test programs from */
/* Mario Bezzi. Thanks Mario! Also special thanks to Greg Smith who */
/* introduced iregs, needed when a page fault occurs. */
/* */
/* Implemented copyrighted features */
/* - Expanding index symbol caching */
/* - Compression dead end elimination */
/* - 8 index symbol fetching */
/* - 8 index symbol store */
/* */
/* (c) Copyright Bernard van der Helm, 2000-2012 */
/* Noordwijkerhout, The Netherlands. */
/* */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Compression optimalization */
/* */
/* Dead end determination */
/* Whenever a next character does not match any child in the character */
/* entry and possible sibling descriptors, it is a dead end. This dead */
/* combination is administrated in dea and tested before every start */
/* of finding a index symbol. This prevents many fetches. For example: */
/* */
/* HHC90318D fetch_ch : 01 at 000000001DDDC00F */
/* HHC90318D fetch_ch : C1 at 000000001DDDC010 */
/* HHC90316D fetch_cce: index 0001 */
/* HHC90319D cce : DF042A001C47500C */
/* HHC90320D cct : 6 */
/* HHC90327D x1..x5 : 11111 */
/* HHC90328D y1..y2 : 00 */
/* HHC90329D d : False */
/* HHC90325D cptr : 042A */
/* HHC90331D ccs : 00 1C 47 50 0C */
/* HHC90318D fetch_ch : C1 at 000000001DDDC010 */
/* HHC90339D fetch_sd1: index 042F */
/* HHC90332D sd1 : FBAF40580DD0F07041D3C514C3DD0F5A */
/* HHC90333D sct : 15 */
/* HHC90334D y1..y12: 101110101111 */
/* HHC90335D sc(s) : 40 58 0D D0 F0 70 41 D3 C5 14 C3 DD 0F 5A */
/* HHC90339D fetch_sd1: index 043E */
/* HHC90332D sd1 : E4888006120530011E4A549E42D15734 */
/* HHC90333D sct : 14 */
/* HHC90334D y1..y12: 010010001000 */
/* HHC90335D sc(s) : 80 06 12 05 30 01 1E 4A 54 9E 42 D1 57 34 */
/* HHC90365D dead_end : 01 C1 found */
/* */
/* The above dead end is found after fetching a character entry and 2 */
/* sibling entries. These fetches are saved on encountering a 01 C1 */
/* combination. */
/* */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Expansion optimalization */
/* */
/* Caching */
/* Every index symbol is cached after determination. This cache is used */
/* on every second appearance of that index symbol. This saves many fetches */
/* of character entries. For expample: */
/* */
/* HHC90349D fetch_ece: index 105F */
/* HHC90353D ece : B05A384040000104 */
/* HHC90354D psl : 5 */
/* HHC90355D pptr : 105A */
/* HHC90356D ecs : 38 40 40 00 01 */
/* HHC90357D ofst : 04 */
/* HHC90349D fetch_ece: index 105A */
/* HHC90353D ece : 0458404000000000 */
/* HHC90354D psl : 0 */
/* HHC90358D bit34 : False */
/* HHC90359D csl : 4 */
/* HHC90356D ecs : 58 40 40 00 */
/* */
/* The above index symbol 105F, meaning 584040003840400001 is cached and */
/* used after every next appearance. */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Common optimalization */
/* */
/* 8 index symbol block processing */
/* Calculating the cbn after placing or reading an index symbol is heavy. */
/* This implementation uses blocks of 8 index symbols. These 8 symbols fit */
/* in 9, 10, 11, 12 or 13 bytes and the cbn stays unchanged. */
/*----------------------------------------------------------------------------*/
#include "hstdinc.h"
#ifndef _HENGINE_DLL_
#define _HENGINE_DLL_
#endif /* #ifndef _HENGINE_DLL_ */
#ifndef _CMPSC_C_
#define _CMPSC_C_
#endif /* #ifndef _CMPSC_C_ */
#if !defined( NOT_HERC ) // (building Hercules?)
#include "hercules.h"
#include "opcode.h"
#include "inline.h"
#else // (building utility)
#define compression_call legacy_cmpsc
#endif
#ifdef FEATURE_COMPRESSION
/*============================================================================*/
/* Common */
/*============================================================================*/
/*----------------------------------------------------------------------------*/
/* Debugging options: */
/*----------------------------------------------------------------------------*/
#if 0
#define OPTION_CMPSC_DEBUG
#define TRUEFALSE(boolean) ((boolean) ? "True" : "False")
#endif /* #if 0|1 */
/*----------------------------------------------------------------------------*/
/* After a succesful compression of characters to an index symbol or a */
/* succsful translation of an index symbol to characters, the registers must */
/* be updated. */
/*----------------------------------------------------------------------------*/
#define ADJUSTREGS(r, regs, iregs, len) \
{ \
SET_GR_A((r), (iregs), (GR_A((r), (iregs)) + (len)) & ADDRESS_MAXWRAP((regs))); \
SET_GR_A((r) + 1, (iregs), GR_A((r) + 1, (iregs)) - (len)); \
}
/*----------------------------------------------------------------------------*/
/* Commit intermediate register */
/*----------------------------------------------------------------------------*/
#ifdef OPTION_CMPSC_DEBUG
#define COMMITREGS(regs, iregs, r1, r2) \
__COMMITREGS((regs), (iregs), (r1), (r2)) \
WRMSG(HHC90312, "D");
#else
#define COMMITREGS(regs, iregs, r1, r2) \
__COMMITREGS((regs), (iregs), (r1), (r2))
#endif /* ifdef OPTION_CMPSC_DEBUG */
#define __COMMITREGS(regs, iregs, r1, r2) \
{ \
SET_GR_A(1, (regs), GR_A(1, (iregs))); \
SET_GR_A((r1), (regs), GR_A((r1), (iregs))); \
SET_GR_A((r1) + 1, (regs), GR_A((r1) + 1, (iregs))); \
SET_GR_A((r2), (regs), GR_A((r2), (iregs))); \
SET_GR_A((r2) + 1, (regs), GR_A((r2) + 1, (iregs))); \
}
/*----------------------------------------------------------------------------*/
/* Commit intermediate register, except for GR1 */
/*----------------------------------------------------------------------------*/
#ifdef OPTION_CMPSC_DEBUG
#define COMMITREGS2(regs, iregs, r1, r2) \
__COMMITREGS2((regs), (iregs), (r1), (r2)) \
WRMSG(HHC90312, "D");
#else
#define COMMITREGS2(regs, iregs, r1, r2) \
__COMMITREGS2((regs), (iregs), (r1), (r2))
#endif /* #ifdef OPTION_CMPSC_DEBUG */
#define __COMMITREGS2(regs, iregs, r1, r2) \
{ \
SET_GR_A((r1), (regs), GR_A((r1), (iregs))); \
SET_GR_A((r1) + 1, (regs), GR_A((r1) + 1, (iregs))); \
SET_GR_A((r2), (regs), GR_A((r2), (iregs))); \
SET_GR_A((r2) + 1, (regs), GR_A((r2) + 1, (iregs))); \
}
/*----------------------------------------------------------------------------*/
/* Initialize intermediate registers */
/*----------------------------------------------------------------------------*/
#define INITREGS(iregs, regs, r1, r2) \
{ \
(iregs)->gr[1] = (regs)->gr[1]; \
(iregs)->gr[(r1)] = (regs)->gr[(r1)]; \
(iregs)->gr[(r1) + 1] = (regs)->gr[(r1) + 1]; \
(iregs)->gr[(r2)] = (regs)->gr[(r2)]; \
(iregs)->gr[(r2) + 1] = (regs)->gr[(r2) + 1]; \
}
#if __GEN_ARCH == 900
#undef INITREGS
#define INITREGS(iregs, regs, r1, r2) \
{ \
(iregs)->gr[1] = (regs)->gr[1]; \
(iregs)->gr[(r1)] = (regs)->gr[(r1)]; \
(iregs)->gr[(r1) + 1] = (regs)->gr[(r1) + 1]; \
(iregs)->gr[(r2)] = (regs)->gr[(r2)]; \
(iregs)->gr[(r2) + 1] = (regs)->gr[(r2) + 1]; \
(iregs)->psw.amode64 = (regs)->psw.amode64; \
}
#endif /* #if __GEN_ARCH == 900 */
/*----------------------------------------------------------------------------*/
/* General Purpose Register 0 macro's (GR0) */
/*----------------------------------------------------------------------------*/
/* cdss : compressed-data symbol size */
/* e : expansion operation */
/* f1 : format-1 sibling descriptors */
/* st : symbol-translation option */
/* zp : zero padding */
/*----------------------------------------------------------------------------*/
#define GR0_cdss(regs) (((regs)->GR_L(0) & 0x0000F000) >> 12)
#define GR0_e(regs) ((regs)->GR_L(0) & 0x00000100)
#define GR0_f1(regs) ((regs)->GR_L(0) & 0x00000200)
#define GR0_st(regs) ((regs)->GR_L(0) & 0x00010000)
#define GR0_zp(regs) ((regs)->GR_L(0) & 0x00020000)
/*----------------------------------------------------------------------------*/
/* General Purpose Register 0 macro's (GR0) derived */
/*----------------------------------------------------------------------------*/
/* dcten : # dictionary entries */
/* dctsz : dictionary size */
/* smbsz : symbol size */
/*----------------------------------------------------------------------------*/
#define GR0_dcten(regs) (0x100 << GR0_cdss(regs))
#define GR0_dctsz(regs) (0x800 << GR0_cdss((regs)))
#define GR0_smbsz(regs) (GR0_cdss((regs)) + 8)
/*----------------------------------------------------------------------------*/
/* General Purpose Register 1 macro's (GR1) */
/*----------------------------------------------------------------------------*/
/* cbn : compressed-data bit number */
/* dictor: compression dictionary or expansion dictionary */
/* sttoff: symbol-translation-table offset */
/*----------------------------------------------------------------------------*/
#define GR1_cbn(regs) (((regs)->GR_L(1) & 0x00000007))
#define GR1_dictor(regs) (GR_A(1, regs) & ((GREG) 0xFFFFFFFFFFFFF000ULL))
#define GR1_sttoff(regs) (((regs)->GR_L(1) & 0x00000FF8) << 4)
/*----------------------------------------------------------------------------*/
/* Sets the compressed bit number in GR1 */
/*----------------------------------------------------------------------------*/
#define GR1_setcbn(regs, cbn) ((regs)->GR_L(1) = ((regs)->GR_L(1) & 0xFFFFFFF8) | ((cbn) & 0x00000007))
/*----------------------------------------------------------------------------*/
/* Constants */
/*----------------------------------------------------------------------------*/
#define MINPROC_SIZE 32768 /* Minumum processing size */
/*----------------------------------------------------------------------------*/
/* Typedefs and prototypes */
/*----------------------------------------------------------------------------*/
#ifndef NO_2ND_COMPILE
struct cc /* Compress context */
{
BYTE *cce; /* Character entry under investigation */
unsigned dctsz; /* Dictionary size */
BYTE dea[0x100][0x100]; /* Dead end administration */
BYTE dead_end; /* Needed for dead end administration */
BYTE *dest; /* Destination MADDR address */
BYTE *dict[32]; /* Dictionary MADDR addresses */
GREG dictor; /* Dictionary origin */
BYTE *edict[32]; /* Expansion dictionary MADDR addrs */
int f1; /* Indication format-1 sibling descr */
REGS *iregs; /* Intermediate registers */
U16 is[8]; /* Cache for 8 index symbols */
unsigned ofst; /* Latest fetched offset */
int r1; /* Guess what */
int r2; /* Yep */
REGS *regs; /* Registers */
unsigned smbsz; /* Symbol size */
BYTE *src; /* Source MADDR page address */
BYTE st; /* Symbol translation */
};
struct ec /* Expand context */
{
BYTE *dest; /* Destination MADDR page address */
BYTE *dict[32]; /* Dictionary MADDR addresses */
GREG dictor; /* Dictionary origin */
BYTE ec[8192 * 7]; /* Expanded index symbol cache */
int eci[8192]; /* Index within cache for is */
int ecl[8192]; /* Size of expanded is */
int ecwm; /* Water mark */
REGS *iregs; /* Intermediate registers */
BYTE oc[8 * 260]; /* Output cache */
unsigned ocl; /* Output cache length */
int r1; /* Guess what */
int r2; /* Yep */
REGS *regs; /* Registers */
unsigned smbsz; /* Symbol size */
BYTE *src; /* Source MADDR page address */
};
#endif /* #ifndef NO_2ND_COMPILE */
static void ARCH_DEP(compress)(int r1, int r2, REGS *regs, REGS *iregs);
static void ARCH_DEP(expand)(int r1, int r2, REGS *regs, REGS *iregs);
static void ARCH_DEP(expand_is)(struct ec *ec, U16 is);
static BYTE *ARCH_DEP(fetch_cce)(struct cc *cc, unsigned index);
static int ARCH_DEP(fetch_ch)(struct cc *cc, BYTE *ch);
static int ARCH_DEP(fetch_chs_and_adjust)(struct cc *cc, BYTE *ch1, BYTE *ch2);
static int ARCH_DEP(fetch_is)(struct ec *ec, U16 *is);
static void ARCH_DEP(fetch_iss)(struct ec *ec, U16 is[8]);
#ifdef OPTION_CMPSC_DEBUG
static void print_cce(BYTE *cce);
static void print_ece(U16 is, BYTE *ece);
static void print_sd(int f1, BYTE *sd1, BYTE *sd2);
#endif /* #ifdef OPTION_CMPSC_DEBUG */
static int ARCH_DEP(search_cce)(struct cc *cc, BYTE *ch, U16 *is);
static int ARCH_DEP(search_sd)(struct cc *cc, BYTE *ch, U16 *is);
static int ARCH_DEP(store_is)(struct cc *cc, U16 is);
static void ARCH_DEP(store_iss)(struct cc *cc);
static int ARCH_DEP(test_ec)(struct cc *cc, BYTE *cce);
static int ARCH_DEP(vstore)(struct ec *ec, BYTE *buf, unsigned len);
/*----------------------------------------------------------------------------*/
/* B263 CMPSC - Compression Call [RRE] */
/*----------------------------------------------------------------------------*/
DEF_INST(compression_call)
{
REGS iregs; /* Intermediate registers */
int r1; /* Guess what */
int r2; /* Yep */
RRE(inst, regs, r1, r2);
#ifdef OPTION_CMPSC_DEBUG
WRGMSG_ON;
WRGMSG(HHC90300, "D");
WRGMSG(HHC90301, "D", 1, r1);
WRGMSG(HHC90302, "D", regs->GR(r1));
WRGMSG(HHC90303, "D", regs->GR(r1 + 1));
WRGMSG(HHC90301, "D", 2, r2);
WRGMSG(HHC90302, "D", regs->GR(r2));
WRGMSG(HHC90303, "D", regs->GR(r2 + 1));
WRGMSG(HHC90304, "D", 0, regs->GR(0));
WRGMSG(HHC90364, "D", TRUEFALSE(GR0_zp(regs)));
WRGMSG(HHC90305, "D", TRUEFALSE(GR0_st(regs)));
WRGMSG(HHC90306, "D", GR0_cdss(regs));
WRGMSG(HHC90307, "D", TRUEFALSE(GR0_f1(regs)));
WRGMSG(HHC90308, "D", TRUEFALSE(GR0_e(regs)));
WRGMSG(HHC90304, "D", 1, regs->GR(1));
WRGMSG(HHC90309, "D", GR1_dictor(regs));
WRGMSG(HHC90310, "D", GR1_sttoff(regs));
WRGMSG(HHC90311, "D", GR1_cbn(regs));
WRGMSG_OFF;
#endif /* #ifdef OPTION_CMPSC_DEBUG */
/* Check the registers on even-odd pairs and valid compression-data symbol size */
if(unlikely(r1 & 0x01 || r2 & 0x01 || !GR0_cdss(regs) || GR0_cdss(regs) > 5))
ARCH_DEP(program_interrupt)(regs, PGM_SPECIFICATION_EXCEPTION);
/* Check for empty input */
if(unlikely(!GR_A(r2 + 1, regs)))
{
regs->psw.cc = 0;
return;
}
/* Check for empty output */
if(unlikely(!GR_A(r1 + 1, regs)))
{
regs->psw.cc = 1;
return;
}
/* Set possible Data Exception code */
regs->dxc = DXC_DECIMAL;
/* Initialize intermediate registers */
INITREGS(&iregs, regs, r1, r2);
/* Now go to the requested function */
if(likely(GR0_e(regs)))
ARCH_DEP(expand)(r1, r2, regs, &iregs);
else
ARCH_DEP(compress)(r1, r2, regs, &iregs);
}
/*============================================================================*/
/* Compress */
/*============================================================================*/
/*----------------------------------------------------------------------------*/
/* Compression Character Entry macro's (CCE) */
/*----------------------------------------------------------------------------*/
/* act : additional-extension-character count */
/* cct : child count */
/* cptr : child pointer; index of first child */
/* d : double-character entry */
/* x(i) : examine child bit for children 1 to 5 */
/* y(i) : examine child bit for 6th/13th and 7th/14th sibling */
/*----------------------------------------------------------------------------*/
#define CCE_act(cce) ((cce)[1] >> 5)
#define CCE_cct(cce) ((cce)[0] >> 5)
#define CCE_cptr(cce) ((((cce)[1] & 0x1f) << 8) | (cce)[2])
#define CCE_d(cce) ((cce)[1] & 0x20)
#define CCE_x(cce, i) ((cce)[0] & (0x10 >> (i)))
#define CCE_y(cce, i) ((cce)[1] & (0x80 >> (i)))
/*----------------------------------------------------------------------------*/
/* Compression Character Entry macro's (CCE) derived */
/*----------------------------------------------------------------------------*/
/* cc(i) : child character */
/* ccc(i) : indication consecutive child character */
/* ccs : number of child characters */
/* ec(i) : additional extension character */
/* ecs : number of additional extension characters */
/* mcc : indication if siblings follow child characters */
/*----------------------------------------------------------------------------*/
#define CCE_cc(cce, i) ((cce)[3 + CCE_ecs((cce)) + (i)])
#define CCE_ccc(cce, i) (CCE_cc((cce), (i)) == CCE_cc((cce), 0))
#define CCE_ccs(cce) (CCE_cct((cce)) - (CCE_mcc((cce)) ? 1 : 0))
#define CCE_ec(cce, i) ((cce)[3 + (i)])
#define CCE_ecs(cce) ((CCE_cct((cce)) <= 1) ? CCE_act((cce)) : (CCE_d((cce)) ? 1 : 0))
#define CCE_mcc(cce) ((CCE_cct((cce)) + (CCE_d((cce)) ? 1 : 0) == 6))
/*----------------------------------------------------------------------------*/
/* Format-0 Sibling Descriptors macro's (SD0) */
/*----------------------------------------------------------------------------*/
/* sct : sibling count */
/* y(i) : examine child bit for siblings 1 to 5 */
/*----------------------------------------------------------------------------*/
#define SD0_sct(sd0) ((sd0)[0] >> 5)
#define SD0_y(sd0, i) ((sd0)[0] & (0x10 >> (i)))
/*----------------------------------------------------------------------------*/
/* Format-0 Sibling Descriptors macro's (SD0) derived */
/*----------------------------------------------------------------------------*/
/* ccc(i) : indication consecutive child character */
/* ecb(i) : examine child bit, if y then 6th/7th fetched from parent */
/* msc : indication if siblings follows last sibling */
/* sc(i) : sibling character */
/* scs : number of sibling characters */
/*----------------------------------------------------------------------------*/
#define SD0_ccc(sd0, i) (SD0_sc((sd0), (i)) == SD0_sc((sd0), 0))
#define SD0_ecb(sd0, i, cce, y) (((i) < 5) ? SD0_y((sd0), (i)) : (y) ? CCE_y((cce), ((i) - 5)) : 1)
#define SD0_msc(sd0) (!SD0_sct((sd0)))
#define SD0_sc(sd0, i) ((sd0)[1 + (i)])
#define SD0_scs(sd0) (SD0_msc((sd0)) ? 7 : SD0_sct((sd0)))
/*----------------------------------------------------------------------------*/
/* Format-1 Sibling Descriptors macro's (SD1) */
/*----------------------------------------------------------------------------*/
/* sct : sibling count */
/* y(i) : examine child bit for sibling 1 to 12 */
/*----------------------------------------------------------------------------*/
#define SD1_sct(sd1) ((sd1)[0] >> 4)
#define SD1_y(sd1, i) ((i) < 4 ? ((sd1)[0] & (0x08 >> (i))) : ((sd1)[1] & (0x800 >> (i))))
/*----------------------------------------------------------------------------*/
/* Format-1 Sibling Descriptors macro's (SD1) derived */
/*----------------------------------------------------------------------------*/
/* ccc(i) : indication consecutive child character */
/* ecb(i) : examine child bit, if y then 13th/14th fetched from parent */
/* msc : indication if siblings follows last sibling */
/* sc(i) : sibling character */
/* scs : number of sibling characters */
/*----------------------------------------------------------------------------*/
#define SD1_ccc(sd1, sd2, i) (SD1_sc((sd1), (sd2), (i)) == SD1_sc((sd1), (sd2), 0))
#define SD1_ecb(sd1, i, cce, y) (((i) < 12) ? SD1_y((sd1), (i)) : (y) ? CCE_y((cce), ((i) - 12)) : 1)
#define SD1_msc(sd1) ((SD1_sct((sd1)) == 15))
#define SD1_sc(sd1, sd2, i) ((i) < 6 ? (sd1)[2 + (i)] : (sd2)[(i) - 6])
#define SD1_scs(sd1) (SD1_msc((sd1)) ? 14 : SD1_sct((sd1)))
/*----------------------------------------------------------------------------*/
/* Format independent sibling descriptor macro's */
/*----------------------------------------------------------------------------*/
#define SD_ccc(f1, sd1, sd2, i) ((f1) ? SD1_ccc((sd1), (sd2), (i)) : SD0_ccc((sd1), (i)))
#define SD_ecb(f1, sd1, i, cce, y) ((f1) ? SD1_ecb((sd1), (i), (cce), (y)) : SD0_ecb((sd1), (i), (cce), (y)))
#define SD_msc(f1, sd1) ((f1) ? SD1_msc((sd1)) : SD0_msc((sd1)))
#define SD_sc(f1, sd1, sd2, i) ((f1) ? SD1_sc((sd1), (sd2), (i)) : SD0_sc((sd1), (i)))
#define SD_scs(f1, sd1) ((f1) ? SD1_scs((sd1)) : SD0_scs((sd1)))
/*============================================================================*/
/*----------------------------------------------------------------------------*/
/* compress */
/*----------------------------------------------------------------------------*/
static void ARCH_DEP(compress)(int r1, int r2, REGS *regs, REGS *iregs)
{
struct cc cc; /* Compression context */
BYTE ch1; /* Character read */
BYTE ch2;
int i; /* Index */
U16 is; /* Last matched index symbol */
GREG srclen; /* Source length */
/* Initialize values */
srclen = GR_A(r2 + 1, iregs);
/* Initialize compression context */
cc.dctsz = GR0_dctsz(regs);
memset(cc.dea, 0, sizeof(cc.dea));
cc.dest = NULL;
for(i = 0; i < (0x01 << GR0_cdss(regs)); i++)
{
cc.dict[i] = NULL;
cc.edict[i] = NULL;
}
cc.dictor = GR1_dictor(iregs);
cc.f1 = GR0_f1(regs);
cc.iregs = iregs;
cc.ofst = 0;
cc.r1 = r1;
cc.r2 = r2;
cc.regs = regs;
cc.smbsz = GR0_smbsz(regs);
cc.src = NULL;
cc.st = GR0_st(regs) ? 1 : 0;
/* Process individual index symbols until cbn bocomes zero */
while(unlikely(GR1_cbn(iregs)))
{
/* Get the next characters and adjust alphabet entry, return on end of source */
if(unlikely(ARCH_DEP(fetch_chs_and_adjust)(&cc, &ch1, &ch2)))
return;
cc.dead_end = 1;
is = ch1;
/* Do normal searching on unknown dead end */
if(likely(!cc.dea[is][ch2]))
{
/* Get the alphabet entry and try to find a child */
cc.cce = ARCH_DEP(fetch_cce)(&cc, is);
while(ARCH_DEP(search_cce)(&cc, &ch1, &is));
if(unlikely(cc.dead_end))
{
/* We found a dead end combination */
cc.dea[is][ch2] = 1;
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90365, "D", is, ch2, "found");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
}
}
#ifdef OPTION_CMPSC_DEBUG
else
WRMSG(HHC90365, "D", is, ch2, "encountered");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
/* Write the last match, return on end of destination */
if(unlikely(ARCH_DEP(store_is)(&cc, is)))
return;
/* Commit registers */
COMMITREGS(regs, iregs, r1, r2);
}
/* Block processing, cbn stays zero */
while(likely(GR_A(r1 + 1, iregs) >= cc.smbsz))
{
for(i = 0; i < 8; i++)
{
/* Get the next characters and adjust alphabet entry, return on end of source */
if(unlikely(ARCH_DEP(fetch_chs_and_adjust)(&cc, &ch1, &ch2)))
{
int j;
/* Write individual found index symbols */
for(j = 0; j < i; j++)
ARCH_DEP(store_is)(&cc, cc.is[j]);
COMMITREGS(regs, iregs, r1, r2);
return;
}
cc.dead_end = 1;
is = ch1;
/* Do normal searching on unknown dead end */
if(likely(!cc.dea[is][ch2]))
{
/* Get the alphabet entry and try to find a child */
cc.cce = ARCH_DEP(fetch_cce)(&cc, is);
while(ARCH_DEP(search_cce)(&cc, &ch1, &is));
if(unlikely(cc.dead_end))
{
/* We found a dead end combination */
cc.dea[is][ch2] = 1;
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90365, "D", is, ch2, "found");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
}
}
#ifdef OPTION_CMPSC_DEBUG
else
WRMSG(HHC90365, "D", is, ch2, "encountered");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
cc.is[i] = is;
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90314, "D", is, i);
#endif /* #ifdef OPTION_CMPSC_DEBUG */
}
/* Write index symbols and commit */
ARCH_DEP(store_iss)(&cc);
COMMITREGS2(regs, iregs, r1, r2);
/* Return with cc3 on interrupt pending after a minumum size of processing */
if(unlikely(srclen - GR_A(r2 + 1, iregs) >= MINPROC_SIZE && INTERRUPT_PENDING(regs)))
{
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90315, "D");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
regs->psw.cc = 3;
return;
}
}
while(GR_A(r2 + 1, iregs))
{
/* Get the next characters and adjust alphabet entry, return on end of source */
if(unlikely(ARCH_DEP(fetch_chs_and_adjust)(&cc, &ch1, &ch2)))
return;
cc.dead_end = 1;
is = ch1;
/* Do normal searching on unknown dead end */
if(unlikely(!cc.dea[is][ch2]))
{
/* Get the alphabet entry and try to find a child */
cc.cce = ARCH_DEP(fetch_cce)(&cc, is);
while(ARCH_DEP(search_cce)(&cc, &ch1, &is));
if(unlikely(cc.dead_end))
{
/* We found a dead end combination */
cc.dea[is][ch2] = 1;
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90365, "D", is, ch2, "found");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
}
}
#ifdef OPTION_CMPSC_DEBUG
else
WRMSG(HHC90365, "D", is, ch2, "encountered");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
/* Write the last match, return on end of destination */
if(unlikely(ARCH_DEP(store_is)(&cc, is)))
return;
/* Commit registers */
COMMITREGS(regs, iregs, r1, r2);
}
}
/*----------------------------------------------------------------------------*/
/* fetch_cce (compression character entry) */
/*----------------------------------------------------------------------------*/
static BYTE *ARCH_DEP(fetch_cce)(struct cc *cc, unsigned index)
{
BYTE *cce; /* Compression child entry */
unsigned cct; /* Child count */
index *= 8;
if(unlikely(!cc->dict[index / 0x800]))
cc->dict[index / 0x800] = MADDR((cc->dictor + (index / 0x800) * 0x800) & ADDRESS_MAXWRAP(cc->regs), cc->r2, cc->regs, ACCTYPE_READ, cc->regs->psw.pkey);
cce = &cc->dict[index / 0x800][index % 0x800];
ITIMER_SYNC((cc->dictor + index) & ADDRESS_MAXWRAP(cc->regs), 8 - 1, cc->regs);
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90316, "D", index / 8);
print_cce(cce);
#endif /* #ifdef OPTION_CMPSC_DEBUG */
/* Check for data exception */
cct = CCE_cct(cce);
if(cct < 2)
{
if(unlikely(CCE_act(cce) > 4))
ARCH_DEP(program_interrupt)(cc->regs, PGM_DATA_EXCEPTION);
}
else
{
if(!CCE_d(cce))
{
if(unlikely(cct == 7))
ARCH_DEP(program_interrupt)(cc->regs, PGM_DATA_EXCEPTION);
}
else
{
if(unlikely(cct > 5))
ARCH_DEP(program_interrupt)(cc->regs, PGM_DATA_EXCEPTION);
}
}
return(cce);
}
/*----------------------------------------------------------------------------*/
/* fetch_ch (character) */
/*----------------------------------------------------------------------------*/
static int ARCH_DEP(fetch_ch)(struct cc *cc, BYTE *ch)
{
unsigned ofst; /* Offset within page */
/* Check for end of source condition */
if(unlikely(!GR_A(cc->r2 + 1, cc->iregs)))
{
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90317, "D");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
cc->regs->psw.cc = 0;
return(-1);
}
ofst = GR_A(cc->r2, cc->iregs) & 0x7ff;
ITIMER_SYNC(GR_A(cc->r2, cc->iregs) & ADDRESS_MAXWRAP(cc->regs), 1 - 1, cc->regs);
/* Fingers crossed that we stay within current page */
if(unlikely(!cc->src || ofst < cc->ofst))
cc->src = MADDR((GR_A(cc->r2, cc->iregs) & ~0x7ff) & ADDRESS_MAXWRAP(cc->regs), cc->r2, cc->regs, ACCTYPE_READ, cc->regs->psw.pkey);
*ch = cc->src[ofst];
cc->ofst = ofst;
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90318, "D", *ch, GR_A(cc->r2, cc->iregs));
#endif /* #ifdef OPTION_CMPSC_DEBUG */
return(0);
}
/*----------------------------------------------------------------------------*/
/* fetch_chs_and_adjust (characters) */
/*----------------------------------------------------------------------------*/
static int ARCH_DEP(fetch_chs_and_adjust)(struct cc *cc, BYTE *ch1, BYTE *ch2)
{
#ifdef OPTION_CMPSC_DEBUG
char buf[6]; /* Print buffer for 2 or 1 character */
#endif /* #ifdef OPTION_CMPSC_DEBUG */
U64 len; /* Source length left */
unsigned ofst; /* Offset within page */
/* Check for end of source condition */
len = GR_A(cc->r2 + 1, cc->iregs);
if(unlikely(!len))
{
#ifdef OPTION_CMPSC_DEBUG
WRMSG(HHC90317, "D");
#endif /* #ifdef OPTION_CMPSC_DEBUG */
cc->regs->psw.cc = 0;
return(-1);
}
ofst = GR_A(cc->r2, cc->iregs) & 0x7ff;
ITIMER_SYNC(GR_A(cc->r2, cc->iregs) & ADDRESS_MAXWRAP(cc->regs), 1 - 1, cc->regs);
/* Fingers crossed that we stay within current page */
if(unlikely(!cc->src || ofst < cc->ofst))
cc->src = MADDR((GR_A(cc->r2, cc->iregs) & ~0x7ff) & ADDRESS_MAXWRAP(cc->regs), cc->r2, cc->regs, ACCTYPE_READ, cc->regs->psw.pkey);
*ch1 = cc->src[ofst];
cc->ofst = ofst;
/* Adjust registers, we always match the alphabet entry */
ADJUSTREGS(cc->r2, cc->regs, cc->iregs, 1);
len--;
/* Check if 2nd character available */
if(unlikely(!len))
{
#ifdef OPTION_CMPSC_DEBUG
snprintf(buf, 6, "%02X", *ch1);
WRMSG(HHC90313, "D", buf, GR_A(cc->r2, cc->iregs) - 1);
#endif /* #ifdef OPTION_CMPSC_DEBUG */
return(0); /* It is ok when dead_end is detected */
}
ITIMER_SYNC(GR_A(cc->r2, cc->iregs) & ADDRESS_MAXWRAP(cc->regs), 1 - 1, cc->regs);
/* Fingers crossed that we stay within current page */
ofst++;
if(unlikely(ofst == 0x800))
{
ofst = 0;
cc->src = MADDR((GR_A(cc->r2, cc->iregs) & ~0x7ff) & ADDRESS_MAXWRAP(cc->regs), cc->r2, cc->regs, ACCTYPE_READ, cc->regs->psw.pkey);
}
*ch2 = cc->src[ofst];
cc->ofst = ofst;
#ifdef OPTION_CMPSC_DEBUG
snprintf(buf, 6, "%02X %02X", *ch1, *ch2);
WRMSG(HHC90313, "D", buf, GR_A(cc->r2, cc->iregs) - 1);
#endif /* #ifdef OPTION_CMPSC_DEBUG */
return(0);
}
#ifndef NO_2ND_COMPILE
#ifdef OPTION_CMPSC_DEBUG
/*----------------------------------------------------------------------------*/
/* print_cce (compression character entry). */
/*----------------------------------------------------------------------------*/
static void print_cce(BYTE *cce)
{
char buf[128]; /* Buffer */
int j; /* Index */
int prt_detail; /* Switch for detailed printing */
buf[0] = 0;
prt_detail = 0;
for(j = 0; j < 8; j++)
{
if(!prt_detail && cce[j])
prt_detail = 1;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%02X", cce[j]);
buf[sizeof(buf)-1] = '\0';
}
if(prt_detail)
{
WRGMSG_ON;
WRGMSG(HHC90319, "D", buf);;
WRGMSG(HHC90320, "D", CCE_cct(cce));
switch(CCE_cct(cce))
{
case 0:
{
WRGMSG(HHC90321, "D", (int) CCE_act(cce));
if(CCE_act(cce))
{
buf[0] = 0;
for(j = 0; j < CCE_ecs(cce); j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %02X", CCE_ec(cce, j));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90322, "D", buf);
}
break;
}
case 1:
{
WRGMSG(HHC90323, "D", (int) (CCE_x(cce, 0) ? '1' : '0'));
WRGMSG(HHC90324, "D", (int) CCE_act(cce));
WRGMSG(HHC90325, "D", CCE_cptr(cce));
if(CCE_act(cce))
{
buf[0] = 0;
for(j = 0; j < CCE_ecs(cce); j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %02X", CCE_ec(cce, j));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90322, "D", buf);
}
WRGMSG(HHC90326, "D", CCE_cc(cce, 0));
break;
}
default:
{
buf[0] = 0;
for(j = 0; j < 5; j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c", (int) (CCE_x(cce, j) ? '1' : '0'));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90327, "D", buf);
buf[0] = 0;
for(j = 0; j < 2; j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c", (int) (CCE_y(cce, j) ? '1' : '0'));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90328, "D", buf);
WRGMSG(HHC90329, "D", TRUEFALSE(CCE_d(cce)));
WRGMSG(HHC90325, "D", CCE_cptr(cce));
if(CCE_d(cce))
WRGMSG(HHC90330, "D", CCE_ec(cce, 0));
buf[0] = 0;
for(j = 0; j < CCE_ccs(cce); j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %02X", CCE_cc(cce, j));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90331, "D", buf);
break;
}
}
WRGMSG_OFF;
}
else
WRMSG(HHC90319, "D", buf);
}
/*----------------------------------------------------------------------------*/
/* print_sd (sibling descriptor). */
/*----------------------------------------------------------------------------*/
static void print_sd(int f1, BYTE *sd1, BYTE *sd2)
{
char buf[128]; /* Buffer */
int j; /* Index */
int prt_detail; /* Switch for detailed printing */
if(f1)
{
buf[0] = 0;
prt_detail = 0;
for(j = 0; j < 8; j++)
{
if(!prt_detail && sd1[j])
prt_detail = 1;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%02X", sd1[j]);
}
buf[sizeof(buf)-1] = '\0';
for(j = 0; j < 8; j++)
{
if(!prt_detail && sd2[j])
prt_detail = 1;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%02X", sd2[j]);
}
buf[sizeof(buf)-1] = '\0';
if(prt_detail)
{
WRGMSG_ON;
WRGMSG(HHC90332, "D", buf);
WRGMSG(HHC90333, "D", SD1_sct(sd1));
buf[0] = 0;
for(j = 0; j < 12; j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c", (SD1_y(sd1, j) ? '1' : '0'));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90334, "D", buf);
buf[0] = 0;
for(j = 0; j < SD1_scs(sd1); j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %02X", SD1_sc(sd1, sd2, j));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90335, "D", buf);
WRGMSG_OFF;
}
else
WRMSG(HHC90332, "D", buf);
}
else
{
buf[0] = 0;
prt_detail = 0;
for(j = 0; j < 8; j++)
{
if(!prt_detail && sd1[j])
prt_detail = 1;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%02X", sd1[j]);
}
buf[sizeof(buf)-1] = '\0';
if(prt_detail)
{
WRGMSG_ON;
WRGMSG(HHC90336, "D", buf);
WRGMSG(HHC90333, "D", SD0_sct(sd1));
buf[0] = 0;
for(j = 0; j < 5; j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c", (SD0_y(sd1, j) ? '1' : '0'));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90337, "D", buf);
buf[0] = 0;
for(j = 0; j < SD0_scs(sd1); j++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %02X", SD0_sc(sd1, j));
buf[sizeof(buf)-1] = '\0';
WRGMSG(HHC90335, "D", buf);
WRGMSG_OFF;
}
else
WRMSG(HHC90336, "D", buf);
}
}
#endif /* #ifdef OPTION_CMPSC_DEBUG */
#endif /* #ifndef NO_2ND_COMPILE */
/*----------------------------------------------------------------------------*/
/* search_cce (compression character entry) */
/*----------------------------------------------------------------------------*/
static int ARCH_DEP(search_cce)(struct cc *cc, BYTE *ch, U16 *is)
{
BYTE *ccce; /* Child compression character entry */
int ccs; /* Number of child characters */
int i; /* Child character index */
int ind_search_siblings; /* Indicator for searching siblings */
/* Initialize values */
ccs = CCE_ccs(cc->cce);
/* Get the next character when there are children */
if(likely(ccs))
{
if(ARCH_DEP(fetch_ch(cc, ch)))
return(0);
ind_search_siblings = 1;
/* Now check all children in parent */
for(i = 0; i < ccs; i++)
{
/* Stop searching when child tested and no consecutive child character */
if(unlikely(!ind_search_siblings && !CCE_ccc(cc->cce, i)))