From 066675896deaa2dc654fc72aba7d749cd941454e Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Mon, 18 Aug 2014 19:58:10 +0200 Subject: [PATCH] Dont rely on compiler smartness to replace / and % by shifting and masking. Make use of constants more consistence. --- common/coords.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/coords.go b/common/coords.go index da10333..0ab4585 100644 --- a/common/coords.go +++ b/common/coords.go @@ -11,8 +11,8 @@ import ( const ( numBitsPerComponent = 12 - maxPositive = 2048 - modulo = 4096 + modulo = 1 << numBitsPerComponent + maxPositive = modulo / 2 ) type ( @@ -92,7 +92,9 @@ func InterleavedToXYZ(c int64) (x, y, z int16) { } func XYZToPlain(x, y, z int16) int64 { - return int64(z)<<24 + int64(y)<<12 + int64(x) + return int64(z)<<(2*numBitsPerComponent) + + int64(y)<= 0 { - return i % modulo + return i & mask } - return modulo - (-i)%modulo + return modulo - -i&mask } // Only to match the C++ code. func PlainToXYZ(i int64) (x, y, z int16) { x = unsignedToSigned(pythonModulo(int16(i))) - i = (i - int64(x)) / modulo + i = (i - int64(x)) >> numBitsPerComponent y = unsignedToSigned(pythonModulo(int16(i))) - i = (i - int64(y)) / modulo + i = (i - int64(y)) >> numBitsPerComponent z = unsignedToSigned(pythonModulo(int16(i))) return }