Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: BL_Hamming_64_8_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_Hamming_64_8_Synd_h__ | |
37 | #define __BL_Hamming_64_8_Synd_h__ | |
38 | #include "BL_BaseSynd.h" | |
39 | #include "BL_HammingEcc.h" | |
40 | ||
41 | class BL_Hamming_64_8_Synd : public BL_BaseSynd | |
42 | { | |
43 | public: | |
44 | ||
45 | BL_Hamming_64_8_Synd(uint32_t syndrome) : BL_BaseSynd(syndrome) | |
46 | { | |
47 | if (syndrome > 0xff) | |
48 | { | |
49 | fprintf(stderr,"ERROR: Bad Syndrome!"); | |
50 | exit(-1); | |
51 | } | |
52 | } | |
53 | ||
54 | BL_Hamming_64_8_Synd(uint64_t data, BL_EccBits ecc) : | |
55 | BL_BaseSynd(BL_HammingEcc:: | |
56 | get_hamming_64_8_synd(data,ecc.get()).getSyndrome()) | |
57 | { } | |
58 | ||
59 | ~BL_Hamming_64_8_Synd() {} | |
60 | ||
61 | bool isDoubleBitError() const { return (syndrome_ - 1) < 0x7F; } | |
62 | ||
63 | bool isSingleBitError() const { return (syndrome_ - 0x80) < 0x48; } | |
64 | ||
65 | // ((syndrome_ - 0x80) & syndrome_ - 0x81)) returns true if | |
66 | // "syndrome_ - 0x80"is *NOT* a power of 2. See Table A-3 to see | |
67 | // that this is true for all data bits. | |
68 | bool isDataBitError() const | |
69 | { | |
70 | return (isSingleBitError() && ((syndrome_ - 0x80) & syndrome_ - 0x81)); | |
71 | } | |
72 | ||
73 | // This method works because the check bits are at powers of 2 | |
74 | // (after substracting 0x80) so the data bits break up into | |
75 | // large ranges. | |
76 | uint32_t getDataBit() const | |
77 | { | |
78 | if (!isDataBitError()) | |
79 | { | |
80 | fprintf(stderr,"ERROR: Not data bit error!"); | |
81 | exit(-1); | |
82 | } | |
83 | ||
84 | uint32_t bit = syndrome_ - 0x80; | |
85 | if (bit >= 0x20) | |
86 | return (bit >= 0x40) ? bit - 8 : bit - 7; | |
87 | else if (bit >= 0x10) | |
88 | return bit - 6; | |
89 | else if (bit > 8) | |
90 | return bit - 5; | |
91 | else if (bit > 4) | |
92 | return bit - 4; | |
93 | else | |
94 | return bit - 3; | |
95 | } | |
96 | ||
97 | // ((syndrome_ - 0x80) & (syndrome_ - 0x81)) returns true if | |
98 | // "syndrome_ - 0x80" is a power of 2. See Table A-3 to see | |
99 | // that this is true for all check bits. | |
100 | bool isCheckBitError() const | |
101 | { | |
102 | return (isSingleBitError() && !((syndrome_ - 0x80) & syndrome_ - 0x81)); | |
103 | } | |
104 | ||
105 | // This method works because the check bits are at powers of 2 | |
106 | // (after substracting 0x80) so this divide and conquer search | |
107 | // is quite fast. | |
108 | uint32_t getCheckBit() const | |
109 | { | |
110 | if (!isCheckBitError()) | |
111 | { | |
112 | fprintf(stderr,"ERROR: Not check bit error!"); | |
113 | exit(-1); | |
114 | } | |
115 | ||
116 | uint32_t bit = syndrome_ - 0x80; | |
117 | if (bit >= 0x20) | |
118 | return (bit >= 0x40) ? 6 : 5; | |
119 | else if (bit >= 0x10) | |
120 | return 4; | |
121 | else if (bit == 8) | |
122 | return 3; | |
123 | else if (bit == 4) | |
124 | return 2; | |
125 | else | |
126 | return (bit == 0) ? 7 : bit - 1; | |
127 | } | |
128 | ||
129 | bool isMultipleBitError() const { return (syndrome_ - 0xc8) < (0x38); } | |
130 | ||
131 | static BL_EccBits calc_check_bits(unsigned long long data) | |
132 | { | |
133 | return BL_HammingEcc::calc_check_bits(BL_HammingEcc::BL_Hamming_64_8, data); | |
134 | } | |
135 | ||
136 | #define BL_HAMMING_64_8_DIE(S) { \ | |
137 | fprintf(stderr, S " line: %d\n", __LINE__); \ | |
138 | exit(-1); \ | |
139 | } | |
140 | static void validate() | |
141 | { | |
142 | uint64_t data = 0x123456789ABCDEF; | |
143 | uint32_t ecc = BL_Hamming_64_8_Synd::calc_check_bits(data).get(); | |
144 | ||
145 | BL_Hamming_64_8_Synd syndrome = | |
146 | BL_HammingEcc::get_hamming_64_8_synd(data, ecc); | |
147 | ||
148 | if (!syndrome.noError()) | |
149 | BL_HAMMING_64_8_DIE("NoError fails"); | |
150 | ||
151 | int i; | |
152 | for (i = 0; i < 64; ++i) { | |
153 | syndrome = | |
154 | BL_HammingEcc::get_hamming_64_8_synd((1ULL<<i)^data, ecc); | |
155 | ||
156 | if (syndrome.noError()) | |
157 | BL_HAMMING_64_8_DIE("NoError succeeds"); | |
158 | ||
159 | if (!syndrome.isSingleBitError()) | |
160 | BL_HAMMING_64_8_DIE("isSingleBit fails"); | |
161 | ||
162 | if (syndrome.isDoubleBitError()) | |
163 | BL_HAMMING_64_8_DIE("isDoubleBit succeeds"); | |
164 | ||
165 | if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError()) | |
166 | BL_HAMMING_64_8_DIE("isMultipleBit/isUncorrectable succeeds"); | |
167 | ||
168 | if (syndrome.getDataBit() != i) | |
169 | BL_HAMMING_64_8_DIE("getDataBit mismatch"); | |
170 | } | |
171 | ||
172 | for (i = 0; i < 8; ++i) { | |
173 | syndrome = | |
174 | BL_HammingEcc::get_hamming_64_8_synd(data, (1ULL<<i)^ecc); | |
175 | ||
176 | if (syndrome.noError()) | |
177 | BL_HAMMING_64_8_DIE("NoError succeeds"); | |
178 | ||
179 | if (!syndrome.isSingleBitError()) | |
180 | BL_HAMMING_64_8_DIE("isSingleBit fails"); | |
181 | ||
182 | if (syndrome.isDoubleBitError()) | |
183 | BL_HAMMING_64_8_DIE("isDoubleBit succeeds"); | |
184 | ||
185 | if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError()) | |
186 | BL_HAMMING_64_8_DIE("isMultipleBit/isUncorrectable succeeds"); | |
187 | ||
188 | if (syndrome.getCheckBit() != i) | |
189 | BL_HAMMING_64_8_DIE("getCheckBit mismatch"); | |
190 | } | |
191 | ||
192 | for (i = 1; i < 64; ++i) { | |
193 | int j; | |
194 | ||
195 | for (j = 0; j < i; ++j) { | |
196 | syndrome = | |
197 | BL_HammingEcc::get_hamming_64_8_synd((1ULL<<i)^(1ULL<<j)^data, | |
198 | ecc); | |
199 | ||
200 | if (syndrome.noError()) | |
201 | BL_HAMMING_64_8_DIE("NoError succeeds"); | |
202 | ||
203 | if (syndrome.isSingleBitError()) | |
204 | BL_HAMMING_64_8_DIE("isSingleBit succeeds"); | |
205 | ||
206 | if (!syndrome.isDoubleBitError()) | |
207 | BL_HAMMING_64_8_DIE("isDoubleBit fails"); | |
208 | ||
209 | if (syndrome.isMultipleBitError()) | |
210 | BL_HAMMING_64_8_DIE("isMultipleBit succeeds"); | |
211 | ||
212 | if (!syndrome.isUncorrectableError()) | |
213 | BL_HAMMING_64_8_DIE("isUncorrectable fails"); | |
214 | } | |
215 | } | |
216 | ||
217 | for (i = 1; i < 8; ++i) { | |
218 | int j; | |
219 | ||
220 | for (j = 0; j < i; ++j) { | |
221 | syndrome = | |
222 | BL_HammingEcc::get_hamming_64_8_synd(data, | |
223 | (1ULL<<i)^(1ULL<<j)^ecc); | |
224 | ||
225 | if (syndrome.noError()) | |
226 | BL_HAMMING_64_8_DIE("NoError succeeds"); | |
227 | ||
228 | if (syndrome.isSingleBitError()) | |
229 | BL_HAMMING_64_8_DIE("isSingleBit succeeds"); | |
230 | ||
231 | if (!syndrome.isDoubleBitError()) | |
232 | BL_HAMMING_64_8_DIE("isDoubleBit fails"); | |
233 | ||
234 | if (syndrome.isMultipleBitError()) | |
235 | BL_HAMMING_64_8_DIE("isMultipleBit succeeds"); | |
236 | ||
237 | if (!syndrome.isUncorrectableError()) | |
238 | BL_HAMMING_64_8_DIE("isUncorrectable fails"); | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | #undef BL_HAMMING_64_8_DIE | |
244 | ||
245 | private: | |
246 | ||
247 | BL_Hamming_64_8_Synd(); | |
248 | }; | |
249 | ||
250 | #endif |