Prevent GCC from optimizing away a snippet of code

Nowadays compilers are extremely capable of elimiting 'dead' code. But in benchmarking we need some seemingly 'useless' code to do the work we want. For example, to do computation in registers in order to measure instruction latency and throughput. In these cases, we need a mechanism to temporarily disable optimization.

This document keep an up-to-date collections of techniques to temporarily disable compiler optimizations. These techniques are tested on a recent gcc or icc compiler.

Using volatile

volatile makes compilers be extremely careful (or conservative) on memory load and store of a variable. Most compilers tend to do no optimizations at all (even for proven dead code). So the volatile technique becomes the top 1 used.


  Read the rest of this post

Convert Chinese Asciidoc Documents to PDF

Asciidoctor does well in translating asciidoc documents to html5, docbook and etc. Chinese documents also looks great in html5 and docbook. But sometimes we need to use PDF to share with others. Unfortunately, this is not easy for Chinese documents. This document shares my experience converting Chinese asciidoc documents into pdfs.


  Read the rest of this post
Older