Skip to content

Commit

Permalink
Reverting PR 452
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lemire committed Sep 25, 2023
1 parent 3781b2d commit 15e4a17
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions src/containers/mixed_union.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,37 +206,11 @@ bool array_array_container_inplace_union(
return false; // not a bitset
} else {
memmove(src_1->array + src_2->cardinality, src_1->array, src_1->cardinality * sizeof(uint16_t));
/*
Next line is safe:
We just need to focus on the reading and writing performed on array1. In `union_vector16`, both vectorized and scalar code still obey the basic rule: read from two inputs, do the union, and then write the output.
Let's say the length(cardinality) of input2 is L2:
```
|<- L2 ->|
array1: [output--- |input 1---|---]
array2: [input 2---]
```
Let's define 3 __m128i pointers, `pos1` starts from `input1`, `pos2` starts from `input2`, these 2 point at the next byte to read, `out` starts from `output`, pointing at the next byte to overwrite.
```
array1: [output--- |input 1---|---]
^ ^
out pos1
array2: [input 2---]
^
pos2
```
The union output always contains less or equal number of elements than all inputs added, so we have:
```
out <= pos1 + pos2
```
therefore:
```
out <= pos1 + L2
```
which means you will not overwrite data beyond pos1, so the data haven't read is safe, and we don't care the data already read.
*/
src_1->cardinality = (int32_t)fast_union_uint16(src_1->array + src_2->cardinality, src_1->cardinality,
// In theory, we could use fast_union_uint16, but it is unsafe. It fails
// with Intel compilers in particular.
// https://github.com/RoaringBitmap/CRoaring/pull/452
// See report https://github.com/RoaringBitmap/CRoaring/issues/476
src_1->cardinality = (int32_t)union_uint16(src_1->array + src_2->cardinality, src_1->cardinality,
src_2->array, src_2->cardinality, src_1->array);
return false; // not a bitset
}
Expand Down

0 comments on commit 15e4a17

Please sign in to comment.