vectorwrapper/asm_test/README.md

1.8 KiB

Checking the generated assembly

The test

In asm_test.cpp you can find a small program that asks the user for three input floats. The program will add these values together and use the int result as its return value. You can compile different versions of this program so you can compare the binaries: with or without VectorWrapper (-DWITH_VWR) and using std::array (-DUSE_STD_ARRAY) (which will force VectorWrapper's implementation to go through the get_at() implementation rather than using the offset-based one) or using just a plain struct. Please have a look at the source code, it's very short.

Compiling

You can compile four different binaries with the following commands:

g++ -o bin_vwr -O3 -std=gnu++14 asm_test.cpp -DWITH_VWR
g++ -o bin_vwr_array -O3 -std=gnu++14 asm_test.cpp -DWITH_VWR -DUSE_STD_ARRAY
g++ -o bin_plain -O3 -std=gnu++14 asm_test.cpp
g++ -o bin_plain_array -O3 -std=gnu++14 asm_test.cpp -DUSE_STD_ARRAY
  • bin_vwr will use VectorWrapper and the custom struct (offset based accessors)
  • bin_vwr_array will use VectorWrapper and std::array (get_at() method based accessors)
  • bin_plain will use the custom struct directly, without VectorWrapper
  • bin_plain_array will use std::array directly, without VectorWrapper

Running

An input file is provided for convenience. You can run each binary like:

./bin_vwr < sample_input.txt

but of course using a debugger will give you some insight:

gdb ./bin_vwr
break main
layout asm
run < sample_input.txt
ni
...

Results

On my system (amd64, g++ 8.3.0) this generates four identical binaries (you can check their hash). Feel free to insert bad syntax in the code to make sure that you're indeed compiling different ifdef branches. This is enough to say that at least in this simple case VectorWrapper has no overhead.