-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFault_sim.cpp
2422 lines (2250 loc) · 117 KB
/
Fault_sim.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
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
/*
** 체크해야 할 것
(1) conservative : BL32 묶음 내에서 error가 다른 chip에서 나오는가 (1-bit error는 내부 OECC에서 고쳐서 나온다.)
=> on/off 가능하도록 만들기 [일단 끄고 하자.]
(2)
** CE/DUE/SDC
(1) if Syndrome == 0
-> NE 'or' SDC
-> error correction 안하고 SDC check 하면 된다.
(2) else if Syndrome != 0
[1] CE가 되는 case면 CE
문제: Correction capability 넘어가는 error 발생시 해당 error가 DUE인지 SDC인지 구분하는 것이 문제
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctime>
#include<iostream>
#include<cstdlib>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstring>
// Configuration
// 필요로 하면 변경하기
#define CHANNEL_WIDTH 40
#define CHIP_NUM 10
#define DATA_CHIP_NUM 8 // sub-channel마다 data chip 개수
#define CHIP_WIDTH 4
#define BLHEIGHT 32 // RECC가 검사해야 하는 Burst length (ondie ecc의 redundancy는 제외하고 BL32만 검사한다. conservative mode 조건 고려하기)
#define OECC_CW_LEN 136 // ondie ecc의 codeword 길이 (bit 단위)
#define OECC_DATA_LEN 128 // ondie ecc의 dataward 길이 (bit 단위)
#define OECC_REDUN_LEN 8 // ondie ecc의 redundancy 길이 (bit 단위)
#define RUN_NUM 100000000 // 실행 횟수
int fault_cnt=0;
//configuration over
using namespace std;
int pp_8 [9] = {1, 0, 1, 1, 1, 0, 0, 0, 1}; /* specify irreducible polynomial coeffts. ex: GF(2^8) 1+x^2+x^3+x^4+x^8 = {1, 0, 1, 1, 1, 0, 0, 0, 1} */
int pp_16 [17] = {1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; /* GF(2^16) 1+x^2+x^3+x^5+x^16 = {1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} */
int alpha_to_8 [256], index_of_8 [256];
int alpha_to_16 [65536], index_of_16 [65536];
unsigned int H_Matrix_SEC_16b_bound[OECC_REDUN_LEN][OECC_CW_LEN]; // 8 x 136
unsigned int H_Matrix_SEC_32b_bound[OECC_REDUN_LEN][OECC_CW_LEN]; // 8 x 136
unsigned int H_Matrix_SEC_Un_bound[OECC_REDUN_LEN][OECC_CW_LEN]; // 8 x 136
enum OECC_TYPE {Bound_1_16=0, Bound_2_8=1, Bound_4_4=2, Bound_1_32=3, Bound_2_16=4, Bound_4_8=5, Un_bound_1_16=6, Un_bound_2_8=7, Un_bound_4_4=8, Un_bound_1_32=9, Un_bound_2_16=10, Un_bound_4_8=11}; // oecc_type
enum FAULT_TYPE {SE_SE=0, SE_MBBE=1, SE_SW=2, SE_SP=3, SE_CHIPKILL=4, MBBE_MBBE=5, MBBE_SW=6, MBBE_SP=7, MBBE_CHIPKILL=8, SW_SW=9, SW_SP=10, SW_CHIPKILL=11, SP_SP=12, SP_CHIPKILL=13, CHIPKILL_CHIPKILL=14}; // fault_type (Error)
enum RECC_TYPE {Chipkill_correct_4_2=0, Chipkill_correct_4_4=1, Chipkill_correct_2_4=2, Chipkill_correct_2_8=3, Chipkill_correct_1_8=4, Chipkill_correct_1_16=5, NO_RLECC=6}; // recc_type
enum RESULT_TYPE {NE=0, CE=1, DUE=2, SDC=3}; // result_type
/* generate GF(2**mm) from the irreducible polynomial p(X) in pp[0]..pp[mm]
lookup tables: index->polynomial form alpha_to[] contains j=alpha**i;
polynomial form -> index form index_of[j=alpha**i] = i
alpha=2 is the primitive element of GF(2**mm)
GF(2^4) 기준 (x^4+x+1)
index_of[0] = -1 -> 0000은 a^-1로 처리
index_of[a^0 (0001)] = 0
index_of[a^1 (0010)] = 1
index_of[a^2 (0100)] = 2
index_of[a^3 (1000)] = 3
index_of[a^4 (0011)] = 4
index_of[a^5 (0110)] = 5
index_of[a^6 (1100)] = 6
index_of[a^7 (1011)] = 7
index_of[a^8 (0101)] = 8
index_of[a^9 (1010)] = 9
index_of[a^10 (0111)] = 10
index_of[a^11 (1110)] = 11
index_of[a^12 (1111)] = 12
index_of[a^13 (1101)] = 13
index_of[a^14 (1001)] = 14
*/
void generate_gf()
{
//register int i, mask;
int i, mask;
int mm_8=8;
int mm_16=16;
// 1. GF(2^8)
mask = 1;
alpha_to_8[mm_8] = 0;
// a^?의 vector form에서 1이 1개인 부분 -> 0000_0001, 0000_0010, ... 1000_0000 GF(2^8) 기준
for (i=0; i<mm_8; i++){ // 0~3 GF(2^4), 0~7 GF(2^8)
alpha_to_8[i] = mask;
index_of_8[alpha_to_8[i]] = i;
if (pp_8[i]!=0)
alpha_to_8[mm_8] ^= mask;
mask <<= 1;
}
index_of_8[alpha_to_8[mm_8]] = mm_8;
// a^?의 vector form에서 1이 2개 이상인 부분
mask >>= 1 ;
for (i=mm_8+1; i<(int)pow(2.0,mm_8)-1; i++){ // 5~14, 9~254 (원래 nn)
if (alpha_to_8[i-1] >= mask)
alpha_to_8[i] = alpha_to_8[mm_8] ^ ((alpha_to_8[i-1]^mask)<<1);
else
alpha_to_8[i] = alpha_to_8[i-1]<<1;
index_of_8[alpha_to_8[i]] = i;
}
index_of_8[0] = -1;
// 2. GF(2^16)
mask = 1;
alpha_to_16[mm_16] = 0;
for (i=0; i<mm_16; i++){
alpha_to_16[i] = mask;
index_of_16[alpha_to_16[i]] = i;
if (pp_16[i]!=0)
alpha_to_16[mm_16] ^= mask;
mask <<= 1;
}
index_of_16[alpha_to_16[mm_16]] = mm_16;
mask >>= 1 ;
for (i=mm_16+1; i<(int)pow(2.0,mm_16)-1; i++){
if (alpha_to_16[i-1] >= mask)
alpha_to_16[i] = alpha_to_16[mm_16] ^ ((alpha_to_16[i-1]^mask)<<1);
else
alpha_to_16[i] = alpha_to_16[i-1]<<1;
index_of_16[alpha_to_16[i]] = i;
}
index_of_16[0] = -1;
}
// O-ECC H-matrix 생성
void generator_oecc_H_matrix()
{
FILE *fp5=fopen("H_Matrix_SEC_16b_bound.txt","r");
while(1){
unsigned int value;
for(int row=0; row<OECC_REDUN_LEN; row++){
for(int column=0; column<OECC_CW_LEN; column++){
fscanf(fp5,"%d ",&value);
H_Matrix_SEC_16b_bound[row][column]=value;
//printf("%d ",H_Matrix_binary[row][column]);
}
}
if(feof(fp5))
break;
}
fclose(fp5);
FILE *fp6=fopen("H_Matrix_SEC_32b_bound.txt","r");
while(1){
unsigned int value;
for(int row=0; row<OECC_REDUN_LEN; row++){
for(int column=0; column<OECC_CW_LEN; column++){
fscanf(fp6,"%d ",&value);
H_Matrix_SEC_32b_bound[row][column]=value;
//printf("%d ",H_Matrix_binary[row][column]);
}
}
if(feof(fp6))
break;
}
fclose(fp6);
FILE *fp4=fopen("H_Matrix_SEC_Un_bound.txt","r");
while(1){
unsigned int value;
for(int row=0; row<OECC_REDUN_LEN; row++){
for(int column=0; column<OECC_CW_LEN; column++){
fscanf(fp4,"%d ",&value);
H_Matrix_SEC_Un_bound[row][column]=value;
//printf("%d ",H_Matrix_binary[row][column]);
}
}
if(feof(fp4))
break;
}
fclose(fp4);
return;
}
// OECC, RECC, FAULT TYPE 각각의 type을 string으로 지정. 이것을 기준으로 뒤에서 error injection, oecc, recc에서 어떻게 할지 바뀐다!!!
void oecc_recc_fault_type_assignment(string &OECC, string &FAULT, string &RECC, int *oecc_type, int *fault_type, int*recc_type, int oecc, int fault, int recc)
{
// 1. OECC TYPE 지정
// int oecc, int fault, int recc는 main함수 매개변수 argv로 받은 것이다. run.py에서 변경 가능
switch (oecc){
case Bound_1_16:
OECC.replace(OECC.begin(), OECC.end(),"Bound_1_16");
*oecc_type=Bound_1_16;
break;
case Bound_2_8:
OECC.replace(OECC.begin(), OECC.end(),"Bound_2_8");
*oecc_type=Bound_2_8;
break;
case Bound_4_4:
OECC.replace(OECC.begin(), OECC.end(),"Bound_4_4");
*oecc_type=Bound_4_4;
break;
case Bound_1_32:
OECC.replace(OECC.begin(), OECC.end(),"Bound_1_32");
*oecc_type=Bound_1_32;
break;
case Bound_2_16:
OECC.replace(OECC.begin(), OECC.end(),"Bound_2_16");
*oecc_type=Bound_2_16;
break;
case Bound_4_8:
OECC.replace(OECC.begin(), OECC.end(),"Bound_4_8");
*oecc_type=Bound_4_8;
break;
case Un_bound_1_16:
OECC.replace(OECC.begin(), OECC.end(),"Un_bound_1_16");
*oecc_type=Un_bound_1_16;
break;
case Un_bound_2_8:
OECC.replace(OECC.begin(), OECC.end(),"Un_bound_2_8");
*oecc_type=Un_bound_2_8;
break;
case Un_bound_4_4:
OECC.replace(OECC.begin(), OECC.end(),"Un_bound_4_4");
*oecc_type=Un_bound_4_4;
break;
case Un_bound_1_32:
OECC.replace(OECC.begin(), OECC.end(),"Un_bound_1_32");
*oecc_type=Un_bound_1_32;
break;
case Un_bound_2_16:
OECC.replace(OECC.begin(), OECC.end(),"Un_bound_2_16");
*oecc_type=Un_bound_2_16;
break;
case Un_bound_4_8:
OECC.replace(OECC.begin(), OECC.end(),"Un_bound_4_8");
*oecc_type=Un_bound_4_8;
break;
default:
break;
}
switch (fault){
case SE_SE:
FAULT.replace(FAULT.begin(), FAULT.end(),"SE_SE");
*fault_type=SE_SE;
break;
case SE_MBBE:
FAULT.replace(FAULT.begin(), FAULT.end(),"SE_MBBE");
*fault_type=SE_MBBE;
break;
case SE_SW:
FAULT.replace(FAULT.begin(), FAULT.end(),"SE_SW");
*fault_type=SE_SW;
break;
case SE_SP:
FAULT.replace(FAULT.begin(), FAULT.end(),"SE_SP");
*fault_type=SE_SP;
break;
case SE_CHIPKILL:
FAULT.replace(FAULT.begin(), FAULT.end(),"SE_CHIPKILL");
*fault_type=SE_CHIPKILL;
break;
case MBBE_MBBE:
FAULT.replace(FAULT.begin(), FAULT.end(),"MBBE_MBBE");
*fault_type=MBBE_MBBE;
break;
case MBBE_SW:
FAULT.replace(FAULT.begin(), FAULT.end(),"MBBE_SW");
*fault_type=MBBE_SW;
break;
case MBBE_SP:
FAULT.replace(FAULT.begin(), FAULT.end(),"MBBE_SP");
*fault_type=MBBE_SP;
break;
case MBBE_CHIPKILL:
FAULT.replace(FAULT.begin(), FAULT.end(),"MBBE_CHIPKILL");
*fault_type=MBBE_CHIPKILL;
break;
case SW_SW:
FAULT.replace(FAULT.begin(), FAULT.end(),"SW_SW");
*fault_type=SW_SW;
break;
case SW_SP:
FAULT.replace(FAULT.begin(), FAULT.end(),"SW_SP");
*fault_type=SW_SP;
break;
case SW_CHIPKILL:
FAULT.replace(FAULT.begin(), FAULT.end(),"SW_CHIPKILL");
*fault_type=SW_CHIPKILL;
break;
case SP_SP:
FAULT.replace(FAULT.begin(), FAULT.end(),"SP_SP");
*fault_type=SP_SP;
break;
case SP_CHIPKILL:
FAULT.replace(FAULT.begin(), FAULT.end(),"SP_CHIPKILL");
*fault_type=SP_CHIPKILL;
break;
case CHIPKILL_CHIPKILL:
FAULT.replace(FAULT.begin(), FAULT.end(),"CHIPKILL_CHIPKILL");
*fault_type=CHIPKILL_CHIPKILL;
break;
default:
break;
}
switch (recc){
case Chipkill_correct_4_2:
RECC.replace(RECC.begin(), RECC.end(),"Chipkill_correct_4_2");
*recc_type=Chipkill_correct_4_2;
break;
case Chipkill_correct_4_4:
RECC.replace(RECC.begin(), RECC.end(),"Chipkill_correct_4_4");
*recc_type=Chipkill_correct_4_4;
break;
case Chipkill_correct_2_4:
RECC.replace(RECC.begin(), RECC.end(),"Chipkill_correct_2_4");
*recc_type=Chipkill_correct_2_4;
break;
case Chipkill_correct_2_8:
RECC.replace(RECC.begin(), RECC.end(),"Chipkill_correct_2_8");
*recc_type=Chipkill_correct_2_8;
break;
case Chipkill_correct_1_8:
RECC.replace(RECC.begin(), RECC.end(),"Chipkill_correct_1_8");
*recc_type=Chipkill_correct_1_8;
break;
case Chipkill_correct_1_16:
RECC.replace(RECC.begin(), RECC.end(),"Chipkill_correct_1_16");
*recc_type=Chipkill_correct_1_16;
break;
case NO_RLECC:
RECC.replace(RECC.begin(), RECC.end(),"NO_RLECC");
*recc_type=NO_RLECC;
break;
default:
break;
}
return;
}
// SE injection (Single Error injection)
void error_injection_SE(int Fault_Chip_position, unsigned int Chip_array[][OECC_CW_LEN], int oecc_type)
{
int Fault_pos = rand()%OECC_CW_LEN; // 0~135;
Chip_array[Fault_Chip_position][Fault_pos]^=1;
return;
}
// MBE injection (Multi bit Bounded Error injection) (More than 1 bit)
void error_injection_MBBE(int Fault_Chip_position, unsigned int Chip_array[][OECC_CW_LEN], int oecc_type)
{
int error_bound_pos;
switch(oecc_type){
case Bound_1_16:
case Un_bound_1_16:{
error_bound_pos=rand()%8; // 0~7
while(1){
int error_count=0;
for(int index=0; index<16; index++){
Chip_array[Fault_Chip_position][(error_bound_pos/4)*64+index*4+error_bound_pos%4]=rand()%2; // 0 (no-error) 'or' 1 (error)
error_count+=Chip_array[Fault_Chip_position][(error_bound_pos/4)*64+index*4+error_bound_pos%4];
}
// # of errors: more than 1-bit
if(error_count>=2)
break;
}
}
break;
case Bound_2_8:
case Un_bound_2_8:{
error_bound_pos=rand()%8; // 0~7
while(1){
int error_count=0;
for(int index=0; index<8; index++){
Chip_array[Fault_Chip_position][(error_bound_pos/2)*32+index*4+(error_bound_pos%2)*2]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][(error_bound_pos/2)*32+index*4+(error_bound_pos%2)*2+1]=rand()%2; // 0 (no-error) 'or' 1 (error)
error_count+=Chip_array[Fault_Chip_position][(error_bound_pos/2)*32+index*4+(error_bound_pos%2)*2];
error_count+=Chip_array[Fault_Chip_position][(error_bound_pos/2)*32+index*4+(error_bound_pos%2)*2+1];
}
// # of errors: more than 1-bit
if(error_count>=2)
break;
}
}
break;
case Bound_4_4:
case Un_bound_4_4:{
error_bound_pos=rand()%8; // 0~7
while(1){
int error_count=0;
for(int index=0; index<4; index++){
Chip_array[Fault_Chip_position][error_bound_pos*16+index*4]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][error_bound_pos*16+index*4+1]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][error_bound_pos*16+index*4+2]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][error_bound_pos*16+index*4+3]=rand()%2; // 0 (no-error) 'or' 1 (error)
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*16+index*4];
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*16+index*4+1];
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*16+index*4+2];
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*16+index*4+3];
}
// # of errors: more than 1-bit
if(error_count>=2)
break;
}
}
break;
case Bound_1_32:
case Un_bound_1_32:{
error_bound_pos=rand()%4; // 0~3
while(1){
int error_count=0;
for(int index=0; index<32; index++){
Chip_array[Fault_Chip_position][index*4+error_bound_pos%4]=rand()%2; // 0 (no-error) 'or' 1 (error)
error_count+=Chip_array[Fault_Chip_position][index*4+error_bound_pos%4];
}
// # of errors: more than 1-bit
if(error_count>=2)
break;
}
}
break;
case Bound_2_16:
case Un_bound_2_16:{
error_bound_pos=rand()%4; // 0~3
while(1){
int error_count=0;
for(int index=0; index<16; index++){
Chip_array[Fault_Chip_position][(error_bound_pos/2)*64+index*4+(error_bound_pos%2)*2]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][(error_bound_pos/2)*64+index*4+(error_bound_pos%2)*2+1]=rand()%2; // 0 (no-error) 'or' 1 (error)
error_count+=Chip_array[Fault_Chip_position][(error_bound_pos/2)*64+index*4+(error_bound_pos%2)*2];
error_count+=Chip_array[Fault_Chip_position][(error_bound_pos/2)*64+index*4+(error_bound_pos%2)*2+1];
}
// # of errors: more than 1-bit
if(error_count>=2)
break;
}
}
break;
case Bound_4_8:
case Un_bound_4_8:{
error_bound_pos=rand()%4; // 0~3
while(1){
int error_count=0;
for(int index=0; index<4; index++){
Chip_array[Fault_Chip_position][error_bound_pos*32+index*4]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][error_bound_pos*32+index*4+1]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][error_bound_pos*32+index*4+2]=rand()%2; // 0 (no-error) 'or' 1 (error)
Chip_array[Fault_Chip_position][error_bound_pos*32+index*4+3]=rand()%2; // 0 (no-error) 'or' 1 (error)
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*32+index*4];
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*32+index*4+1];
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*32+index*4+2];
error_count+=Chip_array[Fault_Chip_position][error_bound_pos*32+index*4+3];
}
// # of errors: more than 1-bit
if(error_count>=2)
break;
}
}
break;
default:
break;
}
return;
}
// SW injection (Single Word Error injection) -> All 4 bits are corrupted
void error_injection_SW(int Fault_Chip_position, unsigned int Chip_array[][OECC_CW_LEN], int oecc_type)
{
int fault_beat_pos = rand()%(OECC_CW_LEN/CHIP_WIDTH); // 0~33
for(int index=0; index<CHIP_WIDTH; index++) // 0~3
Chip_array[Fault_Chip_position][fault_beat_pos*CHIP_WIDTH+index]^=1;
return;
}
// SP injection (Single Pin Error injection) -> more than 2 bits
// Parity에서는 error 발생 X
void error_injection_SP(int Fault_Chip_position, unsigned int Chip_array[][OECC_CW_LEN], int oecc_type)
{
while(1){
// 0으로 초기화
for(int index=0; index<OECC_DATA_LEN; index++)
Chip_array[Fault_Chip_position][index]=0;
// error injection
int Fault_pin_pos=rand()%CHIP_WIDTH; // 0~3
int pin_error_pos=Fault_pin_pos;
while(pin_error_pos<OECC_DATA_LEN){
if(rand()%2!=0) // 0(no error) 'or' 1(bit-flip)
Chip_array[Fault_Chip_position][pin_error_pos]^=1;
pin_error_pos+=CHIP_WIDTH;
}
// 2bit 초과로 error가 발생했는지 check
int count=0;
for(int index=0; index<OECC_DATA_LEN; index++){
if(Chip_array[Fault_Chip_position][index]==1){count++;}
}
if(count>=3)
break;
}
return;
}
// Chipkill injection
void error_injection_CHIPKILL(int Fault_Chip_position, unsigned int Chip_array[][OECC_CW_LEN], int oecc_type)
{
for(int Fault_pos=0; Fault_pos<OECC_CW_LEN; Fault_pos++){ // 0~135
if(rand()%2!=0) // 0(no error) 'or' 1(bit-flip)
Chip_array[Fault_Chip_position][Fault_pos]^=1;
}
return;
}
// OECC 1bit correction
void error_correction_oecc(int Fault_Chip_position, unsigned int Chip_array[][OECC_CW_LEN], int oecc_type)
{
unsigned int Syndromes[OECC_REDUN_LEN]; // 8 x 1
int cnt=0;
switch (oecc_type){
case Bound_1_16:
// Syndromes = H * C^T
for(int row=0; row<OECC_REDUN_LEN; row++){
unsigned int row_value=0;
for(int column=0; column<16; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][60-column*CHIP_WIDTH]); // 60, 56, 52, ... 0 -> 총 16개
for(int column=16; column<32; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][61-(column-16)*CHIP_WIDTH]); // 61, 57, 53, ... 1 -> 총 16개
for(int column=32; column<48; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][62-(column-32)*CHIP_WIDTH]); // 62, 58, 54, ... 2 -> 총 16개
for(int column=48; column<64; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][63-(column-48)*CHIP_WIDTH]); // 63, 59, 55, ... 3 -> 총 16개
for(int column=64; column<80; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][124-(column-64)*CHIP_WIDTH]); // 124, 120, 116, ... 64 -> 총 16개
for(int column=80; column<96; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][125-(column-80)*CHIP_WIDTH]); // 125, 121, 117, ... 65 -> 총 16개
for(int column=96; column<112; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][126-(column-96)*CHIP_WIDTH]); // 126, 122, 118, ... 66 -> 총 16개
for(int column=112; column<128; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][127-(column-112)*CHIP_WIDTH]); // 127, 123, 119, ... 67 -> 총 16개
for(int column=128; column<136; column++) // parity 부분
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][column]); // 128~135 -> 총 8개
Syndromes[row]=row_value;
}
// error correction (Check Syndromes)
for(int error_pos=0; error_pos<OECC_CW_LEN; error_pos++){
cnt=0;
for(int row=0; row<OECC_REDUN_LEN; row++){
if(Syndromes[row]==H_Matrix_SEC_16b_bound[row][error_pos])
cnt++;
else
break;
}
// 1-bit error 일때만 error correction 진행
if(cnt==OECC_REDUN_LEN){
if(error_pos<16) // error_pos:0 => 60, error_pos:1 => 56, ... error_pos:15 => 0
Chip_array[Fault_Chip_position][60-error_pos*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<32) // error_pos:16 => 61, error_pos:17 => 57, ... error_pos:31 => 1
Chip_array[Fault_Chip_position][61-(error_pos-16)*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<48)
Chip_array[Fault_Chip_position][62-(error_pos-32)*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<64)
Chip_array[Fault_Chip_position][63-(error_pos-48)*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<80) //
Chip_array[Fault_Chip_position][124-(error_pos-64)*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<96)
Chip_array[Fault_Chip_position][125-(error_pos-80)*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<112)
Chip_array[Fault_Chip_position][126-(error_pos-96)*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<128)
Chip_array[Fault_Chip_position][127-(error_pos-112)*CHIP_WIDTH]^=1; // error correction (bit-flip)
else if(error_pos<136)
Chip_array[Fault_Chip_position][error_pos]^=1; // error correction (bit-flip)
}
}
break;
case Bound_2_8:
// Syndromes = H * C^T
for(int row=0; row<OECC_REDUN_LEN; row++){
unsigned int row_value=0;
for(int column=0; column<16; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][60-4*(column/2)+(column%2)]); // 60, 61, 56, 57, 52, 53, 48, 49, 44, 45, 40, 41, 36, 37, 32, 33 -> 총 16개
for(int column=16; column<32; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][62 - 4*((column-16)/2)+((column-16)%2)]); // 62, 63, 58, 59, 54, 55, 50, 51, 46, 47, 42, 43, 38, 39, 34, 35 -> 총 16개
for(int column=32; column<48; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][28 - 4*((column-32)/2)+((column-32)%2)]); // 28, 29, 24, 25, 20, 21, 16, 17, 12, 13, 8, 9, 4, 5, 0, 1 -> 총 16개
for(int column=48; column<64; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][30 - 4*((column-48)/2)+((column-48)%2)]); // 30, 31, 26, 27, 22, 23, 18, 19, 14, 15, 10, 11, 6, 7, 2, 3 -> 총 16개
for(int column=64; column<80; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][124 - 4*((column-64)/2)+((column-64)%2)]); // 124, 125, 120, 121, 116, 117, 112, 113, 108, 109, 104, 105, 100, 101, 96, 97 -> 총 16개
for(int column=80; column<96; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][126 - 4*((column-80)/2)+((column-80)%2)]); // 126, 127, 122, 123, 118, 119, 114, 115, 110, 111, 106, 107, 102, 103, 98, 99 -> 총 16개
for(int column=96; column<112; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][92 - 4*((column-96)/2)+((column-96)%2)]); // 92, 93, 88, 89, 84, 85, 80, 81, 76, 77, 72, 73, 68, 69, 64, 65 -> 총 16개
for(int column=112; column<128; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][94 - 4*((column-112)/2)+((column-112)%2)]); // 94, 95, 90, 91, 86, 87, 82, 83, 78, 79, 74, 75, 70, 71, 66, 67 -> 총 16개
for(int column=128; column<136; column++) // parity 부분
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][column]); // 128~135 -> 총 8개
Syndromes[row]=row_value;
}
// error correction (Check Syndromes)
for(int error_pos=0; error_pos<OECC_CW_LEN; error_pos++){
cnt=0;
for(int row=0; row<OECC_REDUN_LEN; row++){
if(Syndromes[row]==H_Matrix_SEC_16b_bound[row][error_pos])
cnt++;
else
break;
}
// 1-bit error 일때만 error correction 진행
if(cnt==OECC_REDUN_LEN){
if(error_pos<16)
Chip_array[Fault_Chip_position][60-4*(error_pos/2)+(error_pos%2)]^=1; // error correction (bit-flip)
else if(error_pos<32)
Chip_array[Fault_Chip_position][62 - 4*((error_pos-16)/2)+((error_pos-16)%2)]^=1; // error correction (bit-flip)
else if(error_pos<48)
Chip_array[Fault_Chip_position][28 - 4*((error_pos-32)/2)+((error_pos-32)%2)]^=1; // error correction (bit-flip)
else if(error_pos<64)
Chip_array[Fault_Chip_position][30 - 4*((error_pos-48)/2)+((error_pos-48)%2)]^=1; // error correction (bit-flip)
else if(error_pos<80) //
Chip_array[Fault_Chip_position][124 - 4*((error_pos-64)/2)+((error_pos-64)%2)]^=1; // error correction (bit-flip)
else if(error_pos<96)
Chip_array[Fault_Chip_position][126 - 4*((error_pos-80)/2)+((error_pos-80)%2)]^=1; // error correction (bit-flip)
else if(error_pos<112)
Chip_array[Fault_Chip_position][92 - 4*((error_pos-96)/2)+((error_pos-96)%2)]^=1; // error correction (bit-flip)
else if(error_pos<128)
Chip_array[Fault_Chip_position][94 - 4*((error_pos-112)/2)+((error_pos-112)%2)]^=1; // error correction (bit-flip)
else if(error_pos<136)
Chip_array[Fault_Chip_position][error_pos]^=1; // error correction (bit-flip)
}
}
break;
case Bound_4_4:
// Syndromes = H * C^T
for(int row=0; row<OECC_REDUN_LEN; row++){
unsigned int row_value=0;
for(int column=0; column<16; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][60-4*(column/4)+(column%4)]); // 60, 61, 62, 63, 56, 57, 58, 59, 52, 53, 54, 55, 48, 49, 50, 51 -> 총 16개
for(int column=16; column<32; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][44-4*((column-16)/4)+((column-16)%4)]); // 44, 45, 46, 47, 40, 41, 42, 43, 36, 37, 38, 39, 32, 33, 34, 35 -> 총 16개
for(int column=32; column<48; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][28-4*((column-32)/4)+((column-32)%4)]); // 28, 29, 30, 31, 24, 25, 26, 27, 20, 21, 22, 23, 16, 17, 18, 19 -> 총 16개
for(int column=48; column<64; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][12-4*((column-48)/4)+((column-48)%4)]); // 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 -> 총 16개
for(int column=64; column<80; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][124-4*((column-64)/4)+((column-64)%4)]);
for(int column=80; column<96; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][108-4*((column-80)/4)+((column-80)%4)]);
for(int column=96; column<112; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][92-4*((column-96)/4)+((column-96)%4)]);
for(int column=112; column<128; column++)
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][76-4*((column-112)/4)+((column-112)%4)]);
for(int column=128; column<136; column++) // parity 부분
row_value=row_value^(H_Matrix_SEC_16b_bound[row][column] * Chip_array[Fault_Chip_position][column]); // 128~135 -> 총 8개
Syndromes[row]=row_value;
}
// error correction (Check Syndromes)
for(int error_pos=0; error_pos<OECC_CW_LEN; error_pos++){
cnt=0;
for(int row=0; row<OECC_REDUN_LEN; row++){
if(Syndromes[row]==H_Matrix_SEC_16b_bound[row][error_pos])
cnt++;
else
break;
}
// 1-bit error 일때만 error correction 진행
if(cnt==OECC_REDUN_LEN){
if(error_pos<16)
Chip_array[Fault_Chip_position][60-4*(error_pos/4)+(error_pos%4)]^=1; // error correction (bit-flip)
else if(error_pos<32)
Chip_array[Fault_Chip_position][44-4*((error_pos-16)/4)+((error_pos-16)%4)]^=1; // error correction (bit-flip)
else if(error_pos<48)
Chip_array[Fault_Chip_position][28-4*((error_pos-32)/4)+((error_pos-32)%4)]^=1; // error correction (bit-flip)
else if(error_pos<64)
Chip_array[Fault_Chip_position][12-4*((error_pos-48)/4)+((error_pos-48)%4)]^=1; // error correction (bit-flip)
else if(error_pos<80)
Chip_array[Fault_Chip_position][124-4*((error_pos-64)/4)+((error_pos-64)%4)]^=1; // error correction (bit-flip)
else if(error_pos<96)
Chip_array[Fault_Chip_position][108-4*((error_pos-80)/4)+((error_pos-80)%4)]^=1; // error correction (bit-flip)
else if(error_pos<112)
Chip_array[Fault_Chip_position][92-4*((error_pos-96)/4)+((error_pos-96)%4)]^=1; // error correction (bit-flip)
else if(error_pos<128)
Chip_array[Fault_Chip_position][76-4*((error_pos-112)/4)+((error_pos-112)%4)]^=1; // error correction (bit-flip)
else if(error_pos<136)
Chip_array[Fault_Chip_position][error_pos]^=1; // error correction (bit-flip)
}
}
break;
case Bound_1_32:
// Syndromes = H * C^T
for(int row=0; row<OECC_REDUN_LEN; row++){
unsigned int row_value=0;
for(int column=0; column<32; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][124-4*(column)]); // 124, 120, 116, 112, 108, 104, 100, 96, 92, 88, 84, 80, 76, 72, 68, 64, ..., 0 -> 총 32개
for(int column=32; column<64; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][125-4*(column-32)]); // 125, 121, 117, 113, ... , 1 -> 총 32개
for(int column=64; column<96; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][126-4*(column-64)]); // 126, 122, ..., 2 -> 총 32개
for(int column=96; column<128; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][127-4*(column-96)]);
for(int column=128; column<136; column++) // parity 부분
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][column]); // 128~135 -> 총 8개
Syndromes[row]=row_value;
}
// error correction (Check Syndromes)
for(int error_pos=0; error_pos<OECC_CW_LEN; error_pos++){
cnt=0;
for(int row=0; row<OECC_REDUN_LEN; row++){
if(Syndromes[row]==H_Matrix_SEC_32b_bound[row][error_pos])
cnt++;
else
break;
}
// 1-bit error 일때만 error correction 진행
if(cnt==OECC_REDUN_LEN){
if(error_pos<32) // error_pos : 0 => 124, 1 => 120, 2 => 116, ...
Chip_array[Fault_Chip_position][124-4*(error_pos)]^=1; // error correction (bit-flip)
else if(error_pos<64) // error_pos : 32 => 125, 33 => 121, 34 => 117, ..
Chip_array[Fault_Chip_position][125-4*(error_pos-32)]^=1; // error correction (bit-flip)
else if(error_pos<96) //
Chip_array[Fault_Chip_position][126-4*(error_pos-64)]^=1; // error correction (bit-flip)
else if(error_pos<128)
Chip_array[Fault_Chip_position][127-4*(error_pos-96)]^=1; // error correction (bit-flip)
else if(error_pos<136)
Chip_array[Fault_Chip_position][error_pos]^=1; // error correction (bit-flip)
}
}
break;
case Bound_2_16:
// Syndromes = H * C^T
for(int row=0; row<OECC_REDUN_LEN; row++){
unsigned int row_value=0;
for(int column=0; column<32; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][60-4*(column/2)+(column%2)]); // 60, 61, 56, 57, ... 0, 1 -> 총 32개
for(int column=32; column<64; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][62-4*((column-32)/2)+((column-32)%2)]);
for(int column=64; column<96; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][124-4*((column-64)/2)+((column-64)%2)]);
for(int column=96; column<128; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][126-4*((column-96)/2)+((column-96)%2)]);
for(int column=128; column<136; column++) // parity 부분
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][column]); // 128~135 -> 총 8개
Syndromes[row]=row_value;
}
// error correction (Check Syndromes)
for(int error_pos=0; error_pos<OECC_CW_LEN; error_pos++){
cnt=0;
for(int row=0; row<OECC_REDUN_LEN; row++){
if(Syndromes[row]==H_Matrix_SEC_32b_bound[row][error_pos])
cnt++;
else
break;
}
// 1-bit error 일때만 error correction 진행
if(cnt==OECC_REDUN_LEN){
if(error_pos<32)
Chip_array[Fault_Chip_position][60-4*(error_pos/2)+(error_pos%2)]^=1; // error correction (bit-flip)
else if(error_pos<64)
Chip_array[Fault_Chip_position][62-4*((error_pos-32)/2)+((error_pos-32)%2)]^=1; // error correction (bit-flip)
else if(error_pos<96)
Chip_array[Fault_Chip_position][124-4*((error_pos-64)/2)+((error_pos-64)%2)]^=1; // error correction (bit-flip)
else if(error_pos<128)
Chip_array[Fault_Chip_position][126-4*((error_pos-96)/2)+((error_pos-96)%2)]^=1; // error correction (bit-flip)
else if(error_pos<136)
Chip_array[Fault_Chip_position][error_pos]^=1; // error correction (bit-flip)
}
}
break;
case Bound_4_8:
// Syndromes = H * C^T
for(int row=0; row<OECC_REDUN_LEN; row++){
unsigned int row_value=0;
for(int column=0; column<32; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][60-4*(column/4)+(column%4)]); // 60, 61, 62, 63, 56, 57, ..., 32, 33, 34, 35 -> 총 32개
for(int column=32; column<64; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][28-4*((column-32)/4)+((column-32)%4)]); // 28, 29, 30, 31, 24, 25, ..., 0, 1, 2, 3 -> 총 32개
for(int column=64; column<96; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][124-4*((column-64)/4)+((column-64)%4)]); // 124, ...
for(int column=96; column<128; column++)
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][92-4*((column-96)/4)+((column-96)%4)]); // 92, ...
for(int column=128; column<136; column++) // parity 부분
row_value=row_value^(H_Matrix_SEC_32b_bound[row][column] * Chip_array[Fault_Chip_position][column]); // 128~135 -> 총 8개
Syndromes[row]=row_value;
}
// error correction (Check Syndromes)
for(int error_pos=0; error_pos<OECC_CW_LEN; error_pos++){
cnt=0;
for(int row=0; row<OECC_REDUN_LEN; row++){
if(Syndromes[row]==H_Matrix_SEC_32b_bound[row][error_pos])
cnt++;
else
break;
}
// 1-bit error 일때만 error correction 진행
if(cnt==OECC_REDUN_LEN){
if(error_pos<32)
Chip_array[Fault_Chip_position][60-4*(error_pos/4)+(error_pos%4)]^=1; // error correction (bit-flip)
else if(error_pos<64)
Chip_array[Fault_Chip_position][28-4*((error_pos-32)/4)+((error_pos-32)%4)]^=1; // error correction (bit-flip)
else if(error_pos<96)
Chip_array[Fault_Chip_position][124-4*((error_pos-64)/4)+((error_pos-64)%4)]^=1; // error correction (bit-flip)
else if(error_pos<128)
Chip_array[Fault_Chip_position][92-4*((error_pos-96)/4)+((error_pos-96)%4)]^=1; // error correction (bit-flip)
else if(error_pos<136)
Chip_array[Fault_Chip_position][error_pos]^=1; // error correction (bit-flip)
}
}
break;
case Un_bound_1_16:
case Un_bound_2_8:
case Un_bound_4_4:
case Un_bound_1_32:
case Un_bound_2_16:
case Un_bound_4_8:
// Syndromes = H * C^T
for(int row=0; row<OECC_REDUN_LEN; row++){
unsigned int row_value=0;
for(int column=0; column<OECC_CW_LEN; column++)
row_value=row_value^(H_Matrix_SEC_Un_bound[row][column] * Chip_array[Fault_Chip_position][column]);
Syndromes[row]=row_value;
}
// error correction (Check Syndromes)
for(int error_pos=0; error_pos<OECC_CW_LEN; error_pos++){
cnt=0;
for(int row=0; row<OECC_REDUN_LEN; row++){
if(Syndromes[row]==H_Matrix_SEC_Un_bound[row][error_pos])
cnt++;
else
break;
}
// 1-bit error 일때만 error correction 진행
if(cnt==OECC_REDUN_LEN){
Chip_array[Fault_Chip_position][error_pos]^=1; // error correction (bit-flip)
return;
}
}
break;
default:
break;
}
// Error가 발생하지 않았거나, 발생했지만 1-bit error는 아닌 경우이다.
// 이 경우에는 correction을 진행하지 않는다.
return;
}
// GF(2^8) Rank-level ECC decoding
int decode_rs_8(int recd[], int bb[], int nn, int kk, int tt, int nn_short)
{
register int i,j,u,q ;
int elp[nn-kk+2][nn-kk], d[nn-kk+2], l[nn-kk+2], u_lu[nn-kk+2], s[nn-kk+1] ;
int count=0, syn_error=0, root[tt], loc[tt], z[tt+1], err[nn], reg[tt+1] ;
/* first form the syndromes */
for (i=1; i<=nn-kk; i++){
s[i] = 0;
for (j=0; j<nn; j++)
if (recd[j]!=-1)
s[i] ^= alpha_to_8[(recd[j]+i*j)%nn]; /* recd[j] in index form */
/* convert syndrome from polynomial form to index form */
if (s[i]!=0) syn_error=1; /* set flag if non-zero syndrome => error */
s[i] = index_of_8[s[i]];
}
/* compute the error location polynomial via the Berlekamp iterative algorithm,
following the terminology of Lin and Costello :
d[u]: the 'mu'th discrepancy, where u='mu'+1 and 'mu' (the Greek letter!) is the step number
ranging from -1 to 2*tt (see L&C)
l[u]: the degree of the elp at that step, and u_l[u] is the difference between the
step number and the degree of the elp.
*/
// Syndrome != 0 -> CE 'or' DUE 'or' SDC
if (syn_error) /* if errors, try and correct */
{
/* initialise table entries */
d[0] = 0 ; /* index form */
d[1] = s[1] ; /* index form */
elp[0][0] = 0 ; /* index form */
elp[1][0] = 1 ; /* polynomial form */
for (i=1; i<nn-kk; i++)
{ elp[0][i] = -1 ; /* index form */
elp[1][i] = 0 ; /* polynomial form */
}
l[0] = 0 ;
l[1] = 0 ;
u_lu[0] = -1 ;
u_lu[1] = 0 ;
u = 0 ;
do
{
u++ ;
if (d[u]==-1)
{ l[u+1] = l[u];
for (i=0; i<=l[u]; i++)
{ elp[u+1][i] = elp[u][i] ;
elp[u][i] = index_of_8[elp[u][i]] ;
}
}
else
/* search for words with greatest u_lu[q] for which d[q]!=0 */
{ q = u-1 ;
while ((d[q]==-1) && (q>0)) q-- ;
/* have found first non-zero d[q] */
if (q>0)
{ j=q ;
do
{ j-- ;
if ((d[j]!=-1) && (u_lu[q]<u_lu[j]))
q = j ;
}while (j>0) ;
}
/* have now found q such that d[u]!=0 and u_lu[q] is maximum */
/* store degree of new elp polynomial */
if (l[u]>l[q]+u-q) l[u+1] = l[u] ;
else l[u+1] = l[q]+u-q ;
/* form new elp(x) */
for (i=0; i<nn-kk; i++) elp[u+1][i] = 0;
for (i=0; i<=l[q]; i++)
if (elp[q][i]!=-1)
elp[u+1][i+u-q] = alpha_to_8[(d[u]+nn-d[q]+elp[q][i])%nn];
for (i=0; i<=l[u]; i++)
{ elp[u+1][i] ^= elp[u][i];
elp[u][i] = index_of_8[elp[u][i]]; /*convert old elp value to index*/
}
}
u_lu[u+1] = u-l[u+1];
/* form (u+1)th discrepancy */
if (u<nn-kk) /* no discrepancy computed on last iteration */
{
if (s[u+1]!=-1)
d[u+1] = alpha_to_8[s[u+1]] ;
else
d[u+1] = 0 ;
for (i=1; i<=l[u+1]; i++)
if ((s[u+1-i]!=-1) && (elp[u+1][i]!=0))
d[u+1] ^= alpha_to_8[(s[u+1-i]+index_of_8[elp[u+1][i]])%nn] ;
d[u+1] = index_of_8[d[u+1]] ; /* put d[u+1] into index form */
}
} while ((u<nn-kk) && (l[u+1]<=tt)) ;
u++ ;
////////////////////////////////////////////////////
// error correction start!!!!!!!!!!!!!!!!!!!!!!!!!
////////////////////////////////////////////////////
// CE 'or' SDC cases
if (l[u]<=tt) /* can correct error */
{
/* put elp into index form */
for (i=0; i<=l[u]; i++) elp[u][i] = index_of_8[elp[u][i]] ;
/* find roots of the error location polynomial -> finding error location */
for (i=1; i<=l[u]; i++)
reg[i] = elp[u][i] ;
count = 0 ;
for (i=1; i<=nn; i++){
q = 1 ;
for (j=1; j<=l[u]; j++)
if (reg[j]!=-1){
reg[j] = (reg[j]+j)%nn;
q ^= alpha_to_8[reg[j]];
}
if (!q) { /* store root and error location number indices */
root[count] = i;
loc[count] = nn-i; // -> error location
count++ ;
}
}
int CE_cases=1;
//printf("error location check! (shortened RS code!)\n");
for(int index=0; index<count; index++){
if(loc[index]>=nn_short) // except for zero-padding part!!
CE_cases=0;
}
// CE 'or' SDC cases
if (count==l[u] && CE_cases==1){ /* no. roots = degree of elp hence <= tt errors*/
//printf("CE 'or' SDC cases\n");