Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / utl / src / BL_Types.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: BL_Types.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 ============================================
*/
#ifndef __BL_Types_h__
#define __BL_Types_h__
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <assert.h>
typedef signed int int_t;
typedef unsigned int uint_t;
// Unsigned 256_bit type
class BL_Uint256 {
public:
BL_Uint256()
{
array[0] = 0;
array[1] = 0;
array[2] = 0;
array[3] = 0;
}
// Create a BL_Uint256 from 4 uint64_t. The first argument is the
// least significant uint64_t, the last argument the most
// significant, etc.
BL_Uint256(uint64_t _ls_val, uint64_t _lms_val,
uint64_t _mms_val, uint64_t _ms_val)
{
array[0] = _ls_val;
array[1] = _lms_val;
array[2] = _mms_val;
array[3] = _ms_val;
}
uint64_t get(uint_t ndx) const { return array[ndx]; }
BL_Uint256& set(uint_t ndx, uint64_t val)
{
array[ndx] = val;
return *this;
}
BL_Uint256& invert(uint_t bit)
{
const uint_t nr_bits_in_ull = sizeof(uint64_t) * 8;
uint_t array_ndx = bit/nr_bits_in_ull;
if (array_ndx >= 4)
{
fprintf(stderr, "BL_Uint256::invert(): bad bit number: %d\n", bit);
exit(-1);
}
array[array_ndx] ^= (1ULL << (bit%nr_bits_in_ull));
return *this;
}
BL_Uint256 operator&(const BL_Uint256& op2) const
{
BL_Uint256 result;
for (uint_t ndx = 0; ndx < 4; ++ndx)
result.array[ndx] = array[ndx] & op2.array[ndx];
return result;
}
~BL_Uint256() {}
private:
uint64_t array[4];
};
#endif /* __BL_Types_h__ */