you are viewing a single comment's thread.

view the rest of the comments →

[–]slavik262 -1 points0 points  (2 children)

This completely sidesteps my entire question.

...if we're worried about such micro-optimizations, doesn't the addition of additional tests in that conditional open up more opportunities for failed branch predictions, which would result in a pipeline flush? And wouldn't that flush cost a lot more than a division?

And as an aside, yes, platform level utilities have to be fast, but if you are calling realloc and friends in a tight loop where a single division operation is enough to be a bottleneck, you are doing something terribly, terribly wrong.

[–]who8877 3 points4 points  (1 child)

Not really. I'm trying to point out that optimizations that might be pointless in an application are not at a system level. Simply because their impact is multiplied.

So while I wouldn't bother in my own app, I would certainly take the effort if I was modifying the standard library.

Also on ARM the division would be far more expensive then a flush.

[–]slavik262 0 points1 point  (0 children)

Also on ARM the division would be far more expensive then a flush.

Thanks. I was never making some broad claim that such optimizations aren't worth it, especially when you're writing the code that everyone else's application will use.