2 ms·
Always tricky. I avoid inline assembler, except in cases where the compiler cannot generate some special instruction. This can occur in drivers and kernel code,
by JoeAltmaier 6y ago
Always tricky. I avoid inline assembler, except in cases where the compiler cannot generate some special instruction. This can occur in drivers and kernel code, where there's no other language feature to manipulate processor architecture (special registers or machine state manipulation).
It can be fun to try and hand-optimize code in regular applications. I can't help but feel, there's more juice in teaching the compiler to recognize the case and generate better code instead. But few know how to go down that road.
- saagarjha 6y agoTeaching compilers works in most cases, but not all of them. Sometimes the language just does not have ways of expressing things to the compiler that you would like it to know. (For example, how would you explain to the compiler that reading within the same page will not trigger a fault? Such a guarantee is often used in vectorized strlen functions, for example.)