Taming the optimizer

Johan Engelen j at j.nl
Thu Jun 14 16:56:21 UTC 2018

On Thursday, 14 June 2018 at 03:39:39 UTC, Mike Franklin wrote:
> Using the information at 
> https://stackoverflow.com/questions/40122141/preventing-compiler-optimizations-while-benchmarking, I've created this:

Have you read this too?

> This seems to work, but I don't know that I've implemented it 
> properly; especially the `use` function.  How would you write 
> this to achieve a real-world optimized measurement?  What's the 
> equivalent of...
> static void escape(void *p) {
>   asm volatile("" : : "g"(p) : "memory");
> }

Your use function may be correct, I'm not 100% sure. The escape 
function you ask for is clobbering _all_ memory (not only the 
memory accessible through `p`), so that then becomes:

void escape(void* p)
          import ldc.llvmasm;
           __asm("", "r,~{memory}", p); // added the memory 
clobber here


More information about the digitalmars-d-ldc mailing list