* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: BL_BitUtility.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_BitUtility_h__
#define __BL_BitUtility_h__
// This method calculates the parity value for up to 64 bits of
// data using 4 XORs with a clever shift and returns a parity
// value of either 0 or 1.
// Data should be right justified and unused bits must be set to zero.
static uint32_t calc_parity(uint64_t data
)
return (0x6996 >> p
) & 1;
// This method calculates the parity value for a BL_Uint256 (or
static uint32_t calc_parity(BL_Uint256 data
)
return calc_parity(data
.get(0)) ^ calc_parity(data
.get(1)) ^
calc_parity(data
.get(2)) ^ calc_parity(data
.get(3));
// This method calculates the byte-by_byte parity values for a
// The parities are returned packed in 8 bits.
static uint8_t calc_byte_parities(uint64_t data
)
p
&= 0x0101010101010101ULL
;
// This routine can be used to set a certain number of bits within a 64 bit
// value. The routine takes the super set, subset, starting index and
// ending index as its four input parameters.
static uint64_t set_subfield(uint64_t data
, uint64_t subfield
, uint64_t start_offset
, uint64_t end_offset
)
uint64_t width
= (end_offset
- start_offset
) + 1;
uint64_t mask
= (((uint64_t(1) << width
) - 1) << start_offset
);
data
= (data
&~ mask
) | ((subfield
<< start_offset
) & mask
);