Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / ecc / src / BL_Hsiao_30_7_Synd.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: BL_Hsiao_30_7_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_Hsiao_30_7_Synd_h__
#define __BL_Hsiao_30_7_Synd_h__
#include "BL_Utils.h"
#include "BL_BaseSynd.h"
#include "BL_HsiaoEcc.h"
class BL_Hsiao_30_7_Synd : public BL_BaseSynd
{
public:
BL_Hsiao_30_7_Synd(uint32_t syndrome) : BL_BaseSynd(syndrome)
{
if (syndrome > 0x7f)
{
fprintf(stderr,"ERROR: Bad Syndrome: 0x%x", syndrome);
exit(-1);
}
}
BL_Hsiao_30_7_Synd(uint32_t data, BL_EccBits ecc) :
BL_BaseSynd(BL_Hsiao_30_7_Synd::calc_check_bits(data).get() ^ ecc.get())
{}
~BL_Hsiao_30_7_Synd() {}
bool isDoubleBitError() const
{
return (syndrome_ != 0) && !isSingleBitError();
}
bool isSingleBitError() const
{
if (syndrome_ == 0)
return false;
switch (nr_bits_set())
{
case 1:
case 3:
return true;
default:
return false;
}
}
bool isDataBitError() const
{
return (isSingleBitError() && !(is_power_of_two(syndrome_)));
}
// 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);
}
return find_syndrome_ndx();
}
bool isCheckBitError() const
{
return (isSingleBitError() && is_power_of_two(syndrome_));
}
uint32_t getCheckBit() const
{
if (!isCheckBitError())
{
fprintf(stderr,"ERROR: Not check bit error!");
exit(-1);
}
return bit2idx(syndrome_);
}
bool isMultipleBitError() const { return false; }
static BL_EccBits calc_check_bits(uint32_t data)
{
uint32_t* patterns = BL_Hsiao_30_7_Synd::hsiao_30_7_patterns.patterns;
return calc_checks(7, patterns, data);
}
#define BL_HSIAO_30_7_DIE(S) { \
fprintf(stderr, S " line: %d\n", __LINE__); \
exit(-1); \
}
static void validate()
{
uint32_t data = 0x12345678;
uint32_t ecc = BL_Hsiao_30_7_Synd::calc_check_bits(data).get();
BL_Hsiao_30_7_Synd syndrome = BL_Hsiao_30_7_Synd(data, ecc);
if (!syndrome.noError())
BL_HSIAO_30_7_DIE("NoError fails");
int i;
for (i = 0; i < 30; ++i) {
syndrome = BL_Hsiao_30_7_Synd((1<<i)^data, ecc);
if (syndrome.noError())
BL_HSIAO_30_7_DIE("NoError succeeds");
if (!syndrome.isSingleBitError())
BL_HSIAO_30_7_DIE("isSingleBit fails");
if (syndrome.isDoubleBitError())
BL_HSIAO_30_7_DIE("isDoubleBit succeeds");
if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError())
BL_HSIAO_30_7_DIE("isMultipleBit/isUncorrectable succeeds");
if (syndrome.getDataBit() != i)
BL_HSIAO_30_7_DIE("getDataBit mismatch");
}
for (i = 0; i < 7; ++i) {
syndrome = BL_Hsiao_30_7_Synd(data, (1<<i)^ecc);
if (syndrome.noError())
BL_HSIAO_30_7_DIE("NoError succeeds");
if (!syndrome.isSingleBitError())
BL_HSIAO_30_7_DIE("isSingleBit fails");
if (syndrome.isDoubleBitError())
BL_HSIAO_30_7_DIE("isDoubleBit succeeds");
if (syndrome.isMultipleBitError() || syndrome.isUncorrectableError())
BL_HSIAO_30_7_DIE("isMultipleBit/isUncorrectable succeeds");
if (syndrome.getCheckBit() != i)
BL_HSIAO_30_7_DIE("getCheckBit mismatch");
}
for (i = 1; i < 30; ++i) {
int j;
for (j = 0; j < i; ++j) {
syndrome = BL_Hsiao_30_7_Synd((1<<i)^(1<<j)^data, ecc);
if (syndrome.noError())
BL_HSIAO_30_7_DIE("NoError succeeds");
if (syndrome.isSingleBitError())
BL_HSIAO_30_7_DIE("isSingleBit succeeds");
if (!syndrome.isDoubleBitError())
BL_HSIAO_30_7_DIE("isDoubleBit fails");
if (syndrome.isMultipleBitError())
BL_HSIAO_30_7_DIE("isMultipleBit succeeds");
if (!syndrome.isUncorrectableError())
BL_HSIAO_30_7_DIE("isUncorrectable fails");
}
}
for (i = 1; i < 7; ++i) {
int j;
for (j = 0; j < i; ++j) {
syndrome = BL_Hsiao_30_7_Synd(data, (1<<i)^(1<<j)^ecc);
if (syndrome.noError())
BL_HSIAO_30_7_DIE("NoError succeeds");
if (syndrome.isSingleBitError())
BL_HSIAO_30_7_DIE("isSingleBit succeeds");
if (!syndrome.isDoubleBitError())
BL_HSIAO_30_7_DIE("isDoubleBit fails");
if (syndrome.isMultipleBitError())
BL_HSIAO_30_7_DIE("isMultipleBit succeeds");
if (!syndrome.isUncorrectableError())
BL_HSIAO_30_7_DIE("isUncorrectable fails");
}
}
}
#undef BL_HSIAO_30_7_DIE
private:
BL_Hsiao_30_7_Synd();
// Number of bits set in syndrome
// This trick works up to 12 bits
uint_t nr_bits_set() const
{
return (syndrome_ * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f;
}
int find_syndrome_ndx() const
{
switch (nr_bits_set())
{
case 3:
for (uint_t ndx = 0; ndx < 30; ++ndx)
if (syndrome_ == hsiao_30_7_patterns.get(ndx).get())
return ndx;
assert(0);
break;
default:
break;
}
return -1; // -1 is didn't find it
}
class Patterns
{
public:
uint_t patterns[7];
Patterns();
~Patterns() {}
BL_EccBits get(uint_t ndx) const { return syndromes[ndx]; }
private:
static uint64_t calc_pattern(uint_t pattern_ndx);
static BL_EccBits syndromes[30];
};
static Patterns hsiao_30_7_patterns;
};
#endif