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

« back to all changes in this revision

Viewing changes to scripts/bench.py

  • Committer: Matthew Gretton-Dann
  • Author(s): Marcus Shawcroft
  • Date: 2013-01-16 20:55:59 UTC
  • mto: This revision was merged to the branch mainline in revision 99.
  • Revision ID: matthew.gretton-dann@linaro.org-20130116205559-7nye0l7d8fvzdye3
This patch fixes an issue in the AArch64 strnlen implementation which
occurs if  ULONG_MAX-15 <= n <= ULONG_MAX.

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-a9': 'memcmp memcpy memset strcmp strcpy strlen',
25
 
    'bionic-a15': 'memcmp memcpy memset strcmp strcpy strlen',
 
24
    'bionic': 'memcmp memcpy memset strcmp strcpy strlen',
26
25
    'bionic-c': ALL,
27
26
    'csl': 'memcpy memset',
28
 
    'glibc': 'memcpy memset strchr strlen',
 
27
    'glibc': 'memcpy memset strlen',
29
28
    'glibc-c': ALL,
30
29
    'newlib': 'memcpy strcmp strcpy strlen',
31
30
    'newlib-c': ALL,
33
32
    'plain': 'memset memcpy strcmp strcpy',
34
33
}
35
34
 
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
 
NUM_RUNS = 5
53
 
 
54
 
def run(cache, variant, function, bytes, loops, alignment, run_id, quiet=False):
 
35
def run(cache, variant, function, bytes, loops, alignment=8, quiet=False):
55
36
    """Perform a single run, exercising the cache as appropriate."""
56
 
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops, alignment, run_id))
 
37
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops, alignment))
57
38
 
58
39
    if key in cache:
59
40
        got = cache[key]
60
41
    else:
61
42
        xbuild = build
62
 
        cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s -a %(alignment)s -r %(run_id)s' % locals()
 
43
        cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s -a %(alignment)s' % locals()
63
44
 
64
45
        try:
65
46
            got = subprocess.check_output(cmd.split()).strip()
67
48
            assert False, 'Error %s while running %s' % (ex, cmd)
68
49
 
69
50
    parts = got.split(':')
70
 
    took = float(parts[7])
 
51
    took = float(parts[5])
71
52
 
72
53
    cache[key] = got
73
54
 
77
58
 
78
59
    return took
79
60
 
80
 
def run_many(cache, variants, bytes, all_functions):
 
61
def run_many(cache, variants, bytes, alignments):
81
62
    # We want the data to come out in a useful order.  So fix an
82
63
    # alignment and function, and do all sizes for a variant first
83
64
    bytes = sorted(bytes)
84
 
    mid = bytes[int(len(bytes)/1.5)]
85
 
 
86
 
    if not all_functions:
87
 
        # Use the ordering in 'this' as the default
88
 
        all_functions = HAS['this'].split()
89
 
 
90
 
        # Find all other functions
91
 
        for functions in HAS.values():
92
 
            for function in functions.split():
93
 
                if function not in all_functions:
94
 
                    all_functions.append(function)
95
 
 
96
 
    for function in all_functions:
97
 
        for alignment in ALIGNMENTS[function]:
 
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:
98
78
            for variant in variants:
99
79
                if function not in HAS[variant].split():
100
80
                    continue
107
87
                want = 5.0
108
88
 
109
89
                loops = int(f / math.sqrt(max(1, mid)))
110
 
                took = run(cache, variant, function, mid, loops, alignment, 0,
111
 
                           quiet=True)
 
90
                took = run(cache, variant, function, mid, loops, alignment, quiet=True)
112
91
                # Keep it reasonable for silly routines like bounce
113
92
                factor = min(20, max(0.05, want/took))
114
93
                f = f * factor
120
99
                for b in sorted(bytes):
121
100
                    # Figure out the number of loops to give a roughly consistent run
122
101
                    loops = int(f / math.sqrt(max(1, b)))
123
 
                    for run_id in range(0, NUM_RUNS):
124
 
                        run(cache, variant, function, b, loops, alignment,
125
 
                            run_id)
 
102
                    run(cache, variant, function, b, loops, alignment)
126
103
 
127
104
def run_top(cache):
128
105
    variants = sorted(HAS.keys())
129
 
    functions = sys.argv[1:]
130
106
 
131
107
    # Upper limit in bytes to test to
132
108
    top = 512*1024
143
119
            steps = int(round(math.log(top) / math.log(step)))
144
120
            bytes.extend([int(step**x) for x in range(0, steps+1)])
145
121
 
146
 
    run_many(cache, variants, bytes, functions)
 
122
    alignments = [8, 16, 4, 1, 2, 32]
 
123
 
 
124
    run_many(cache, variants, bytes, alignments)
147
125
 
148
126
def main():
149
127
    cachename = 'cache.txt'
155
133
            for line in f:
156
134
                line = line.strip()
157
135
                parts = line.split(':')
158
 
                cache[':'.join(parts[:7])] = line
 
136
                cache[':'.join(parts[:5])] = line
159
137
    except:
160
138
        pass
161
139