Skip to content

Commit

Permalink
std::math: minor optimization the Fma function and clear todo
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jul 29, 2024
1 parent 588c9c7 commit d6f9dab
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions std/math/fma.jule
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,12 @@ fn shl(u1: u64, u2: u64, n: uint): (r1: u64, r2: u64) {
}

fn shr(u1: u64, u2: u64, n: uint): (r1: u64, r2: u64) {
// Compute shift for correct FMA computing.
// Actually: r2 = u2>>n | u1<<(64-n) | u1>>(n-64)
// But u1>>(n-64) is bad computation, but why: ?
// For this reason, compute this shifting manually.
//
// TODO: Make sure this computation is fast and efficiency?
let mut shift = u1
let mut shiftN = n - 64
for shift > 0 && shiftN > 0 {
shiftN--
shift >>= 1
r2 = u2 >> n | u1 << (64 - n)
// Avoid overflow value of: u1>>(n-64)
let shift = n - 64
if shift < 64 {
r2 |= u1 >> shift
}

r2 = u2 >> n | u1 << (64 - n) | shift
r1 = u1 >> n
ret
}
Expand Down

0 comments on commit d6f9dab

Please sign in to comment.