Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Bruse committed Jul 12, 2012
1 parent 64e5dd0 commit 2e57ba0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions log.go
Expand Up @@ -3,24 +3,24 @@ package gotomic
/*
Ripped from http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
*/
var LOG_TABLE_256 []uint32
var log_table_256 []uint32

func init() {
LOG_TABLE_256 = make([]uint32, 256)
log_table_256 = make([]uint32, 256)
for i := 2; i < 256; i++ {
LOG_TABLE_256[i] = 1 + LOG_TABLE_256[i/2]
log_table_256[i] = 1 + log_table_256[i/2]
}
}
func log2(v uint32) uint32 {
var r, tt uint32
if tt = v >> 24; tt != 0 {
r = 24 + LOG_TABLE_256[tt]
r = 24 + log_table_256[tt]
} else if tt = v >> 16; tt != 0 {
r = 16 + LOG_TABLE_256[tt]
r = 16 + log_table_256[tt]
} else if tt = v >> 8; tt != 0 {
r = 8 + LOG_TABLE_256[tt]
r = 8 + log_table_256[tt]
} else {
r = LOG_TABLE_256[v]
r = log_table_256[v]
}
return r
}

0 comments on commit 2e57ba0

Please sign in to comment.