1
1
// regbits: C++ templates for type-safe bit manipulation
2
- // Copyright (C) 2019 Mark R. Rubin
2
+ // Copyright (C) 2019,2020 Mark R. Rubin
3
3
//
4
4
// This file is part of regbits.
5
5
//
6
- // The regbits program is free software: you can redistribute it and/or
7
- // modify it under the terms of the GNU General Public License as
8
- // published by the Free Software Foundation, either version 3 of the
9
- // License, or (at your option) any later version.
6
+ // The regbits program is free software: you can redistribute it
7
+ // and/or modify it under the terms of the GNU General Public License
8
+ // as published by the Free Software Foundation, either version 3 of
9
+ // the License, or (at your option) any later version.
10
10
//
11
11
// The regbits program is distributed in the hope that it will be
12
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13
- // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
14
// General Public License for more details.
15
15
//
16
- // You should have received a copy of the GNU General Public
17
- // License (LICENSE.txt) along with the regbits program. If not, see
16
+ // You should have received a copy of the GNU General Public License
17
+ // (LICENSE.txt) along with the regbits program. If not, see
18
18
// <https://www.gnu.org/licenses/gpl.html>
19
19
20
20
21
21
#ifndef regbits_hxx
22
22
#define regbits_hxx
23
23
24
+ #define REGBITS_MAJOR_VERSION 1
25
+ #define REGBITS_MINOR_VERSION 0
26
+ #define REGBITS_MICRO_VERSION 1
27
+
28
+
24
29
namespace regbits {
25
30
26
31
// forward refs
@@ -42,6 +47,7 @@ template<typename WORD, typename CLSS> class Pos {
42
47
43
48
// constructors
44
49
//
50
+ explicit
45
51
constexpr
46
52
Pos ()
47
53
: _pos(static_cast <WORD>(0 ))
@@ -60,6 +66,8 @@ template<typename WORD, typename CLSS> class Pos {
60
66
const Pos<WORD, CLSS> &other)
61
67
: _pos(other._pos)
62
68
{}
69
+ #else
70
+ Pos (const Pos<WORD, CLSS> &other) = default;
63
71
#endif
64
72
65
73
@@ -142,6 +150,7 @@ template<typename WORD, typename CLSS> class Bits {
142
150
143
151
// constructors
144
152
//
153
+ explicit
145
154
constexpr
146
155
Bits ()
147
156
: _bits(static_cast <WORD>(0 ))
@@ -182,6 +191,8 @@ template<typename WORD, typename CLSS> class Bits {
182
191
const Bits<WORD, CLSS> &other)
183
192
: _bits(other._bits)
184
193
{}
194
+ #else
195
+ Bits (const Bits<WORD, CLSS> &other) = default;
185
196
#endif
186
197
187
198
// for passing constexpr instance by value without requiring storage
@@ -348,6 +359,7 @@ template<typename WORD, typename CLSS> class Mskd {
348
359
349
360
// constructors
350
361
//
362
+ explicit
351
363
constexpr
352
364
Mskd ()
353
365
: _mask(static_cast <WORD>(0 )),
@@ -385,6 +397,8 @@ template<typename WORD, typename CLSS> class Mskd {
385
397
: _mask(other._mask),
386
398
_bits(other._bits)
387
399
{}
400
+ #else
401
+ Mskd (const Mskd<WORD, CLSS> &other) = default;
388
402
#endif
389
403
390
404
// for passing constexpr instance by value without requiring storage
@@ -585,6 +599,7 @@ template<typename WORD, typename CLSS> class Shft {
585
599
586
600
// constructors
587
601
//
602
+ explicit
588
603
constexpr
589
604
Shft ()
590
605
: _mask(static_cast <WORD>(0 )),
@@ -606,6 +621,8 @@ template<typename WORD, typename CLSS> class Shft {
606
621
: _mask(other._mask),
607
622
_pos (other._pos )
608
623
{}
624
+ #else
625
+ Shft (const Shft<WORD, CLSS> &other) = default;
609
626
#endif
610
627
611
628
// for passing constexpr instance by value without requiring storage
@@ -690,6 +707,8 @@ template<typename WORD, typename CLSS> class Reg {
690
707
const Reg<WORD, CLSS> &other)
691
708
: _word(other._word)
692
709
{}
710
+ #else
711
+ Reg (const Reg<WORD, CLSS> &other) = default;
693
712
#endif
694
713
695
714
// for passing constexpr instance by value without requiring storage
@@ -704,6 +723,15 @@ template<typename WORD, typename CLSS> class Reg {
704
723
return Reg<WORD, CLSS>(_word);
705
724
}
706
725
726
+
727
+ // for passing all bits off
728
+ static
729
+ Bits<WORD, CLSS> zero ()
730
+ {
731
+ return Bits<WORD, CLSS>(0 );
732
+ }
733
+
734
+
707
735
// assignments
708
736
//
709
737
void operator =(const WORD word) volatile { _word = word; }
@@ -794,15 +822,17 @@ template<typename WORD, typename CLSS> class Reg {
794
822
795
823
// extractors
796
824
//
797
- Reg<WORD, CLSS> operator &(Bits<WORD, CLSS> bits) volatile const
798
- { return Reg<WORD, CLSS>(_word & bits._bits ); }
799
- Reg<WORD, CLSS> operator &(Bits<WORD, CLSS> bits) const
800
- { return Reg<WORD, CLSS>(_word & bits._bits ); }
801
-
802
- Reg<WORD, CLSS> operator &(Mskd<WORD, CLSS> mskd) volatile const
803
- { return Reg<WORD, CLSS>(_word & mskd._mask ); }
804
- Reg<WORD, CLSS> operator &(Mskd<WORD, CLSS> mskd) const
805
- { return Reg<WORD, CLSS>(_word & mskd._mask ); }
825
+ Bits<WORD, CLSS> operator &(Bits<WORD, CLSS> bits) volatile const
826
+ { return Bits<WORD, CLSS>(_word & bits._bits ); }
827
+ Bits<WORD, CLSS> operator &(Bits<WORD, CLSS> bits) const
828
+ { return Bits<WORD, CLSS>(_word & bits._bits ); }
829
+
830
+ Mskd<WORD, CLSS> operator &(Mskd<WORD, CLSS> mskd) volatile const
831
+ { return Mskd<WORD, CLSS>(_word & mskd._mask ,
832
+ mskd._mask ); }
833
+ Mskd<WORD, CLSS> operator &(Mskd<WORD, CLSS> mskd) const
834
+ { return Mskd<WORD, CLSS>(_word & mskd._mask ,
835
+ mskd._mask ); }
806
836
807
837
WORD operator >>(const Shft<WORD, CLSS> shft) volatile const
808
838
{ return (_word & shft._mask ) >> shft._pos ._pos ; }
@@ -841,6 +871,21 @@ template<typename WORD, typename CLSS> class Reg {
841
871
bool all (const Bits<WORD, CLSS> bits) const
842
872
{ return (_word & bits._bits ) == bits._bits ; }
843
873
874
+ bool all (
875
+ const Bits<WORD, CLSS> mask,
876
+ const Bits<WORD, CLSS> bits)
877
+ volatile const
878
+ {
879
+ return (_word & mask._bits ) == bits._bits ;
880
+ }
881
+ bool all (
882
+ const Bits<WORD, CLSS> mask,
883
+ const Bits<WORD, CLSS> bits)
884
+ const
885
+ {
886
+ return (_word & mask._bits ) == bits._bits ;
887
+ }
888
+
844
889
bool all (const Mskd<WORD, CLSS> mskd) volatile const
845
890
{ return (_word & mskd._mask ) == mskd._bits ; }
846
891
bool all (const Mskd<WORD, CLSS> mskd) const
0 commit comments