libstdc++-v3 PATCH: _Count_ones<> should meet the zero-overhead rule
Gabriel Dos Reis
gdr@codesourcery.com
Fri Nov 10 09:42:00 GMT 2000
This patch turns the static integral data members of _Count_ones<>
into enumerators -- that makes it possible to avoid emission of
useless variables. _Count_ones<> should be costless.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com
http://www.codesourcery.com/gcc-compile.shtml
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/ChangeLog,v
retrieving revision 1.251
diff -p -r1.251 ChangeLog
*** ChangeLog 2000/11/09 02:57:23 1.251
--- ChangeLog 2000/11/10 17:33:37
***************
*** 1,3 ****
--- 1,8 ----
+ 2000-11-10 Gabriel Dos Reis <gdr@codesourcery.com>
+
+ * include/bits/localefwd.h (_Count_ones<>::_S_halfcount,
+ _Count_ones<>::_S_count): Turn into enumerators.
+
2000-11-08 Mark Mitchell <mark@codesourcery.com>
* include/bits/codecvt.h (codecvt::do_out): Make it const-correct.
Index: include/bits/localefwd.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/localefwd.h,v
retrieving revision 1.3
diff -p -r1.3 localefwd.h
*** localefwd.h 2000/10/20 06:51:59 1.3
--- localefwd.h 2000/11/10 17:33:38
*************** namespace std
*** 49,75 ****
unsigned int _Mask = (~0u >> _Shift) >
struct _Count_ones;
template<unsigned int _Num, unsigned int _Mask>
struct _Count_ones<_Num, 0, _Mask>
! { static const unsigned int _S_count = _Num; };
!
! template<unsigned int _Num, unsigned int _Mask>
! const unsigned int _Count_ones<_Num, 0, _Mask>::_S_count;
template<unsigned int _Num, int _Shift, unsigned int _Mask>
struct _Count_ones
{
! static const unsigned int _S_halfcount =
! _Count_ones<_Num, _Shift/2, (_Mask^((~_Mask)>>(_Shift/2))) >::_S_count;
! static const unsigned int _S_count
! = (_S_halfcount&_Mask) + ((_S_halfcount>>_Shift)&_Mask);
};
-
- template<unsigned int _Num, int _Shift, unsigned int _Mask>
- const unsigned int _Count_ones<_Num, _Shift, _Mask>::_S_count;
-
- template<unsigned int _Num, int _Shift, unsigned int _Mask>
- const unsigned int _Count_ones<_Num, _Shift, _Mask>::_S_halfcount;
// 22.1.1 Locale
template<typename _Tp> class allocator;
--- 49,75 ----
unsigned int _Mask = (~0u >> _Shift) >
struct _Count_ones;
+ // It is preferable to use enumerators instead of integral static data
+ // members to avoid emission of superflous variables -- gdr.
template<unsigned int _Num, unsigned int _Mask>
struct _Count_ones<_Num, 0, _Mask>
! {
! enum
! {
! _S_count = _Num
! };
! };
template<unsigned int _Num, int _Shift, unsigned int _Mask>
struct _Count_ones
{
! enum
! {
! _S_halfcount = _Count_ones<_Num, _Shift/2,
! (_Mask^((~_Mask)>>(_Shift/2))) >::_S_count,
! _S_count = (_S_halfcount&_Mask) + ((_S_halfcount>>_Shift)&_Mask)
! };
};
// 22.1.1 Locale
template<typename _Tp> class allocator;
More information about the Gcc-patches
mailing list