Skip to content

Commit

Permalink
day 85: big perf boost from 10k ns/op to 522 ns/op
Browse files Browse the repository at this point in the history
  • Loading branch information
vaskoz committed Nov 14, 2018
1 parent af82d65 commit 439ba1c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions day85/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package day85
// MathematicalIf returns x if b=1 and y if b=0.
func MathematicalIf(x, y, b int32) int32 {
var xMask, yMask int32
for i := uint32(0); i < 32; i++ {
xMask |= b << i
}
xMask = b
xMask |= xMask << 1
xMask |= xMask << 2
xMask |= xMask << 4
xMask |= xMask << 8
xMask |= xMask << 16
yMask = ^xMask
return (x & xMask) | (y & yMask)
}

0 comments on commit 439ba1c

Please sign in to comment.