github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/runtime/vlop_arm_test.go (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package runtime_test
     6  
     7  import "testing"
     8  
     9  // arm soft division benchmarks adapted from
    10  // http://ridiculousfish.com/files/division_benchmarks.tar.gz
    11  
    12  const numeratorsSize = 1 << 21
    13  
    14  var numerators = randomNumerators()
    15  
    16  type randstate struct {
    17  	hi, lo uint32
    18  }
    19  
    20  func (r *randstate) rand() uint32 {
    21  	r.hi = r.hi<<16 + r.hi>>16
    22  	r.hi += r.lo
    23  	r.lo += r.hi
    24  	return r.hi
    25  }
    26  
    27  func randomNumerators() []uint32 {
    28  	numerators := make([]uint32, numeratorsSize)
    29  	random := &randstate{2147483563, 2147483563 ^ 0x49616E42}
    30  	for i := range numerators {
    31  		numerators[i] = random.rand()
    32  	}
    33  	return numerators
    34  }
    35  
    36  func bmUint32Div(divisor uint32, b *testing.B) {
    37  	var sum uint32
    38  	for i := 0; i < b.N; i++ {
    39  		sum += numerators[i&(numeratorsSize-1)] / divisor
    40  	}
    41  }
    42  
    43  func BenchmarkUint32Div7(b *testing.B)         { bmUint32Div(7, b) }
    44  func BenchmarkUint32Div37(b *testing.B)        { bmUint32Div(37, b) }
    45  func BenchmarkUint32Div123(b *testing.B)       { bmUint32Div(123, b) }
    46  func BenchmarkUint32Div763(b *testing.B)       { bmUint32Div(763, b) }
    47  func BenchmarkUint32Div1247(b *testing.B)      { bmUint32Div(1247, b) }
    48  func BenchmarkUint32Div9305(b *testing.B)      { bmUint32Div(9305, b) }
    49  func BenchmarkUint32Div13307(b *testing.B)     { bmUint32Div(13307, b) }
    50  func BenchmarkUint32Div52513(b *testing.B)     { bmUint32Div(52513, b) }
    51  func BenchmarkUint32Div60978747(b *testing.B)  { bmUint32Div(60978747, b) }
    52  func BenchmarkUint32Div106956295(b *testing.B) { bmUint32Div(106956295, b) }
    53  
    54  func bmUint32Mod(divisor uint32, b *testing.B) {
    55  	var sum uint32
    56  	for i := 0; i < b.N; i++ {
    57  		sum += numerators[i&(numeratorsSize-1)] % divisor
    58  	}
    59  }
    60  
    61  func BenchmarkUint32Mod7(b *testing.B)         { bmUint32Mod(7, b) }
    62  func BenchmarkUint32Mod37(b *testing.B)        { bmUint32Mod(37, b) }
    63  func BenchmarkUint32Mod123(b *testing.B)       { bmUint32Mod(123, b) }
    64  func BenchmarkUint32Mod763(b *testing.B)       { bmUint32Mod(763, b) }
    65  func BenchmarkUint32Mod1247(b *testing.B)      { bmUint32Mod(1247, b) }
    66  func BenchmarkUint32Mod9305(b *testing.B)      { bmUint32Mod(9305, b) }
    67  func BenchmarkUint32Mod13307(b *testing.B)     { bmUint32Mod(13307, b) }
    68  func BenchmarkUint32Mod52513(b *testing.B)     { bmUint32Mod(52513, b) }
    69  func BenchmarkUint32Mod60978747(b *testing.B)  { bmUint32Mod(60978747, b) }
    70  func BenchmarkUint32Mod106956295(b *testing.B) { bmUint32Mod(106956295, b) }