Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / ecc / src / BL_Hamming_64_8_Synd.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: BL_Hamming_64_8_Synd.h
* 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.
**
*************************************************************************/
#ifndef __BL_Hamming_64_8_Synd_h__
#define __BL_Hamming_64_8_Synd_h__
#include "BL_BaseSynd.h"
#include "BL_HammingEcc.h"
class BL_Hamming_64_8_Synd : public BL_BaseSynd
{
public:
BL_Hamming_64_8_Synd(uint32_t syndrome) : BL_BaseSynd(syndrome)
{
if (syndrome > 0xff)
{
fprintf(stderr,"ERROR: Bad Syndrome!");
exit(-1);
}
}
BL_Hamming_64_8_Synd(uint64_t data, BL_EccBits ecc) :
BL_BaseSynd(BL_HammingEcc::
get_hamming_64_8_synd(data,ecc.get()).getSyndrome())
{ }
~BL_Hamming_64_8_Synd() {}
bool isDoubleBitError() const { return (syndrome_ - 1) < 0x7F; }
bool isSingleBitError() const { return (syndrome_ - 0x80) < 0x48; }
// ((syndrome_ - 0x80) & syndrome_ - 0x81)) returns true if
// "syndrome_ - 0x80"is *NOT* a power of 2. See Table A-3 to see
// that this is true for all data bits.
bool isDataBitError() const
{
return (isSingleBitError() && ((syndrome_ - 0x80) & syndrome_ - 0x81));
}
// This method works because the check bits are at powers of 2
// (after substracting 0x80) so the data bits break up into
// large ranges.
uint32_t getDataBit() const
{
if (!isDataBitError())
{
fprintf(stderr,"ERROR: Not data bit error!");
exit(-1);
}
uint32_t bit = syndrome_ - 0x80;
if (bit >= 0x20)
return (bit >= 0x40) ? bit - 8 : bit - 7;
else if (bit >= 0x10)
return bit - 6;
else if (bit > 8)
return bit - 5;
else if (bit > 4)
return bit - 4;
else
return bit - 3;
}
// ((syndrome_ - 0x80) & (syndrome_ - 0x81)) returns true if
// "syndrome_ - 0x80" is a power of 2. See Table A-3 to see
// that this is true for all check bits.
bool isCheckBitError() const
{
return (isSingleBitError() && !((syndrome_ - 0x80) & syndrome_ - 0x81));
}
// This method works because the check bits are at powers of 2
// (after substracting 0x80) so this divide and conquer search
// is quite fast.
uint32_t getCheckBit() const
{
if (!isCheckBitError())
{
fprintf(stderr,"ERROR: Not check bit error!");
exit(-1);
}
uint32_t bit = syndrome_ - 0x80;
if (bit >= 0x20)
return (bit >= 0x40) ? 6 : 5;
else if (bit >= 0x10)
return 4;
else if (bit == 8)
return 3;
else if (bit == 4)
return 2;
else
return (bit == 0) ? 7 : bit - 1;
}
bool isMultipleBitError() const { return (syndrome_ - 0xc8) < (0x38); }
static BL_EccBits calc_check_bits(unsigned long long data)
{
return BL_HammingEcc::calc_check_bits(BL_HammingEcc::BL_Hamming_64_8, data);
}
#define BL_HAMMING_64_8_DIE(S) { \
fprintf(stderr, S " line: %d\n", __LINE__); \
exit(-1); \
}
static void validate()
{
uint64_t data = 0x123456789ABCDEF;
uint32_t ecc = BL_Hamming_64_8_Synd::calc_check_bits(data).get();
BL_Hamming_64_8_Synd syndrome =
BL_HammingEcc::get_hamming_64_8_synd(data, ecc);
if (!syndrome.noError())
BL_HAMMING_64_8_DIE("NoError fails");
int i;
for (i = 0; i < 64; ++i) {
syndrome =
BL_HammingEcc::get_hamming_64_8_synd((1ULL<<i)^data, ecc);
if (syndrome.noError())
BL_HAMMING_64_8_DIE("NoError succeeds");
if (!syndrome.isSingleBitError())
BL_HAMMING_64_8_DIE("isSingleBit fails");
if (syndrome.isDoubleBitError())
BL_HAMMING_64_8_DIE("isDoubleBit succeeds");
if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError())
BL_HAMMING_64_8_DIE("isMultipleBit/isUncorrectable succeeds");
if (syndrome.getDataBit() != i)
BL_HAMMING_64_8_DIE("getDataBit mismatch");
}
for (i = 0; i < 8; ++i) {
syndrome =
BL_HammingEcc::get_hamming_64_8_synd(data, (1ULL<<i)^ecc);
if (syndrome.noError())
BL_HAMMING_64_8_DIE("NoError succeeds");
if (!syndrome.isSingleBitError())
BL_HAMMING_64_8_DIE("isSingleBit fails");
if (syndrome.isDoubleBitError())
BL_HAMMING_64_8_DIE("isDoubleBit succeeds");
if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError())
BL_HAMMING_64_8_DIE("isMultipleBit/isUncorrectable succeeds");
if (syndrome.getCheckBit() != i)
BL_HAMMING_64_8_DIE("getCheckBit mismatch");
}
for (i = 1; i < 64; ++i) {
int j;
for (j = 0; j < i; ++j) {
syndrome =
BL_HammingEcc::get_hamming_64_8_synd((1ULL<<i)^(1ULL<<j)^data,
ecc);
if (syndrome.noError())
BL_HAMMING_64_8_DIE("NoError succeeds");
if (syndrome.isSingleBitError())
BL_HAMMING_64_8_DIE("isSingleBit succeeds");
if (!syndrome.isDoubleBitError())
BL_HAMMING_64_8_DIE("isDoubleBit fails");
if (syndrome.isMultipleBitError())
BL_HAMMING_64_8_DIE("isMultipleBit succeeds");
if (!syndrome.isUncorrectableError())
BL_HAMMING_64_8_DIE("isUncorrectable fails");
}
}
for (i = 1; i < 8; ++i) {
int j;
for (j = 0; j < i; ++j) {
syndrome =
BL_HammingEcc::get_hamming_64_8_synd(data,
(1ULL<<i)^(1ULL<<j)^ecc);
if (syndrome.noError())
BL_HAMMING_64_8_DIE("NoError succeeds");
if (syndrome.isSingleBitError())
BL_HAMMING_64_8_DIE("isSingleBit succeeds");
if (!syndrome.isDoubleBitError())
BL_HAMMING_64_8_DIE("isDoubleBit fails");
if (syndrome.isMultipleBitError())
BL_HAMMING_64_8_DIE("isMultipleBit succeeds");
if (!syndrome.isUncorrectableError())
BL_HAMMING_64_8_DIE("isUncorrectable fails");
}
}
}
#undef BL_HAMMING_64_8_DIE
private:
BL_Hamming_64_8_Synd();
};
#endif