by nkurz · 10y ago · 0 comments
I'd be interested to know more about the internal implementation, but I don't think that address calculation uses any additional registers (physical or logical). There are multiple execution ports dedicated to address generation, and I think they are self-contained.
multiple CPU registers to do the abs()
Likely yes for any library implementation, although this made me wonder if it's possible to do it in-place with constants. Turns out it is, Hacker's Delight to the rescue:
abs(x) == ((x >>> 30) | 1) * x
http://hackersdelight.org/basics2.pdfThe single-expression abs that you specify needs at least two registers, one to hold the shifted value and one to hold the original one. Two alternatives which do not involve multiplication and are 3 instructions is here: