Re: Preventing the Compiler from Optimizing Away Benchmarks

2023-03-13 Thread jmh530 via Digitalmars-d-learn
On Monday, 13 March 2023 at 15:23:25 UTC, user1234 wrote: [snip] [1] https://theunixzoo.co.uk/blog/2021-10-14-preventing-optimisations.html that's illegal code. You mix GCC/LLVM syntax with D asm block and the front-end wont recognize that. LDC recognizes a syntax similar to what is descr

Re: Preventing the Compiler from Optimizing Away Benchmarks

2023-03-13 Thread user1234 via Digitalmars-d-learn
On Monday, 13 March 2023 at 14:17:57 UTC, jmh530 wrote: I was looking at [1] for ways to prevent the compiler from optimizing away code when trying to benchmark. It has the following C++ code as a simpler version: ``` inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { asm volati

Preventing the Compiler from Optimizing Away Benchmarks

2023-03-13 Thread jmh530 via Digitalmars-d-learn
I was looking at [1] for ways to prevent the compiler from optimizing away code when trying to benchmark. It has the following C++ code as a simpler version: ``` inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { asm volatile("" : "+r,m"(value) : : "memory"); } ``` I made an att