Skip to content

Commit

Permalink
update bitlen to use __clzdi2 when using gccgo
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenjl committed Nov 18, 2013
1 parent 7695c37 commit 2b5f82a
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ func testCodecs(codecs map[string]encoding.Integer, data [][]int32, output bool)
return fmt.Errorf("benchmark/testCodecs: Problem recovering. index = %d, in = %d, recovered = %d, original length = %d, recovered length = %d\n", i, in[i], out2[i], k, len(out2))
}
}

runtime.GC()
}
}

Expand Down
6 changes: 3 additions & 3 deletions bitlen.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// +build gccgo !amd64,!386,!arm
// +build !gccgo,!amd64,!386,!arm

// (gccgo) OR ((NOT amd64) AND (NOT 386) AND (NOT ARM))
package encoding

import (
"math/big"
"math/big"
)

func bitlen(x big.Word) (n int) {
return 32 - int(nlz1a(uint32(x)))
return 32 - int(nlz1a(uint32(x)))
}
11 changes: 11 additions & 0 deletions bitlen_decl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !gccgo
// +build amd64 386 arm

package encoding

import (
"math/big"
)

// This is defined in util_{amd64,386}.s, copied from pkg/math/big/arith_{amd64/386}.s
func bitlen(x big.Word) (n int)
14 changes: 14 additions & 0 deletions bitlen_gccgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build gccgo

package encoding

import (
"math/big"
)

func clz(uint64) uint64 __asm__("__clzdi2")

func bitlen(x big.Word) (n int) {
if x == 0 { return 0 }
return 64-int(clz(uint64(x)))
}
2 changes: 1 addition & 1 deletion delta/fastpfor/fastpfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package fastpfor

import (
"errors"
"github.com/reducedb/bytebuffer"
"github.com/reducedb/encoding"
"github.com/reducedb/encoding/bitpacking"
"github.com/reducedb/bytebuffer"
"github.com/reducedb/encoding/cursor"
"math"
)
Expand Down
2 changes: 1 addition & 1 deletion delta/variablebyte/variablebyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package variablebyte

import (
"errors"
"github.com/reducedb/encoding"
"github.com/reducedb/bytebuffer"
"github.com/reducedb/encoding"
"github.com/reducedb/encoding/cursor"
)

Expand Down
2 changes: 1 addition & 1 deletion fastpfor/fastpfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package fastpfor

import (
"errors"
"github.com/reducedb/bytebuffer"
"github.com/reducedb/encoding"
"github.com/reducedb/encoding/bitpacking"
"github.com/reducedb/bytebuffer"

This comment has been minimized.

Copy link
@aktau

aktau Jun 22, 2014

Sorry for commenting on a commit so lately, but it's always a bit nicer if formatting changes are separate from functional changes. I'm quite interested in how you did this (I love Go and I love performance, what can I say), so the formatting changes and reorderings are a bit distracting. I don't always follow my own advice so well, but I try to :).

Very nice blog post as well! Kudos on the great benchmarking and implementation.

This comment has been minimized.

Copy link
@zhenjl

zhenjl Jun 23, 2014

Author Collaborator

@aktau appreciate the feedback. still a noob when it comes to Go and learning as I go... :)

This comment has been minimized.

Copy link
@aktau

aktau Jun 23, 2014

Keep on going!

"github.com/reducedb/encoding/cursor"
"math"
)
Expand Down
7 changes: 2 additions & 5 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package encoding

import (
"fmt"
"math/big"
"math/big"
)

func FloorBy(value, factor int) int {
Expand All @@ -21,7 +21,7 @@ func CeilBy(value, factor int) int {

func LeadingBitPosition(x uint32) int32 {
//return 32 - int32(nlz1a(x))
return int32(bitlen(big.Word(x)))
return int32(bitlen(big.Word(x)))
}

func DeltaMaxBits(initoffset int32, buf []int32) int32 {
Expand Down Expand Up @@ -541,6 +541,3 @@ func UnrolledLeadingBitFrequency128(in, freqs []int32) {
freqs[LeadingBitPosition(uint32(in[126]))]++
freqs[LeadingBitPosition(uint32(in[127]))]++
}

// This is defined in util_{amd64,386}.s, copied from pkg/math/big/arith_{amd64/386}.s
func bitlen(x big.Word) (n int)
2 changes: 1 addition & 1 deletion variablebyte/variablebyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package variablebyte

import (
"errors"
"github.com/reducedb/encoding"
"github.com/reducedb/bytebuffer"
"github.com/reducedb/encoding"
"github.com/reducedb/encoding/cursor"
)

Expand Down
2 changes: 1 addition & 1 deletion zigzag/fastpfor/fastpfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package fastpfor

import (
"errors"
"github.com/reducedb/bytebuffer"
"github.com/reducedb/encoding"
"github.com/reducedb/encoding/bitpacking"
"github.com/reducedb/bytebuffer"
"github.com/reducedb/encoding/cursor"
"math"
)
Expand Down

0 comments on commit 2b5f82a

Please sign in to comment.