Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / ecc / src / BL_BaseEcc.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: BL_BaseEcc.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_BaseEcc_h__
#define __BL_BaseEcc_h__
#include <assert.h>
#include "BL_BitUtility.h"
class BL_EccBits
{
public:
BL_EccBits() : check_bits(0), is_valid(0) {}
BL_EccBits(unsigned short _check_bits) : check_bits(_check_bits), is_valid(true) {}
virtual ~BL_EccBits() {}
unsigned short get() const
{
assert(is_valid); return check_bits;
}
BL_EccBits& set(unsigned short _check_bits)
{
is_valid = true; check_bits = _check_bits;
return *this;
}
bool valid() const { return is_valid; }
BL_EccBits& valid(bool v) { is_valid = v; return *this; }
private:
unsigned short is_valid:1;
unsigned short check_bits:15;
};
// This method calculates the ecc check bits for a given data item and
// requires three parameters
// The first parameter specifies the number of ECC check bits
// The second parameter provide the masks that are required to identify
// which data bits are associated with a given check bit
// Masks are provided with the "most significant check bits first"
// The third parameter is the data
template <typename DataType>
BL_EccBits calc_checks(unsigned n_patterns,
DataType *patterns, DataType data)
{
unsigned i;
unsigned parity;
unsigned checks = 0;
// for each check bit
for (i = 0; i < n_patterns; i++)
{
// Calculate check bit value
parity = BL_BitUtility::calc_parity( data & *patterns++ );
// Accumulate check bits
checks <<= 1;
checks |= parity;
}
//return checks;
return BL_EccBits(checks);
}
#endif