bitunion.hh (6215:9aed64c9f10f) bitunion.hh (6249:ba13184587a5)
1/*
2 * Copyright (c) 2007-2008 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 72 unchanged lines hidden (view full) ---

81 {
82 protected:
83 //This class implements ordinary bitfields, that is a span of bits
84 //who's msb is "first", and who's lsb is "last".
85 template<int first, int last=first>
86 class Bitfield : public BitfieldBase<Type>
87 {
88 public:
1/*
2 * Copyright (c) 2007-2008 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 72 unchanged lines hidden (view full) ---

81 {
82 protected:
83 //This class implements ordinary bitfields, that is a span of bits
84 //who's msb is "first", and who's lsb is "last".
85 template<int first, int last=first>
86 class Bitfield : public BitfieldBase<Type>
87 {
88 public:
89 operator uint64_t () const
89 operator const uint64_t () const
90 {
91 return this->getBits(first, last);
92 }
93
94 uint64_t
95 operator=(const uint64_t _data)
96 {
97 this->setBits(first, last, _data);

--- 14 unchanged lines hidden (view full) ---

112 operator=(const uint64_t _data);
113 };
114
115 //Similar to the above, but only allows writing.
116 template<int first, int last=first>
117 class BitfieldWO : public Bitfield<first, last>
118 {
119 private:
90 {
91 return this->getBits(first, last);
92 }
93
94 uint64_t
95 operator=(const uint64_t _data)
96 {
97 this->setBits(first, last, _data);

--- 14 unchanged lines hidden (view full) ---

112 operator=(const uint64_t _data);
113 };
114
115 //Similar to the above, but only allows writing.
116 template<int first, int last=first>
117 class BitfieldWO : public Bitfield<first, last>
118 {
119 private:
120 operator uint64_t () const;
120 operator const uint64_t () const;
121
122 public:
123 using Bitfield<first, last>::operator=;
124 };
125 };
126
127 //This class contains all the "regular" bitfield classes. It is inherited
128 //by all BitUnions which give them access to those types.
129 template<class Type>
130 class SignedBitfieldTypes
131 {
132 protected:
133 //This class implements ordinary bitfields, that is a span of bits
134 //who's msb is "first", and who's lsb is "last".
135 template<int first, int last=first>
136 class SignedBitfield : public BitfieldBase<Type>
137 {
138 public:
121
122 public:
123 using Bitfield<first, last>::operator=;
124 };
125 };
126
127 //This class contains all the "regular" bitfield classes. It is inherited
128 //by all BitUnions which give them access to those types.
129 template<class Type>
130 class SignedBitfieldTypes
131 {
132 protected:
133 //This class implements ordinary bitfields, that is a span of bits
134 //who's msb is "first", and who's lsb is "last".
135 template<int first, int last=first>
136 class SignedBitfield : public BitfieldBase<Type>
137 {
138 public:
139 operator int64_t () const
139 operator const int64_t () const
140 {
141 return sext<first - last + 1>(this->getBits(first, last));
142 }
143
144 int64_t
145 operator=(const int64_t _data)
146 {
147 this->setBits(first, last, _data);

--- 14 unchanged lines hidden (view full) ---

162 operator=(const int64_t _data);
163 };
164
165 //Similar to the above, but only allows writing.
166 template<int first, int last=first>
167 class SignedBitfieldWO : public SignedBitfield<first, last>
168 {
169 private:
140 {
141 return sext<first - last + 1>(this->getBits(first, last));
142 }
143
144 int64_t
145 operator=(const int64_t _data)
146 {
147 this->setBits(first, last, _data);

--- 14 unchanged lines hidden (view full) ---

162 operator=(const int64_t _data);
163 };
164
165 //Similar to the above, but only allows writing.
166 template<int first, int last=first>
167 class SignedBitfieldWO : public SignedBitfield<first, last>
168 {
169 private:
170 operator int64_t () const;
170 operator const int64_t () const;
171
172 public:
173 int64_t operator=(const int64_t _data)
174 {
175 *((SignedBitfield<first, last> *)this) = _data;
176 return _data;
177 }
178 };

--- 16 unchanged lines hidden (view full) ---

195 public:
196 BitUnionOperators(Type const & _data)
197 {
198 Base::__data = _data;
199 }
200
201 BitUnionOperators() {}
202
171
172 public:
173 int64_t operator=(const int64_t _data)
174 {
175 *((SignedBitfield<first, last> *)this) = _data;
176 return _data;
177 }
178 };

--- 16 unchanged lines hidden (view full) ---

195 public:
196 BitUnionOperators(Type const & _data)
197 {
198 Base::__data = _data;
199 }
200
201 BitUnionOperators() {}
202
203 operator Type () const
203 operator const Type () const
204 {
205 return Base::__data;
206 }
207
208 Type
209 operator=(Type const & _data)
210 {
211 Base::__data = _data;

--- 63 unchanged lines hidden (view full) ---

275
276//This closes off the union created above and gives it a name. Unlike the top
277//level BitUnion, we're interested in creating an object instead of a type.
278//The operators are defined in the macro itself instead of a class for
279//technical reasons. If someone determines a way to move them to one, please
280//do so.
281#define EndSubBitUnion(name) \
282 }; \
204 {
205 return Base::__data;
206 }
207
208 Type
209 operator=(Type const & _data)
210 {
211 Base::__data = _data;

--- 63 unchanged lines hidden (view full) ---

275
276//This closes off the union created above and gives it a name. Unlike the top
277//level BitUnion, we're interested in creating an object instead of a type.
278//The operators are defined in the macro itself instead of a class for
279//technical reasons. If someone determines a way to move them to one, please
280//do so.
281#define EndSubBitUnion(name) \
282 }; \
283 inline operator const __DataType () \
283 inline operator const __DataType () const \
284 { return __data; } \
285 \
286 inline const __DataType operator = (const __DataType & _data) \
287 { return __data = _data;} \
288 } name;
289
290//Regular bitfields
291//These define macros for read/write regular bitfield based subbitfields.

--- 18 unchanged lines hidden ---
284 { return __data; } \
285 \
286 inline const __DataType operator = (const __DataType & _data) \
287 { return __data = _data;} \
288 } name;
289
290//Regular bitfields
291//These define macros for read/write regular bitfield based subbitfields.

--- 18 unchanged lines hidden ---