@@ -138,43 +138,52 @@ static int[] fillInts(int[] a, IntOp f) {
138138 flatMap (fa -> BOOLEAN_MASK_GENERATORS .stream ().skip (1 ).map (
139139 fb -> List .of (fa , fb ))).collect (Collectors .toList ());
140140
141- static long pack_booleans_to_long (boolean [] mask ) {
142- long bits = 0L ;
143- // pack up to 64 bits/lane indices, least significant bit is lane 0
144- int bound = Math .min (mask .length , 64 );
145- for (int i = 0 ; i < bound ; i ++) {
141+ static long [] pack_booleans_to_longs (boolean [] mask ) {
142+ int totalLongs = (mask .length + 63 ) / 64 ; // ceil division
143+ long [] packed = new long [totalLongs ];
144+ for (int i = 0 ; i < mask .length ; i ++) {
145+ int longIndex = i / 64 ;
146+ int bitIndex = i % 64 ;
146147 if (mask [i ]) {
147- bits |= 1L << i ;
148+ packed [ longIndex ] |= 1L << bitIndex ;
148149 }
149150 }
150- return bits ;
151+ return packed ;
151152 }
152153
153- static final List <IntFunction <Long >> LONG_MASK_GENERATORS = List .of (
154+ static final List <IntFunction <long [] >> LONG_MASK_GENERATORS = List .of (
154155 withToString ("mask[random]" , (int l ) -> {
155156 boolean [] a = new boolean [l ];
156157 for (int i = 0 ; i < l ; i ++) {
157158 a [i ] = RAND .nextBoolean ();
158159 }
159- return pack_booleans_to_long (a );
160+ return pack_booleans_to_longs (a );
160161 }),
161162 withToString ("mask[i % 2]" , (int l ) -> {
162163 boolean [] a = new boolean [l ];
163164 for (int i = 0 ; i < l ; i ++) {
164165 a [i ] = (i % 2 == 0 );
165166 }
166- return pack_booleans_to_long (a );
167+ return pack_booleans_to_longs (a );
168+ }),
169+ withToString ("mask[i % 5]" , (int l ) -> {
170+ boolean [] a = new boolean [l ];
171+ for (int i = 0 ; i < l ; i ++) {
172+ a [i ] = (i % 2 == 0 );
173+ }
174+ return pack_booleans_to_longs (a );
167175 }),
168176 withToString ("mask[true]" , (int l ) -> {
169177 boolean [] a = new boolean [l ];
170178 Arrays .fill (a , true );
171- return pack_booleans_to_long (a );
179+ return pack_booleans_to_longs (a );
172180 }),
173- withToString ("mask[false]" , Long ::new ),
174- withToString ("mask[0xFFFFFFFFFFFFFFFFL]" , (_l ) -> 0xFFFFFFFFFFFFFFFFL ), // true
175- withToString ("mask[0x0000000000000000L]" , (_l ) -> 0x0000000000000000L ), // false
176- withToString ("mask[0x5555555555555555L]" , (_l ) -> 0x5555555555555555L ),
177- withToString ("mask[0x0123456789abcdefL]" , (_l ) -> 0x0123456789abcdefL )
181+ withToString ("mask[false]" , (int l ) ->
182+ pack_booleans_to_longs (new boolean [l ])),
183+ withToString ("mask[0xFFFFFFFFFFFFFFFFL]" , (_l ) -> new long [] { 0xFFFFFFFFFFFFFFFFL }),
184+ withToString ("mask[0x0000000000000000L]" , (_l ) -> new long [] { 0x0000000000000000L }),
185+ withToString ("mask[0x5555555555555555L]" , (_l ) -> new long [] { 0x5555555555555555L }),
186+ withToString ("mask[0x0123456789abcdefL]" , (_l ) -> new long [] { 0x0123456789abcdefL })
178187 );
179188
180189 static final List <BiFunction <Integer ,Integer ,int []>> INT_SHUFFLE_GENERATORS = List .of (
0 commit comments