bench-stringop revision 1.1 1 1.1 mrg #!/bin/bash
2 1.1 mrg
3 1.1 mrg # Script to measure memset and memcpy for different sizes and strategies.
4 1.1 mrg #
5 1.1 mrg # Contributed by Jan Hubicka <jh (at] suse.cz>
6 1.1 mrg #
7 1.1 mrg # Copyright (C) 2019 Free Software Foundation, Inc.
8 1.1 mrg #
9 1.1 mrg # This file is part of GCC.
10 1.1 mrg #
11 1.1 mrg # GCC is free software; you can redistribute it and/or modify
12 1.1 mrg # it under the terms of the GNU General Public License as published by
13 1.1 mrg # the Free Software Foundation; either version 3, or (at your option)
14 1.1 mrg # any later version.
15 1.1 mrg #
16 1.1 mrg # GCC is distributed in the hope that it will be useful,
17 1.1 mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 1.1 mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 1.1 mrg # GNU General Public License for more details.
20 1.1 mrg #
21 1.1 mrg # You should have received a copy of the GNU General Public License
22 1.1 mrg # along with GCC; see the file COPYING. If not, write to
23 1.1 mrg # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24 1.1 mrg # Boston, MA 02110-1301, USA.
25 1.1 mrg
26 1.1 mrg # This script will search a line starting with 'spawn' that includes the
27 1.1 mrg # pattern you are looking for (typically a source file name).
28 1.1 mrg #
29 1.1 mrg # Once it finds that pattern, it re-executes the whole command
30 1.1 mrg # in the spawn line. If the pattern matches more than one spawn
31 1.1 mrg # command, it asks which one you want.
32 1.1 mrg
33 1.1 mrg test()
34 1.1 mrg {
35 1.1 mrg rm -f a.out
36 1.1 mrg cat <<END | $1 -x c -O3 $3 -DAVG_SIZE=$2 $STRINGOP -DMEMORY_COPIES=$memsize -
37 1.1 mrg #define BUFFER_SIZE (16*1024*1024 + AVG_SIZE*2)
38 1.1 mrg /*#define MEMORY_COPIES (1024*1024*64*(long long)10)*/
39 1.1 mrg $type t[BUFFER_SIZE];
40 1.1 mrg int main()
41 1.1 mrg {
42 1.1 mrg unsigned int i;
43 1.1 mrg for (i=0;i<((long long)MEMORY_COPIES + AVG_SIZE * 2 - 1)/AVG_SIZE*2;i++)
44 1.1 mrg #ifdef test_memset
45 1.1 mrg __builtin_memset (t+(i*1024*1024+i*1)%(BUFFER_SIZE - AVG_SIZE*2), i, (AVG_SIZE + i) % (AVG_SIZE * 2 + 0));
46 1.1 mrg #else
47 1.1 mrg __builtin_memcpy (t+(i*1024*1024+i*1)%(BUFFER_SIZE - AVG_SIZE*2), t+((i+1)*1024*1024*4+i*1)%(BUFFER_SIZE - AVG_SIZE *2), (AVG_SIZE + i) % (AVG_SIZE * 2 + 0));
48 1.1 mrg #endif
49 1.1 mrg return 0;
50 1.1 mrg }
51 1.1 mrg END
52 1.1 mrg TIME=`/usr/bin/time -f "%E" ./a.out 2>&1`
53 1.1 mrg echo -n " "$TIME
54 1.1 mrg echo $TIME $4 >>/tmp/accum
55 1.1 mrg }
56 1.1 mrg
57 1.1 mrg test2()
58 1.1 mrg {
59 1.1 mrg rm -f a.out
60 1.1 mrg cat <<END | clang -x c -O3 $3 -DAVG_SIZE=$2 $STRINGOP -DMEMORY_COPIES=$memsize 2>/dev/null -
61 1.1 mrg #define BUFFER_SIZE (16*1024*1024 + AVG_SIZE*2)
62 1.1 mrg /*#define MEMORY_COPIES (1024*1024*64*(long long)10)*/
63 1.1 mrg $type t[BUFFER_SIZE];
64 1.1 mrg int main()
65 1.1 mrg {
66 1.1 mrg unsigned int i;
67 1.1 mrg for (i=0;i<((long long)MEMORY_COPIES + AVG_SIZE * 2 - 1)/AVG_SIZE*2;i++)
68 1.1 mrg #ifdef test_memset
69 1.1 mrg __builtin_memset (t+(i*1024*1024+i*1)%(BUFFER_SIZE - AVG_SIZE*2), i, (AVG_SIZE + i) % (AVG_SIZE * 2 + 0));
70 1.1 mrg #else
71 1.1 mrg __builtin_memcpy (t+(i*1024*1024+i*1)%(BUFFER_SIZE - AVG_SIZE*2), t+((i+1)*1024*1024*4+i*1)%(BUFFER_SIZE - AVG_SIZE *2), (AVG_SIZE + i) % (AVG_SIZE * 2 + 0));
72 1.1 mrg #endif
73 1.1 mrg return 0;
74 1.1 mrg }
75 1.1 mrg END
76 1.1 mrg TIME=`/usr/bin/time -f "%E" ./a.out 2>&1`
77 1.1 mrg echo -n " "$TIME
78 1.1 mrg echo $TIME $4 >>/tmp/accum
79 1.1 mrg }
80 1.1 mrg
81 1.1 mrg testrow()
82 1.1 mrg {
83 1.1 mrg echo -n "" >/tmp/accum
84 1.1 mrg printf "%12i " $3
85 1.1 mrg test "$2" "$3" "-mstringop-strategy=libcall" libcall
86 1.1 mrg test "$2" "$3" "-mstringop-strategy=rep_byte -malign-stringops" rep1
87 1.1 mrg test "$2" "$3" "-mstringop-strategy=rep_byte -mno-align-stringops" rep1noalign
88 1.1 mrg test "$2" "$3" "-mstringop-strategy=rep_4byte -malign-stringops" rep4
89 1.1 mrg test "$2" "$3" "-mstringop-strategy=rep_4byte -mno-align-stringops" rep4noalign
90 1.1 mrg if [ "$mode" == 64 ]
91 1.1 mrg then
92 1.1 mrg test "$2" "$3" "-mstringop-strategy=rep_8byte -malign-stringops" rep8
93 1.1 mrg test "$2" "$3" "-mstringop-strategy=rep_8byte -mno-align-stringops" rep8noalign
94 1.1 mrg fi
95 1.1 mrg test "$2" "$3" "-mstringop-strategy=loop -malign-stringops" loop
96 1.1 mrg test "$2" "$3" "-mstringop-strategy=loop -mno-align-stringops" loopnoalign
97 1.1 mrg test "$2" "$3" "-mstringop-strategy=unrolled_loop -malign-stringops" unrl
98 1.1 mrg test "$2" "$3" "-mstringop-strategy=unrolled_loop -mno-align-stringops" unrlnoalign
99 1.1 mrg test "$2" "$3" "-mstringop-strategy=vector_loop -malign-stringops" sse
100 1.1 mrg test "$2" "$3" "-mstringop-strategy=vector_loop -mno-align-stringops -msse2" ssenoalign
101 1.1 mrg #test2 "$2" "$3" ""
102 1.1 mrg test "$2" "$3" "-mstringop-strategy=byte_loop" byte
103 1.1 mrg best=`cat /tmp/accum | sort | head -1`
104 1.1 mrg test "$2" "$3" " -fprofile-generate" >/dev/null 2>&1
105 1.1 mrg test "$2" "$3" " -fprofile-use"
106 1.1 mrg test "$2" "$3" " -minline-stringops-dynamically"
107 1.1 mrg echo " $best"
108 1.1 mrg }
109 1.1 mrg
110 1.1 mrg test_all_sizes()
111 1.1 mrg {
112 1.1 mrg if [ "$mode" == 64 ]
113 1.1 mrg then
114 1.1 mrg echo " block size libcall rep1 noalg rep4 noalg rep8 noalg loop noalg unrl noalg sse noalg byte PGO dynamic BEST"
115 1.1 mrg else
116 1.1 mrg echo " block size libcall rep1 noalg rep4 noalg loop noalg unrl noalg sse noalg byte PGO dynamic BEST"
117 1.1 mrg fi
118 1.1 mrg #for size in 1 2 3 4 6 8 10 12 14 16 24 32 48 64 128 256 512 1024 4096 8192 81920 819200 8192000
119 1.1 mrg #for size in 8192000 819200 81920 8192 4096 2048 1024 512 256 128 64 48 32 24 16 14 12 10 8 6 5 4 3 2 1
120 1.1 mrg for size in 8192000 819200 81920 20480 8192 4096 2048 1024 512 256 128 64 48 32 24 16 14 12 10 8 6 4 1
121 1.1 mrg #for size in 128 256 1024 4096 8192 81920 819200
122 1.1 mrg do
123 1.1 mrg testrow "$1" "$2" $size
124 1.1 mrg done
125 1.1 mrg }
126 1.1 mrg
127 1.1 mrg mode=$1
128 1.1 mrg shift
129 1.1 mrg export memsize=$1
130 1.1 mrg shift
131 1.1 mrg cmdline=$*
132 1.1 mrg if [ "$mode" != 32 ]
133 1.1 mrg then
134 1.1 mrg if [ "$mode" != 64 ]
135 1.1 mrg then
136 1.1 mrg echo "Usage:"
137 1.1 mrg echo "test_stringop mode size cmdline"
138 1.1 mrg echo "mode is either 32 or 64"
139 1.1 mrg echo "size is amount of memory copied in each test. Should be chosed small enough so runtime is less than minute for each test and sorting works"
140 1.1 mrg echo "Example: test_stringop 32 640000000 ./xgcc -B ./ -march=pentium3"
141 1.1 mrg exit
142 1.1 mrg fi
143 1.1 mrg fi
144 1.1 mrg
145 1.1 mrg echo "memcpy"
146 1.1 mrg export STRINGOP=""
147 1.1 mrg type=char
148 1.1 mrg test_all_sizes $mode "$cmdline -m$mode"
149 1.1 mrg echo "Aligned"
150 1.1 mrg type=long
151 1.1 mrg test_all_sizes $mode "$cmdline -m$mode"
152 1.1 mrg echo "memset"
153 1.1 mrg export STRINGOP="-Dtest_memset=1"
154 1.1 mrg type=char
155 1.1 mrg test_all_sizes $mode "$cmdline -m$mode"
156 1.1 mrg echo "Aligned"
157 1.1 mrg type=long
158 1.1 mrg test_all_sizes $mode "$cmdline -m$mode"
159