~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to scripts/bench.py

  • Committer: Will Newton
  • Date: 2013-06-21 14:42:10 UTC
  • Revision ID: will.newton@linaro.org-20130621144210-za4jb0kw9d4mcnml
Allow aligning source and destination buffers separately.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
HAS = {
23
23
    'this': 'bounce memchr memcpy memset strchr strcpy strlen',
24
 
    'bionic': 'memcmp memcpy memset strcmp strcpy strlen',
 
24
    'bionic-a9': 'memcmp memcpy memset strcmp strcpy strlen',
 
25
    'bionic-a15': 'memcmp memcpy memset strcmp strcpy strlen',
25
26
    'bionic-c': ALL,
26
27
    'csl': 'memcpy memset',
27
28
    'glibc': 'memcpy memset strlen',
32
33
    'plain': 'memset memcpy strcmp strcpy',
33
34
}
34
35
 
35
 
def run(cache, variant, function, bytes, loops, alignment=8, quiet=False):
 
36
BOUNCE_ALIGNMENTS = ['1']
 
37
SINGLE_BUFFER_ALIGNMENTS = ['1', '2', '4', '8', '16', '32']
 
38
DUAL_BUFFER_ALIGNMENTS = ['1:32', '2:32', '4:32', '8:32', '16:32', '32:32']
 
39
 
 
40
ALIGNMENTS = {
 
41
    'bounce': BOUNCE_ALIGNMENTS,
 
42
    'memchr': SINGLE_BUFFER_ALIGNMENTS,
 
43
    'memset': SINGLE_BUFFER_ALIGNMENTS,
 
44
    'strchr': SINGLE_BUFFER_ALIGNMENTS,
 
45
    'strlen': SINGLE_BUFFER_ALIGNMENTS,
 
46
    'memcmp': DUAL_BUFFER_ALIGNMENTS,
 
47
    'memcpy': DUAL_BUFFER_ALIGNMENTS,
 
48
    'strcmp': DUAL_BUFFER_ALIGNMENTS,
 
49
    'strcpy': DUAL_BUFFER_ALIGNMENTS,
 
50
}
 
51
 
 
52
def run(cache, variant, function, bytes, loops, alignment, quiet=False):
36
53
    """Perform a single run, exercising the cache as appropriate."""
37
54
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops, alignment))
38
55
 
48
65
            assert False, 'Error %s while running %s' % (ex, cmd)
49
66
 
50
67
    parts = got.split(':')
51
 
    took = float(parts[5])
 
68
    took = float(parts[6])
52
69
 
53
70
    cache[key] = got
54
71
 
58
75
 
59
76
    return took
60
77
 
61
 
def run_many(cache, variants, bytes, alignments):
 
78
def run_many(cache, variants, bytes, all_functions):
62
79
    # We want the data to come out in a useful order.  So fix an
63
80
    # alignment and function, and do all sizes for a variant first
64
81
    bytes = sorted(bytes)
65
 
    mid = bytes[len(bytes)/2]
66
 
 
67
 
    # Use the ordering in 'this' as the default
68
 
    all_functions = HAS['this'].split()
69
 
 
70
 
    # Find all other functions
71
 
    for functions in HAS.values():
72
 
        for function in functions.split():
73
 
            if function not in all_functions:
74
 
                all_functions.append(function)
75
 
 
76
 
    for alignment in alignments:
77
 
        for function in all_functions:
 
82
    mid = bytes[int(len(bytes)/1.5)]
 
83
 
 
84
    if not all_functions:
 
85
        # Use the ordering in 'this' as the default
 
86
        all_functions = HAS['this'].split()
 
87
 
 
88
        # Find all other functions
 
89
        for functions in HAS.values():
 
90
            for function in functions.split():
 
91
                if function not in all_functions:
 
92
                    all_functions.append(function)
 
93
 
 
94
    for function in all_functions:
 
95
        for alignment in ALIGNMENTS[function]:
78
96
            for variant in variants:
79
97
                if function not in HAS[variant].split():
80
98
                    continue
103
121
 
104
122
def run_top(cache):
105
123
    variants = sorted(HAS.keys())
 
124
    functions = sys.argv[1:]
106
125
 
107
126
    # Upper limit in bytes to test to
108
127
    top = 512*1024
119
138
            steps = int(round(math.log(top) / math.log(step)))
120
139
            bytes.extend([int(step**x) for x in range(0, steps+1)])
121
140
 
122
 
    alignments = [8, 16, 4, 1, 2, 32]
123
 
 
124
 
    run_many(cache, variants, bytes, alignments)
 
141
    run_many(cache, variants, bytes, functions)
125
142
 
126
143
def main():
127
144
    cachename = 'cache.txt'