Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / ecc / src / BL_HammingEcc.cc
CommitLineData
920dae64
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: BL_HammingEcc.cc
4// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6//
7// The above named program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public
9// License version 2 as published by the Free Software Foundation.
10//
11// The above named program is distributed in the hope that it will be
12// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public
17// License along with this work; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19//
20// ========== Copyright Header End ============================================
21/************************************************************************
22**
23** Copyright (C) 2006, Sun Microsystems, Inc.
24**
25** Sun considers its source code as an unpublished, proprietary
26** trade secret and it is available only under strict license provisions.
27** This copyright notice is placed here only to protect Sun in the event
28** the source is deemed a published work. Disassembly, decompilation,
29** or other means of reducing the object code to human readable form
30** is prohibited by the license agreement under which this code is
31** provided to the user or company in possession of this copy."
32**
33*************************************************************************/
34#include "BL_HammingEcc.h"
35#include "BL_Hamming_22_6_Synd.h"
36#include "BL_Hamming_32_7_Synd.h"
37#include "BL_Hamming_64_8_Synd.h"
38
39using namespace std;
40
41uint64_t BL_HammingEcc::hamming_22_6_ecc_masks[] =
42{
43 0xa65cb7, // check bit 5
44 0xfff800, // check bit 4
45 0xfc07f0, // check bit 3
46 0xc3c78e, // check bit 2
47 0x33366d, // check bit 1
48 0xaaad5b, // check bit 0
49};
50
51uint64_t BL_HammingEcc::hamming_32_7_ecc_masks[] =
52{
53 0x2da65cb7, // check bit 6
54 0xfc000000, // check bit 5
55 0x03fff800, // check bit 4
56 0x03fc07f0, // check bit 3
57 0xe3c3c78e, // check bit 2
58 0x9b33366d, // check bit 1
59 0x56aaad5b, // check bit 0
60};
61
62uint64_t BL_HammingEcc::hamming_64_8_ecc_masks[] =
63{
64 0x972cd2d32da65cb7, // c7
65 0xfe00000000000000, // c6
66 0x01fffffffc000000, // c5
67 0x01fffe0003fff800, // c4
68 0x01fe01fe03fc07f0, // c3
69 0xf1e1e1e1e3c3c78e, // c2
70 0xcd9999999b33366d, // c1
71 0xab55555556aaad5b, // c0
72};
73
74#define HAMMING_22_6_ECC_MASKS (sizeof(hamming_22_6_ecc_masks)/sizeof(hamming_22_6_ecc_masks[0]))
75
76#define HAMMING_32_7_ECC_MASKS (sizeof(hamming_32_7_ecc_masks)/sizeof(hamming_32_7_ecc_masks[0]))
77
78#define HAMMING_64_8_ECC_MASKS (sizeof(hamming_64_8_ecc_masks)/sizeof(hamming_64_8_ecc_masks[0]))
79
80BL_EccBits BL_HammingEcc::calc_check_bits(BL_HammingEccTypes type, uint64_t data)
81{
82 if (type == BL_Hamming_22_6)
83 {
84 return calc_checks(HAMMING_22_6_ECC_MASKS,hamming_22_6_ecc_masks,data);
85 }
86 else if (type == BL_Hamming_32_7)
87 {
88 return calc_checks(HAMMING_32_7_ECC_MASKS,hamming_32_7_ecc_masks,data);
89 }
90 else if (type == BL_Hamming_64_8)
91 {
92 return calc_checks(HAMMING_64_8_ECC_MASKS,hamming_64_8_ecc_masks,data);
93 }
94}
95
96// This method generates an 22/6 hamming syndrome and returns the
97// value Syndrome is the result of XOR'ing the calculated ecc value
98// and stored ecc value
99BL_Hamming_22_6_Synd BL_HammingEcc::get_hamming_22_6_synd(uint32_t data,
100 uint32_t stored_ecc_val)
101{
102 uint32_t calc_ecc_val =
103 BL_HammingEcc::calc_check_bits(BL_Hamming_22_6, data).get();
104 uint32_t syndrome = calc_ecc_val ^ stored_ecc_val;
105 syndrome = BL_BaseSynd::maskedSyndrome(syndrome, data, stored_ecc_val, 5);
106 return BL_Hamming_22_6_Synd(syndrome);
107}
108
109// This method generates a 32/7 syndrome and returns the value
110// Syndrome is the result of XOR'ing the calculated ecc value and
111// stored ecc value
112BL_Hamming_32_7_Synd BL_HammingEcc::get_hamming_32_7_synd(uint32_t data,
113 uint32_t stored_ecc_val)
114{
115 uint32_t calc_ecc_val =
116 BL_HammingEcc::calc_check_bits(BL_Hamming_32_7, data).get();
117 uint32_t syndrome = calc_ecc_val ^ stored_ecc_val;
118 syndrome = BL_BaseSynd::maskedSyndrome(syndrome, data, stored_ecc_val, 6);
119 return BL_Hamming_32_7_Synd(syndrome);
120}
121
122// This method generates an 64/8 syndrome and returns the value
123// Syndrome is the result of XOR'ing the calculated ecc value and
124// stored ecc value
125BL_Hamming_64_8_Synd BL_HammingEcc::get_hamming_64_8_synd(uint64_t data,
126 uint64_t stored_ecc_val)
127{
128 uint64_t calc_ecc_val =
129 BL_HammingEcc::calc_check_bits(BL_Hamming_64_8, data).get();
130 uint64_t syndrome = calc_ecc_val ^ stored_ecc_val;
131 syndrome = BL_BaseSynd::maskedSyndrome(syndrome, data, stored_ecc_val, 7);
132 return BL_Hamming_64_8_Synd(syndrome);
133}