Skip to content

Commit 2a1eb1c

Browse files
committed
Document the precomputation algorithm's purpose
1 parent 1ae1312 commit 2a1eb1c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/librustc_mir/interpret/memory.rs

+7
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
791791

792792
let undef_mask = &self.get(src.alloc_id)?.undef_mask;
793793

794+
// Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`),
795+
// a naive undef mask copying algorithm would repeatedly have to read the undef mask from
796+
// the source and write it to the destination. Even if we optimized the memory accesses,
797+
// we'd be doing all of this `repeat` times.
798+
// Therefor we precompute a compressed version of the undef mask of the source value and
799+
// then write it back `repeat` times without computing any more information from the source.
800+
794801
// a precomputed cache for ranges of defined/undefined bits
795802
// 0000010010001110 will become
796803
// [5, 1, 2, 1, 3, 3, 1]

0 commit comments

Comments
 (0)