Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / ecc / src / BL_Hsiao_256_10_Synd.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: BL_Hsiao_256_10_Synd.cc
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
//
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
//
// The above named program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// ========== Copyright Header End ============================================
/************************************************************************
**
** Copyright (C) 2006, Sun Microsystems, Inc.
**
** Sun considers its source code as an unpublished, proprietary
** trade secret and it is available only under strict license provisions.
** This copyright notice is placed here only to protect Sun in the event
** the source is deemed a published work. Disassembly, decompilation,
** or other means of reducing the object code to human readable form
** is prohibited by the license agreement under which this code is
** provided to the user or company in possession of this copy.
**
*************************************************************************/
#include <stdlib.h>
#include "BL_Types.h"
#include "BL_Hsiao_256_10_Synd.h"
BL_EccBits BL_Hsiao_256_10_Synd::Patterns::syndromes[256];
BL_Hsiao_256_10_Synd::Patterns BL_Hsiao_256_10_Synd::hsiao_256_10_patterns;
BL_Hsiao_256_10_Synd::Patterns::Patterns()
{
// These syndromes are defined in PRM 1.3 Section 16.14.1
// Note they are written in base 2 so we use strtoul() to convert them.
syndromes[0] = strtoul("1110000000", NULL, 2);
syndromes[1] = strtoul("1101000000", NULL, 2);
syndromes[2] = strtoul("1011000000", NULL, 2);
syndromes[3] = strtoul("0111000000", NULL, 2);
syndromes[4] = strtoul("1100100000", NULL, 2);
syndromes[5] = strtoul("1010100000", NULL, 2);
syndromes[6] = strtoul("0110100000", NULL, 2);
syndromes[7] = strtoul("1001100000", NULL, 2);
syndromes[8] = strtoul("0101100000", NULL, 2);
syndromes[9] = strtoul("0011100000", NULL, 2);
syndromes[10] = strtoul("1100010000", NULL, 2);
syndromes[11] = strtoul("1010010000", NULL, 2);
syndromes[12] = strtoul("0110010000", NULL, 2);
syndromes[13] = strtoul("1001010000", NULL, 2);
syndromes[14] = strtoul("0101010000", NULL, 2);
syndromes[15] = strtoul("0011010000", NULL, 2);
syndromes[16] = strtoul("1000110000", NULL, 2);
syndromes[17] = strtoul("0100110000", NULL, 2);
syndromes[18] = strtoul("0010110000", NULL, 2);
syndromes[19] = strtoul("0001110000", NULL, 2);
syndromes[20] = strtoul("1100001000", NULL, 2);
syndromes[21] = strtoul("1010001000", NULL, 2);
syndromes[22] = strtoul("0110001000", NULL, 2);
syndromes[23] = strtoul("1001001000", NULL, 2);
syndromes[24] = strtoul("0101001000", NULL, 2);
syndromes[25] = strtoul("0011001000", NULL, 2);
syndromes[26] = strtoul("1000101000", NULL, 2);
syndromes[27] = strtoul("0100101000", NULL, 2);
syndromes[28] = strtoul("0010101000", NULL, 2);
syndromes[29] = strtoul("0001101000", NULL, 2);
syndromes[30] = strtoul("1000011000", NULL, 2);
syndromes[31] = strtoul("0100011000", NULL, 2);
syndromes[32] = strtoul("0010011000", NULL, 2);
syndromes[33] = strtoul("0001011000", NULL, 2);
syndromes[34] = strtoul("0000111000", NULL, 2);
syndromes[35] = strtoul("1100000100", NULL, 2);
syndromes[36] = strtoul("1010000100", NULL, 2);
syndromes[37] = strtoul("0110000100", NULL, 2);
syndromes[38] = strtoul("1001000100", NULL, 2);
syndromes[39] = strtoul("0101000100", NULL, 2);
syndromes[40] = strtoul("0011000100", NULL, 2);
syndromes[41] = strtoul("1000100100", NULL, 2);
syndromes[42] = strtoul("0100100100", NULL, 2);
syndromes[43] = strtoul("0010100100", NULL, 2);
syndromes[44] = strtoul("0001100100", NULL, 2);
syndromes[45] = strtoul("1000010100", NULL, 2);
syndromes[46] = strtoul("0100010100", NULL, 2);
syndromes[47] = strtoul("0010010100", NULL, 2);
syndromes[48] = strtoul("0001010100", NULL, 2);
syndromes[49] = strtoul("0000110100", NULL, 2);
syndromes[50] = strtoul("1000001100", NULL, 2);
syndromes[51] = strtoul("0100001100", NULL, 2);
syndromes[52] = strtoul("0010001100", NULL, 2);
syndromes[53] = strtoul("0001001100", NULL, 2);
syndromes[54] = strtoul("0000101100", NULL, 2);
syndromes[55] = strtoul("0000011100", NULL, 2);
syndromes[56] = strtoul("1100000010", NULL, 2);
syndromes[57] = strtoul("1010000010", NULL, 2);
syndromes[58] = strtoul("0110000010", NULL, 2);
syndromes[59] = strtoul("1001000010", NULL, 2);
syndromes[60] = strtoul("0101000010", NULL, 2);
syndromes[61] = strtoul("0011000010", NULL, 2);
syndromes[62] = strtoul("1000100010", NULL, 2);
syndromes[63] = strtoul("0100100010", NULL, 2);
syndromes[64] = strtoul("0010100010", NULL, 2);
syndromes[65] = strtoul("0001100010", NULL, 2);
syndromes[66] = strtoul("1000010010", NULL, 2);
syndromes[67] = strtoul("0100010010", NULL, 2);
syndromes[68] = strtoul("0010010010", NULL, 2);
syndromes[69] = strtoul("0001010010", NULL, 2);
syndromes[70] = strtoul("0000110010", NULL, 2);
syndromes[71] = strtoul("1000001010", NULL, 2);
syndromes[72] = strtoul("0100001010", NULL, 2);
syndromes[73] = strtoul("0010001010", NULL, 2);
syndromes[74] = strtoul("0001001010", NULL, 2);
syndromes[75] = strtoul("0000101010", NULL, 2);
syndromes[76] = strtoul("0000011010", NULL, 2);
syndromes[77] = strtoul("1000000110", NULL, 2);
syndromes[78] = strtoul("0100000110", NULL, 2);
syndromes[79] = strtoul("0010000110", NULL, 2);
syndromes[80] = strtoul("0001000110", NULL, 2);
syndromes[81] = strtoul("0000100110", NULL, 2);
syndromes[82] = strtoul("0000010110", NULL, 2);
syndromes[83] = strtoul("0000001110", NULL, 2);
syndromes[84] = strtoul("1100000001", NULL, 2);
syndromes[85] = strtoul("1010000001", NULL, 2);
syndromes[86] = strtoul("0110000001", NULL, 2);
syndromes[87] = strtoul("1001000001", NULL, 2);
syndromes[88] = strtoul("0101000001", NULL, 2);
syndromes[89] = strtoul("0011000001", NULL, 2);
syndromes[90] = strtoul("1000100001", NULL, 2);
syndromes[91] = strtoul("0100100001", NULL, 2);
syndromes[92] = strtoul("0010100001", NULL, 2);
syndromes[93] = strtoul("0001100001", NULL, 2);
syndromes[94] = strtoul("1000010001", NULL, 2);
syndromes[95] = strtoul("0100010001", NULL, 2);
syndromes[96] = strtoul("0010010001", NULL, 2);
syndromes[97] = strtoul("0001010001", NULL, 2);
syndromes[98] = strtoul("0000110001", NULL, 2);
syndromes[99] = strtoul("1000001001", NULL, 2);
syndromes[100] = strtoul("0100001001", NULL, 2);
syndromes[101] = strtoul("0010001001", NULL, 2);
syndromes[102] = strtoul("0001001001", NULL, 2);
syndromes[103] = strtoul("0000101001", NULL, 2);
syndromes[104] = strtoul("0000011001", NULL, 2);
syndromes[105] = strtoul("1000000101", NULL, 2);
syndromes[106] = strtoul("0100000101", NULL, 2);
syndromes[107] = strtoul("0010000101", NULL, 2);
syndromes[108] = strtoul("0001000101", NULL, 2);
syndromes[109] = strtoul("0000100101", NULL, 2);
syndromes[110] = strtoul("0000010101", NULL, 2);
syndromes[111] = strtoul("0000001101", NULL, 2);
syndromes[112] = strtoul("1000000011", NULL, 2);
syndromes[113] = strtoul("0100000011", NULL, 2);
syndromes[114] = strtoul("0010000011", NULL, 2);
syndromes[115] = strtoul("0001000011", NULL, 2);
syndromes[116] = strtoul("0000100011", NULL, 2);
syndromes[117] = strtoul("0000010011", NULL, 2);
syndromes[118] = strtoul("0000001011", NULL, 2);
syndromes[119] = strtoul("0000000111", NULL, 2);
syndromes[120] = strtoul("1111100000", NULL, 2);
syndromes[121] = strtoul("0000011111", NULL, 2);
syndromes[122] = strtoul("1111010000", NULL, 2);
syndromes[123] = strtoul("0000101111", NULL, 2);
syndromes[124] = strtoul("0111101000", NULL, 2);
syndromes[125] = strtoul("1000010111", NULL, 2);
syndromes[126] = strtoul("0011100110", NULL, 2);
syndromes[127] = strtoul("1100011001", NULL, 2);
syndromes[128] = strtoul("1100010110", NULL, 2);
syndromes[129] = strtoul("0011101001", NULL, 2);
syndromes[130] = strtoul("1010010110", NULL, 2);
syndromes[131] = strtoul("0101101001", NULL, 2);
syndromes[132] = strtoul("0110010110", NULL, 2);
syndromes[133] = strtoul("1001101001", NULL, 2);
syndromes[134] = strtoul("1001010110", NULL, 2);
syndromes[135] = strtoul("0110101001", NULL, 2);
syndromes[136] = strtoul("0101010110", NULL, 2);
syndromes[137] = strtoul("1010101001", NULL, 2);
syndromes[138] = strtoul("0011010110", NULL, 2);
syndromes[139] = strtoul("1100101001", NULL, 2);
syndromes[140] = strtoul("1000110110", NULL, 2);
syndromes[141] = strtoul("0111001001", NULL, 2);
syndromes[142] = strtoul("0100110110", NULL, 2);
syndromes[143] = strtoul("1011001001", NULL, 2);
syndromes[144] = strtoul("0010110110", NULL, 2);
syndromes[145] = strtoul("1101001001", NULL, 2);
syndromes[146] = strtoul("1110011000", NULL, 2);
syndromes[147] = strtoul("0001100111", NULL, 2);
syndromes[148] = strtoul("0001110110", NULL, 2);
syndromes[149] = strtoul("1110001001", NULL, 2);
syndromes[150] = strtoul("1100001110", NULL, 2);
syndromes[151] = strtoul("0011110001", NULL, 2);
syndromes[152] = strtoul("1010001110", NULL, 2);
syndromes[153] = strtoul("0101110001", NULL, 2);
syndromes[154] = strtoul("0110001110", NULL, 2);
syndromes[155] = strtoul("1001110001", NULL, 2);
syndromes[156] = strtoul("1001001110", NULL, 2);
syndromes[157] = strtoul("0110110001", NULL, 2);
syndromes[158] = strtoul("0101001110", NULL, 2);
syndromes[159] = strtoul("1010110001", NULL, 2);
syndromes[160] = strtoul("0011001110", NULL, 2);
syndromes[161] = strtoul("1100110001", NULL, 2);
syndromes[162] = strtoul("1000101110", NULL, 2);
syndromes[163] = strtoul("0111010001", NULL, 2);
syndromes[164] = strtoul("0100101110", NULL, 2);
syndromes[165] = strtoul("1011010001", NULL, 2);
syndromes[166] = strtoul("0010101110", NULL, 2);
syndromes[167] = strtoul("1101010001", NULL, 2);
syndromes[168] = strtoul("1101011000", NULL, 2);
syndromes[169] = strtoul("0010100111", NULL, 2);
syndromes[170] = strtoul("0001101110", NULL, 2);
syndromes[171] = strtoul("1110010001", NULL, 2);
syndromes[172] = strtoul("1000011110", NULL, 2);
syndromes[173] = strtoul("0111100001", NULL, 2);
syndromes[174] = strtoul("0100011110", NULL, 2);
syndromes[175] = strtoul("1011100001", NULL, 2);
syndromes[176] = strtoul("0010011110", NULL, 2);
syndromes[177] = strtoul("1101100001", NULL, 2);
syndromes[178] = strtoul("0001011110", NULL, 2);
syndromes[179] = strtoul("1110100001", NULL, 2);
syndromes[180] = strtoul("0000111110", NULL, 2);
syndromes[181] = strtoul("1111000001", NULL, 2);
syndromes[182] = strtoul("1011011000", NULL, 2);
syndromes[183] = strtoul("0100100111", NULL, 2);
syndromes[184] = strtoul("0111011000", NULL, 2);
syndromes[185] = strtoul("1000100111", NULL, 2);
syndromes[186] = strtoul("1100111000", NULL, 2);
syndromes[187] = strtoul("0011000111", NULL, 2);
syndromes[188] = strtoul("1010011001", NULL, 2);
syndromes[189] = strtoul("0101100110", NULL, 2);
syndromes[190] = strtoul("0110011001", NULL, 2);
syndromes[191] = strtoul("1001100110", NULL, 2);
syndromes[192] = strtoul("1001011001", NULL, 2);
syndromes[193] = strtoul("0110100110", NULL, 2);
syndromes[194] = strtoul("0101011001", NULL, 2);
syndromes[195] = strtoul("1010100110", NULL, 2);
syndromes[196] = strtoul("0011011001", NULL, 2);
syndromes[197] = strtoul("1100100110", NULL, 2);
syndromes[198] = strtoul("1000111001", NULL, 2);
syndromes[199] = strtoul("0111000110", NULL, 2);
syndromes[200] = strtoul("0100111001", NULL, 2);
syndromes[201] = strtoul("1011000110", NULL, 2);
syndromes[202] = strtoul("0010111001", NULL, 2);
syndromes[203] = strtoul("1101000110", NULL, 2);
syndromes[204] = strtoul("1010111000", NULL, 2);
syndromes[205] = strtoul("0101000111", NULL, 2);
syndromes[206] = strtoul("0001111001", NULL, 2);
syndromes[207] = strtoul("1110000110", NULL, 2);
syndromes[208] = strtoul("1110000101", NULL, 2);
syndromes[209] = strtoul("0001111010", NULL, 2);
syndromes[210] = strtoul("1101000101", NULL, 2);
syndromes[211] = strtoul("0010111010", NULL, 2);
syndromes[212] = strtoul("1011000101", NULL, 2);
syndromes[213] = strtoul("0100111010", NULL, 2);
syndromes[214] = strtoul("0111000101", NULL, 2);
syndromes[215] = strtoul("1000111010", NULL, 2);
syndromes[216] = strtoul("1100100101", NULL, 2);
syndromes[217] = strtoul("0011011010", NULL, 2);
syndromes[218] = strtoul("1010100101", NULL, 2);
syndromes[219] = strtoul("0101011010", NULL, 2);
syndromes[220] = strtoul("0110100101", NULL, 2);
syndromes[221] = strtoul("1001011010", NULL, 2);
syndromes[222] = strtoul("1001100101", NULL, 2);
syndromes[223] = strtoul("0110011010", NULL, 2);
syndromes[224] = strtoul("0101100101", NULL, 2);
syndromes[225] = strtoul("1010011010", NULL, 2);
syndromes[226] = strtoul("0110111000", NULL, 2);
syndromes[227] = strtoul("1001000111", NULL, 2);
syndromes[228] = strtoul("0011100101", NULL, 2);
syndromes[229] = strtoul("1100011010", NULL, 2);
syndromes[230] = strtoul("1100010101", NULL, 2);
syndromes[231] = strtoul("0011101010", NULL, 2);
syndromes[232] = strtoul("1010010101", NULL, 2);
syndromes[233] = strtoul("0101101010", NULL, 2);
syndromes[234] = strtoul("0110010101", NULL, 2);
syndromes[235] = strtoul("1001101010", NULL, 2);
syndromes[236] = strtoul("1001010101", NULL, 2);
syndromes[237] = strtoul("0110101010", NULL, 2);
syndromes[238] = strtoul("0101010101", NULL, 2);
syndromes[239] = strtoul("1010101010", NULL, 2);
syndromes[240] = strtoul("0011010101", NULL, 2);
syndromes[241] = strtoul("1100101010", NULL, 2);
syndromes[242] = strtoul("1000110101", NULL, 2);
syndromes[243] = strtoul("0111001010", NULL, 2);
syndromes[244] = strtoul("0100110101", NULL, 2);
syndromes[245] = strtoul("1011001010", NULL, 2);
syndromes[246] = strtoul("0010110101", NULL, 2);
syndromes[247] = strtoul("1101001010", NULL, 2);
syndromes[248] = strtoul("1001111000", NULL, 2);
syndromes[249] = strtoul("0110000111", NULL, 2);
syndromes[250] = strtoul("0001110101", NULL, 2);
syndromes[251] = strtoul("1110001010", NULL, 2);
syndromes[252] = strtoul("1100001101", NULL, 2);
syndromes[253] = strtoul("0011110010", NULL, 2);
syndromes[254] = strtoul("1010001101", NULL, 2);
syndromes[255] = strtoul("0101110010", NULL, 2);
// Convert the syndromes for each single bit error into the H matrix.
// Each pattern (there are 10) is multiplied by the data (a
// BL_Uint256) to generate one bit of ECC.
for (uint_t pattern_ndx = 0; pattern_ndx < 10; ++pattern_ndx)
{
for (uint_t syndrome_ndx = 0; syndrome_ndx < 256; syndrome_ndx += 64)
{
patterns[9 - pattern_ndx].set(syndrome_ndx/64,
calc_pattern(syndrome_ndx, pattern_ndx));
}
}
// self check
// For Hsiao ECC, the check bits and the syndrome are calculated
// using the same algorithm.
// Check that inverting one data bit and calculating the resulting
// ECC matching the bit's syndrome.
for (uint_t syndrome_ndx = 0; syndrome_ndx < 256; ++syndrome_ndx)
{
BL_Uint256 data;
data.invert(syndrome_ndx);
if (calc_checks(10, patterns, data).get() != syndromes[syndrome_ndx].get())
{
fprintf(stderr,
"syndrome mismatch: ndx %d calc_check 0x%x syndrome 0x%x\n",
syndrome_ndx,
calc_checks(10, patterns, data).get(),
syndromes[syndrome_ndx].get());
exit(-1);
}
}
}
uint64_t BL_Hsiao_256_10_Synd::Patterns::calc_pattern(uint_t syndrome_ndx,
uint_t pattern_ndx)
{
uint64_t pattern = 0;
for (uint_t ndx = 0; ndx < 64; ++ndx)
{
if (syndromes[syndrome_ndx + ndx].get() == 0)
{
fprintf(stderr, "bad zero syndrome: %d\n", syndrome_ndx + ndx);
exit(-1);
}
pattern |= ((syndromes[syndrome_ndx + ndx].get() >> pattern_ndx) & 0x1ULL)
<< ndx;
}
return pattern;
}