@@ -58,207 +58,29 @@ class sieve
5858 static constexpr auto screen_bits = sieve_bits - selector_bits;
5959
6060 static constexpr auto empty = system::unmask_right<sieve_t >(sieve_bits);
61- static constexpr auto selector_mask = system::unmask_right<sieve_t >(screen_bits);
6261 static constexpr auto saturated = system::mask_right(empty, sub1(screen_bits));
62+ static constexpr auto first_mask = system::unmask_right<sieve_t >(screen_bits);
63+ static constexpr auto selector_mask = first_mask;
6364
6465 static constexpr auto screens = system::power2(selector_bits);
65- static constexpr auto matrix = to_half(screens * add1 (screens));
66+ static constexpr auto mask_count = to_half(screens * add1 (screens));
6667 static constexpr auto limit = sub1(screens);
67- using masks_t = std_array<sieve_t , matrix>;
68+ using masks_t = std_array<sieve_t , mask_count>;
69+ using offsets_t = std_array<size_t , screens>;
6870
69- // Generate compression offsets at compile, generally 16 or 32 elements.
70- template <size_t Size>
71- static CONSTEVAL auto offsets () NOEXCEPT
72- {
73- using namespace system ;
74- std_array<uint16_t , Size> offset{};
75- for (uint16_t index{}; index < Size; ++index)
76- offset[index] = to_half (ceilinged_multiply (index, add1 (index)));
77- return offset;
78- }
71+ // / Generate compression offsets at compile.
72+ static CONSTEVAL offsets_t generate_offsets () NOEXCEPT;
7973
80- // Access compressed array as if it was a two-dimesional array.
81- static constexpr auto masks (auto screen, auto segment) NOEXCEPT
82- {
83- constexpr auto offset = offsets<screens>();
84- return masks_[offset[screen] + segment];
85- }
74+ // / Compile-time mask table generator.
75+ static CONSTEVAL masks_t generate_masks () NOEXCEPT;
76+
77+ // / Read member compressed mask array as if it was a two-dimesional array.
78+ constexpr sieve_t masks (size_t row, size_t column) const NOEXCEPT;
8679
8780private:
88- // Logically this is sparse 16 x 16 = 256 matrix of uint32_t (1024 bytes).
81+ // Logically sparse, e.g. 16 x 16 = 256 table of uint32_t (1024 bytes).
8982 // Compressed to one-dimensional 136 element array of uint32_t (544 bytes).
90- static constexpr std_array<sieve_t , matrix> masks_
91- {
92- // 1
93- 0b0000'1111111111111111111111111111 ,
94-
95- // 2
96- 0b0000'1111111111111100000000000000 ,
97- 0b0000'0000000000000011111111111111 ,
98-
99- // 3
100- 0b0000'1111111111000000000000000000 ,
101- 0b0000'0000000000000011111111100000 ,
102- 0b0000'0000000000111100000000011111 ,
103-
104- // 4
105- 0b0000'1111111000000000000000000000 ,
106- 0b0000'0000000000000011111110000000 ,
107- 0b0000'0000000000111100000000011100 ,
108- 0b0000'0000000111000000000001100011 ,
109-
110- // 5
111- 0b0000'1111110000000000000000000000 ,
112- 0b0000'0000000000000011111100000000 ,
113- 0b0000'0000000000111100000000011000 ,
114- 0b0000'0000000111000000000001100000 ,
115- 0b0000'0000001000000000000010000111 ,
116-
117- // 6
118- 0b0000'1111100000000000000000000000 ,
119- 0b0000'0000000000000011111000000000 ,
120- 0b0000'0000000000111100000000010000 ,
121- 0b0000'0000000111000000000001100000 ,
122- 0b0000'0000001000000000000010000110 ,
123- 0b0000'0000010000000000000100001001 ,
124-
125- // 7
126- 0b0000'1111000000000000000000000000 ,
127- 0b0000'0000000000000011110000000000 ,
128- 0b0000'0000000000111100000000000000 ,
129- 0b0000'0000000111000000000001000000 ,
130- 0b0000'0000001000000000000010000110 ,
131- 0b0000'0000010000000000000100001001 ,
132- 0b0000'0000100000000000001000110000 ,
133-
134- // 8
135- 0b0000'1111000000000000000000000000 ,
136- 0b0000'0000000000000011110000000000 ,
137- 0b0000'0000000000111100000000000000 ,
138- 0b0000'0000000111000000000001000000 ,
139- 0b0000'0000001000000000000010000100 ,
140- 0b0000'0000010000000000000100001000 ,
141- 0b0000'0000100000000000001000100000 ,
142- 0b0000'0000000000000000000000010011 ,
143-
144- // 9
145- 0b0000'1111000000000000000000000000 ,
146- 0b0000'0000000000000011100000000000 ,
147- 0b0000'0000000000111000000000000000 ,
148- 0b0000'0000000111000000000000000000 ,
149- 0b0000'0000001000000000000010000100 ,
150- 0b0000'0000010000000000000100001000 ,
151- 0b0000'0000100000000000001000100000 ,
152- 0b0000'0000000000000000000000010011 ,
153- 0b0000'0000000000000100010001000000 ,
154-
155- // 10
156- 0b0000'1110000000000000000000000000 ,
157- 0b0000'0000000000000011100000000000 ,
158- 0b0000'0000000000111000000000000000 ,
159- 0b0000'0000000111000000000000000000 ,
160- 0b0000'0000001000000000000010000100 ,
161- 0b0000'0000010000000000000100001000 ,
162- 0b0000'0000100000000000001000100000 ,
163- 0b0000'0000000000000000000000010011 ,
164- 0b0000'0000000000000100010000000000 ,
165- 0b0000'0001000000000000000001000000 ,
166-
167- // 11
168- 0b0000'1110000000000000000000000000 ,
169- 0b0000'0000000000000011100000000000 ,
170- 0b0000'0000000000111000000000000000 ,
171- 0b0000'0000000111000000000000000000 ,
172- 0b0000'0000001000000000000010000100 ,
173- 0b0000'0000010000000000000100001000 ,
174- 0b0000'0000100000000000001000000000 ,
175- 0b0000'0000000000000000000000010010 ,
176- 0b0000'0000000000000100010000000000 ,
177- 0b0000'0001000000000000000001000000 ,
178- 0b0000'0000000000000000000000100001 ,
179-
180- // 12
181- 0b0000'1110000000000000000000000000 ,
182- 0b0000'0000000000000011100000000000 ,
183- 0b0000'0000000000111000000000000000 ,
184- 0b0000'0000000111000000000000000000 ,
185- 0b0000'0000001000000000000010000000 ,
186- 0b0000'0000010000000000000100000000 ,
187- 0b0000'0000100000000000001000000000 ,
188- 0b0000'0000000000000000000000010010 ,
189- 0b0000'0000000000000100010000000000 ,
190- 0b0000'0001000000000000000001000000 ,
191- 0b0000'0000000000000000000000100001 ,
192- 0b0000'0000000000000000000000001100 ,
193-
194- // 13
195- 0b0000'1110000000000000000000000000 ,
196- 0b0000'0000000000000011100000000000 ,
197- 0b0000'0000000000110000000000000000 ,
198- 0b0000'0000000110000000000000000000 ,
199- 0b0000'0000001000000000000010000000 ,
200- 0b0000'0000010000000000000100000000 ,
201- 0b0000'0000100000000000001000000000 ,
202- 0b0000'0000000000000000000000010010 ,
203- 0b0000'0000000000000100010000000000 ,
204- 0b0000'0001000000000000000001000000 ,
205- 0b0000'0000000000000000000000100001 ,
206- 0b0000'0000000000000000000000001100 ,
207- 0b0000'0000000001001000000000000000 ,
208-
209- // 14
210- 0b0000'1100000000000000000000000000 ,
211- 0b0000'0000000000000011000000000000 ,
212- 0b0000'0000000000110000000000000000 ,
213- 0b0000'0000000110000000000000000000 ,
214- 0b0000'0000001000000000000010000000 ,
215- 0b0000'0000010000000000000100000000 ,
216- 0b0000'0000100000000000001000000000 ,
217- 0b0000'0000000000000000000000010010 ,
218- 0b0000'0000000000000100010000000000 ,
219- 0b0000'0001000000000000000001000000 ,
220- 0b0000'0000000000000000000000100001 ,
221- 0b0000'0000000000000000000000001100 ,
222- 0b0000'0000000001001000000000000000 ,
223- 0b0000'0010000000000000100000000000 ,
224-
225- // 15
226- 0b0000'1100000000000000000000000000 ,
227- 0b0000'0000000000000011000000000000 ,
228- 0b0000'0000000000110000000000000000 ,
229- 0b0000'0000000110000000000000000000 ,
230- 0b0000'0000001000000000000010000000 ,
231- 0b0000'0000010000000000000100000000 ,
232- 0b0000'0000100000000000001000000000 ,
233- 0b0000'0000000000000000000000010010 ,
234- 0b0000'0000000000000100010000000000 ,
235- 0b0000'0001000000000000000001000000 ,
236- 0b0000'0000000000000000000000100001 ,
237- 0b0000'0000000000000000000000001100 ,
238- 0b0000'0000000001001000000000000000 ,
239- 0b0000'0010000000000000000000000000 ,
240- 0b0000'0000000000000000100000000000 ,
241-
242- // 16
243- // first row first bit sacrificed for sentinel.
244- 0b0000'0'100000000000000000000000000 ,
245- 0b0000'0000000000000011000000000000 ,
246- 0b0000'0000000000110000000000000000 ,
247- 0b0000'0000000110000000000000000000 ,
248- 0b0000'0000001000000000000010000000 ,
249- 0b0000'0000010000000000000100000000 ,
250- 0b0000'0000100000000000001000000000 ,
251- 0b0000'0000000000000000000000010010 ,
252- 0b0000'0000000000000100010000000000 ,
253- 0b0000'0001000000000000000001000000 ,
254- 0b0000'0000000000000000000000100001 ,
255- 0b0000'0000000000000000000000001100 ,
256- 0b0000'0000000001000000000000000000 ,
257- 0b0000'0010000000000000000000000000 ,
258- 0b0000'0000000000000000100000000000 ,
259- 0b0000'0000000000001000000000000000
260- };
261-
83+ static constexpr masks_t masks_ = generate_masks();
26284 sieve_t sieve_;
26385};
26486
0 commit comments