1 // { dg-do compile { target i?86-*-* x86_64-*-* } }
2 // { dg-options "-std=c++11 -O3 -msse2 -mno-avx -fno-exceptions -fno-rtti -fdump-rtl-final" }
3 
4 typedef unsigned int size_type;
5 
6 #define _GLIBCXX_BITSET_BITS_PER_WORD  (__CHAR_BIT__ * __SIZEOF_INT__)
7 #define _GLIBCXX_BITSET_WORDS(__n) \
8   ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
9    ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
10 
11 namespace std
12 {
13   template<size_type _Nw>
14     struct _Base_bitset
15     {
16       typedef unsigned int _WordT;
17       _WordT 		_M_w[_Nw];
18 
19       _WordT&
_M_hiword_Base_bitset20       _M_hiword()
21       { return _M_w[_Nw - 1]; }
22 
23       void
_M_do_and_Base_bitset24       _M_do_and(const _Base_bitset<_Nw>& __x)
25       {
26 	for (size_type __i = 0; __i < _Nw; __i++)
27 	  _M_w[__i] += __x._M_w[__i];
28       }
29 
30       void
_M_do_flip_Base_bitset31       _M_do_flip()
32       {
33 	for (size_type __i = 0; __i < _Nw; __i++)
34 	  _M_w[__i] = ~_M_w[__i];
35       }
36 
37       bool
_M_is_equal_Base_bitset38       _M_is_equal(const _Base_bitset<_Nw>& __x) const
39       {
40 	for (size_type __i = 0; __i < _Nw; ++__i)
41 	  if (_M_w[__i] != __x._M_w[__i])
42 	    return false;
43 	return true;
44       }
45 
46       bool
_M_is_any_Base_bitset47       _M_is_any() const
48       {
49 	for (size_type __i = 0; __i < _Nw; __i++)
50 	  if (_M_w[__i] != static_cast<_WordT>(0))
51 	    return true;
52 	return false;
53       }
54     };
55 
56   template<size_type _Extrabits>
57     struct _Sanitize
58     {
59       typedef unsigned int _WordT;
60 
61       static void
_S_do_sanitize_Sanitize62       _S_do_sanitize(_WordT& __val)
63       { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
64     };
65 
66   template<size_type _Nb>
67     class bitset
68     : private _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)>
69     {
70     private:
71       typedef _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)> _Base;
72       typedef unsigned int _WordT;
73 
74       void
_M_do_sanitize()75       _M_do_sanitize()
76       {
77 	typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
78 	__sanitize_type::_S_do_sanitize(this->_M_hiword());
79       }
80 
81     public:
82       class reference
83       {
84 	friend class bitset;
85 
86 	_WordT*	_M_wp;
87 	size_type 	_M_bpos;
88 
89       public:
90 	reference&
flip()91 	flip()
92 	{
93 	  *_M_wp ^= _Base::_S_maskbit(_M_bpos);
94 	  return *this;
95 	}
96       };
97 
98       bitset<_Nb>&
99       operator&=(const bitset<_Nb>& __rhs)
100       {
101 	this->_M_do_and(__rhs);
102 	return *this;
103       }
104 
105       bitset<_Nb>&
flip()106       flip()
107       {
108 	this->_M_do_flip();
109 	this->_M_do_sanitize();
110 	return *this;
111       }
112 
113       bitset<_Nb>
114       operator~() const
115       { return bitset<_Nb>(*this).flip(); }
116 
117       bool
118       operator==(const bitset<_Nb>& __rhs) const
119       { return this->_M_is_equal(__rhs); }
120 
121       bool
any()122       any() const
123       { return this->_M_is_any(); }
124     };
125 
126   template<size_type _Nb>
127     inline bitset<_Nb>
128     operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
129     {
130       bitset<_Nb> __result(__x);
131       __result &= __y;
132       return __result;
133     }
134 }
135 template<typename T>
136 class ArrayRef {
137 public:
138     typedef const T *iterator;
139 
140 private:
141     const T *Data;
142     size_type Length;
143 
144 public:
begin()145     iterator begin() const { return Data; }
end()146     iterator end() const { return Data + Length; }
147 };
148 
149 const unsigned MAX_SUBTARGET_FEATURES = 128;
150 class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
151 };
152 
153 struct SubtargetFeatureKV {
154   FeatureBitset Value;
155   FeatureBitset Implies;
156 };
157 
158 struct SubtargetInfoKV {
159   const void *Value;
160 };
161 class SubtargetFeatures {
162 public:
163     FeatureBitset ToggleFeature(FeatureBitset Bits,
164 				const SubtargetFeatureKV *,
165 				ArrayRef<SubtargetFeatureKV> FeatureTable);
166 };
167 
168 static
ClearImpliedBits(FeatureBitset & Bits,const SubtargetFeatureKV * FeatureEntry,ArrayRef<SubtargetFeatureKV> FeatureTable)169 void ClearImpliedBits(FeatureBitset &Bits,
170 		      const SubtargetFeatureKV *FeatureEntry,
171 		      ArrayRef<SubtargetFeatureKV> FeatureTable) {
172   for (auto &FE : FeatureTable) {
173     if ((FE.Implies & FeatureEntry->Value).any()) {
174       Bits &= ~FE.Value;
175       ClearImpliedBits(Bits, &FE, FeatureTable);
176     }
177   }
178 }
179 
180 FeatureBitset
ToggleFeature(FeatureBitset Bits,const SubtargetFeatureKV * FeatureEntry,ArrayRef<SubtargetFeatureKV> FeatureTable)181 SubtargetFeatures::ToggleFeature(FeatureBitset Bits,
182 				 const SubtargetFeatureKV *FeatureEntry,
183 				 ArrayRef<SubtargetFeatureKV> FeatureTable) {
184     if ((Bits & FeatureEntry->Value) == FeatureEntry->Value) {
185       Bits &= ~FeatureEntry->Value;
186       ClearImpliedBits(Bits, FeatureEntry, FeatureTable);
187     }
188   return Bits;
189 }
190 
191 // { dg-final { scan-rtl-dump-not "S16 A32\[^\n\]*\\\*addv4si3" "final" } }
192