]> git.lizzy.rs Git - rust.git/commitdiff
Document the precomputation algorithm's purpose
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 12 Mar 2019 14:00:12 +0000 (15:00 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 12 Mar 2019 14:00:12 +0000 (15:00 +0100)
src/librustc_mir/interpret/memory.rs

index fba0a9af21392c6205bdb0bb12305951f0e1a6ec..6ea200d4e4fad3519335096d9b912e41c95e31a6 100644 (file)
@@ -791,6 +791,13 @@ fn copy_undef_mask(
 
         let undef_mask = &self.get(src.alloc_id)?.undef_mask;
 
+        // Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`),
+        // a naive undef mask copying algorithm would repeatedly have to read the undef mask from
+        // the source and write it to the destination. Even if we optimized the memory accesses,
+        // we'd be doing all of this `repeat` times.
+        // Therefor we precompute a compressed version of the undef mask of the source value and
+        // then write it back `repeat` times without computing any more information from the source.
+
         // a precomputed cache for ranges of defined/undefined bits
         // 0000010010001110 will become
         // [5, 1, 2, 1, 3, 3, 1]