test::black_box for big size T?

ab1281d
Opened by Kibeom Kim at 2019-01-28 15:42:36

I'm not sure if this is a bug or not, but I noticed that FB Folly has two versions of doNotOptimizeAway

https://github.com/facebook/folly/blob/1c098e2758d1bd55c48ffa26dab389dbbe96a666/folly/Benchmark.h#L308

asm volatile("" ::"r"(datum));
asm volatile("" ::"m"(datum) : "memory");

First one for size <= long, second one for larger sizes. Where as our test::black_box only has the first version. Is the second one needed?

  1. @nagisa @huonw

    Kibeom Kim at 2016-12-21 23:59:54

  2. We do

    asm!("" : : "r"(&dummy))
    

    which is pretty much the same as "m"(dummy). We could make it

    unsafe { asm!(""::"*m"(&mut x)); }
    

    in order to use a technically correct reference type and avoid a single instruction for putting the address into a register, but it seems like a wasted effort to me.

    Simonas Kazlauskas at 2016-12-22 00:45:39

  3. fwiw, this if Folly's commit log https://github.com/facebook/folly/commit/81d9192f8afdf53fcbc7bf572f8ce638516380f8

    Kibeom Kim at 2016-12-22 01:59:00

  4. Can we just pass &T instead of T directly to black_box? I'm not familiar with the implementation so I don't really know.

    Mark Rousskov at 2017-05-18 04:22:47

  5. I don't know what the right answers are, but tagging feature-accepted because I would be interested in seeing a PR that applies some of the ideas from doNotOptimizeAway to our black_box.

    David Tolnay at 2017-11-18 07:47:50

  6. Triage: don't believe black_box has been modified in a very long time.

    Steve Klabnik at 2019-01-28 15:42:36