Skip to content

@noopt macro for avoiding optimizations #29817

@KristofferC

Description

@KristofferC

For e.g. benchmarking purposes it would be convenient to have a @noopt macro or something that would instruct the compiler not to optimize something. For example, the google benchmark suite has the following code

// The DoNotOptimize(...) function can be used to prevent a value or
// expression from being optimized away by the compiler. This function is
// intended to add little to no overhead.
// See: https://youtu.be/nXaxk27zwlk?t=2441
#ifndef BENCHMARK_HAS_NO_INLINE_ASSEMBLY
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
  asm volatile("" : : "r,m"(value) : "memory");
}

https://github.com/google/benchmark/blob/d8c0f27448dfad95b94285e612bba1f7c55c9dd0/include/benchmark/benchmark.h#L304-L347

(also see https://www.youtube.com/watch?v=nXaxk27zwlk&feature=youtu.be&t=2441 as the comment links to)

It would be useful to have something similar in Julia.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions