3 ms·
If, as a novice, you wish to write assembly code: - compile your code with "-O3 -S" and examine - analyze it. Assume that glibc for your architecture is going
by rcgorton 9y ago
If, as a novice, you wish to write assembly code:
- compile your code with "-O3 -S" and examine
- analyze it.
Assume that glibc for your architecture is going to be hand tuned (and exceptionally highly optimized)
Read and try to understand the native mem() and str() routines, as the folk who write these routings DEEPLY understand the micro-architecture and instruction set.
A counter example: all implementations of strlen() which evaluate a single character at a time are completely inept if the architecture has vector comparison capabilities.
- slavik81 9y agoIf you can cut things down to something reasonably self-contained, https://godbolt.org/ https://godbolt.org/ is incredibly useful. For example, I was curious about the approximate inverse square root instruction, so I wrote some code: https://godbolt.org/g/qdfSj4 https://godbolt.org/g/qdfSj4 It's a lot easier to read that than the raw output from gcc. The highlighting between matching segments is nice, and the right-click menu has all sorts of goodies, like scrolling everything to the same place or showing the manual entry for some instruction. Plus, it's super easy to see the effect of switching flags or compilers. Though to your point, apparently godbolt v0.0.1 was basically just: watch "g++ /tmp/test.cc -O2 -c -S -o - -masm=intel | c++filit | grep -vE '\s+\.'"
- souprock 9y agoWhat may seem to be "single character at a time" may not be. Recent chips from Intel can run the built-in string operations very quickly. It's as if they are internally vectorized by the hardware.