Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: BL_BaseEcc.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_BaseEcc_h__ | |
37 | #define __BL_BaseEcc_h__ | |
38 | #include <assert.h> | |
39 | #include "BL_BitUtility.h" | |
40 | ||
41 | class BL_EccBits | |
42 | { | |
43 | public: | |
44 | ||
45 | BL_EccBits() : check_bits(0), is_valid(0) {} | |
46 | ||
47 | BL_EccBits(unsigned short _check_bits) : check_bits(_check_bits), is_valid(true) {} | |
48 | ||
49 | virtual ~BL_EccBits() {} | |
50 | ||
51 | unsigned short get() const | |
52 | { | |
53 | assert(is_valid); return check_bits; | |
54 | } | |
55 | ||
56 | BL_EccBits& set(unsigned short _check_bits) | |
57 | { | |
58 | is_valid = true; check_bits = _check_bits; | |
59 | return *this; | |
60 | } | |
61 | ||
62 | bool valid() const { return is_valid; } | |
63 | ||
64 | BL_EccBits& valid(bool v) { is_valid = v; return *this; } | |
65 | ||
66 | private: | |
67 | unsigned short is_valid:1; | |
68 | unsigned short check_bits:15; | |
69 | }; | |
70 | ||
71 | // This method calculates the ecc check bits for a given data item and | |
72 | // requires three parameters | |
73 | // The first parameter specifies the number of ECC check bits | |
74 | // The second parameter provide the masks that are required to identify | |
75 | // which data bits are associated with a given check bit | |
76 | // Masks are provided with the "most significant check bits first" | |
77 | // The third parameter is the data | |
78 | template <typename DataType> | |
79 | BL_EccBits calc_checks(unsigned n_patterns, | |
80 | DataType *patterns, DataType data) | |
81 | { | |
82 | unsigned i; | |
83 | unsigned parity; | |
84 | unsigned checks = 0; | |
85 | ||
86 | // for each check bit | |
87 | for (i = 0; i < n_patterns; i++) | |
88 | { | |
89 | // Calculate check bit value | |
90 | parity = BL_BitUtility::calc_parity( data & *patterns++ ); | |
91 | // Accumulate check bits | |
92 | checks <<= 1; | |
93 | checks |= parity; | |
94 | } | |
95 | //return checks; | |
96 | return BL_EccBits(checks); | |
97 | } | |
98 | ||
99 | #endif |