Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: BL_Types.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef __BL_Types_h__ | |
24 | #define __BL_Types_h__ | |
25 | ||
26 | #include <stdio.h> | |
27 | #include <stdlib.h> | |
28 | ||
29 | #include <sys/types.h> | |
30 | #include <assert.h> | |
31 | ||
32 | ||
33 | typedef signed int int_t; | |
34 | typedef unsigned int uint_t; | |
35 | ||
36 | // Unsigned 256_bit type | |
37 | class BL_Uint256 { | |
38 | public: | |
39 | BL_Uint256() | |
40 | { | |
41 | array[0] = 0; | |
42 | array[1] = 0; | |
43 | array[2] = 0; | |
44 | array[3] = 0; | |
45 | } | |
46 | ||
47 | // Create a BL_Uint256 from 4 uint64_t. The first argument is the | |
48 | // least significant uint64_t, the last argument the most | |
49 | // significant, etc. | |
50 | BL_Uint256(uint64_t _ls_val, uint64_t _lms_val, | |
51 | uint64_t _mms_val, uint64_t _ms_val) | |
52 | { | |
53 | array[0] = _ls_val; | |
54 | array[1] = _lms_val; | |
55 | array[2] = _mms_val; | |
56 | array[3] = _ms_val; | |
57 | } | |
58 | ||
59 | uint64_t get(uint_t ndx) const { return array[ndx]; } | |
60 | BL_Uint256& set(uint_t ndx, uint64_t val) | |
61 | { | |
62 | array[ndx] = val; | |
63 | return *this; | |
64 | } | |
65 | ||
66 | BL_Uint256& invert(uint_t bit) | |
67 | { | |
68 | const uint_t nr_bits_in_ull = sizeof(uint64_t) * 8; | |
69 | uint_t array_ndx = bit/nr_bits_in_ull; | |
70 | if (array_ndx >= 4) | |
71 | { | |
72 | fprintf(stderr, "BL_Uint256::invert(): bad bit number: %d\n", bit); | |
73 | exit(-1); | |
74 | } | |
75 | array[array_ndx] ^= (1ULL << (bit%nr_bits_in_ull)); | |
76 | return *this; | |
77 | } | |
78 | ||
79 | BL_Uint256 operator&(const BL_Uint256& op2) const | |
80 | { | |
81 | BL_Uint256 result; | |
82 | for (uint_t ndx = 0; ndx < 4; ++ndx) | |
83 | result.array[ndx] = array[ndx] & op2.array[ndx]; | |
84 | return result; | |
85 | } | |
86 | ||
87 | ~BL_Uint256() {} | |
88 | ||
89 | private: | |
90 | uint64_t array[4]; | |
91 | }; | |
92 | ||
93 | #endif /* __BL_Types_h__ */ |