OT: abs(x) with 4 assembly insns
Sept. 30, 2003
4:59 a.m.
If your machine does not have an instruction for computing the absolute value, this computation can usually be done in three or four branch-free instructions. First, compute: signed int x signed int y = x >> 31 and then one of the following: abs = (x ^ y) - y abs = (x + y) ^ y abs = x - ((x<<1) & y)
7796
Age (days ago)
7796
Last active (days ago)
0 comments
1 participants
participants (1)
-
Damien Morton