4 ms·
volatile works, asm works, and it's usually not hard to trick the optimizer.
by JoachimSchipper 12y ago
volatile works, asm works, and it's usually not hard to trick the optimizer.
- TheLoneWolfling 12y agoIt's becoming harder to trick the optimizer all the time. I mean, the goal of an optimizer is literally not to be able to be tricked into doing work it doesn't have to.
- JoachimSchipper 12y agoYes; e.g. http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/explicit_bzero.c http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string... demonstrates that rather well. Still, it is and will remain possible - and for the intended use, that's probably good enough. (It's not write - and - forget code where tricking the optimizer is security-critical.)
- TheLoneWolfling 12y agoIf you're having to trick the optimizer, you're doing something wrong. If the language is such that there are things in the language that inherently require tricking the optimizer, the language is doing it wrong.
- JoeAltmaier 12y agoI wondered about 'volatile'. Its not really meant for that - but maybe its enough to trigger 'hands off'.
- fragmede 12y agoPractically speaking, 'volatile' has used for that pretty much since its inception.
- TheLoneWolfling 12y agoYep, even though it really shouldn't be. Volatile has... problems. It was meant more for mem-mapped IO than thread safety. And it's too powerful at the same time, as in there are a number of optimizations that are safe in the typical use cases of volatile that cannot be done to volatile variables.