Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / ecc / src / BL_Hsiao_256_10_Synd.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: BL_Hsiao_256_10_Synd.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23/************************************************************************
24 **
25 ** Copyright (C) 2006, Sun Microsystems, Inc.
26 **
27 ** Sun considers its source code as an unpublished, proprietary
28 ** trade secret and it is available only under strict license provisions.
29 ** This copyright notice is placed here only to protect Sun in the event
30 ** the source is deemed a published work. Disassembly, decompilation,
31 ** or other means of reducing the object code to human readable form
32 ** is prohibited by the license agreement under which this code is
33 ** provided to the user or company in possession of this copy.
34 **
35 *************************************************************************/
36#ifndef __BL_Hsiao_256_10_Synd_h__
37#define __BL_Hsiao_256_10_Synd_h__
38#include "BL_Utils.h"
39#include "BL_BaseSynd.h"
40#include "BL_HsiaoEcc.h"
41
42class BL_Hsiao_256_10_Synd : public BL_BaseSynd
43{
44 public:
45
46 BL_Hsiao_256_10_Synd(uint32_t syndrome) : BL_BaseSynd(syndrome)
47 {
48 if (syndrome > 0x3ff)
49 {
50 fprintf(stderr,"ERROR: Bad Syndrome: 0x%x", syndrome);
51 exit(-1);
52 }
53 }
54
55 BL_Hsiao_256_10_Synd(BL_Uint256 data, BL_EccBits ecc) :
56 BL_BaseSynd(BL_Hsiao_256_10_Synd::calc_check_bits(data).get() ^ ecc.get())
57 {}
58
59
60 ~BL_Hsiao_256_10_Synd() {}
61
62 bool isDoubleBitError() const
63 {
64 return (syndrome_ != 0) && !isSingleBitError();
65 }
66
67 bool isSingleBitError() const
68 {
69 if (syndrome_ == 0)
70 return false;
71 switch (nr_bits_set())
72 {
73 case 1:
74 case 3:
75 return true;
76 case 5:
77 return find_syndrome_ndx() != -1;
78 default:
79 return false;
80 }
81 }
82
83 bool isDataBitError() const
84 {
85 return (isSingleBitError() && nr_bits_set() > 1);
86 }
87
88 // This method works because the check bits are at powers of 2
89 // (after substracting 0x80) so the data bits break up into
90 // large ranges.
91 uint32_t getDataBit() const
92 {
93 if (!isDataBitError())
94 {
95 fprintf(stderr,"ERROR: Not data bit error!");
96 exit(-1);
97 }
98
99 return find_syndrome_ndx();
100 }
101
102 bool isCheckBitError() const
103 {
104 return (isSingleBitError() && is_power_of_two(syndrome_));
105 }
106
107 uint32_t getCheckBit() const
108 {
109 if (!isCheckBitError())
110 {
111 fprintf(stderr,"ERROR: Not check bit error!");
112 exit(-1);
113 }
114 return bit2idx(syndrome_);
115 }
116
117 bool isMultipleBitError() const { return false; }
118
119 static BL_EccBits calc_check_bits(BL_Uint256 data)
120 {
121 BL_Uint256 *patterns =
122 BL_Hsiao_256_10_Synd::hsiao_256_10_patterns.patterns;
123 return calc_checks(10, patterns, data);
124
125 }
126
127 private:
128
129 BL_Hsiao_256_10_Synd();
130
131 // Number of bits set in syndrome
132 // This trick works up to 12 bits
133 uint_t nr_bits_set() const
134 {
135 return (syndrome_ * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
136 }
137
138 int find_syndrome_ndx() const
139 {
140 switch (nr_bits_set())
141 {
142 case 3:
143 for (uint_t ndx = 0; ndx < 120; ++ndx)
144 if (syndrome_ == hsiao_256_10_patterns.get(ndx).get())
145 return ndx;
146 assert(0);
147 break;
148 case 5:
149 for (uint_t ndx = 120; ndx < 256; ++ndx)
150 if (syndrome_ == hsiao_256_10_patterns.get(ndx).get())
151 return ndx;
152 default:
153 break;
154 }
155 return -1; // -1 is didn't find it
156 }
157
158 class Patterns
159 {
160 public:
161 BL_Uint256 patterns[10];
162
163 Patterns();
164
165 ~Patterns() {}
166
167 BL_EccBits get(uint_t ndx) const { return syndromes[ndx]; }
168
169 private:
170
171 static uint64_t calc_pattern(uint_t syndrome_ndx, uint_t pattern_ndx);
172
173 static BL_EccBits syndromes[256];
174 };
175
176 static Patterns hsiao_256_10_patterns;
177
178};
179
180#endif