From cb293cf0cb1a0d008022ef55cad29aa8a3827508 Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Fri, 15 Sep 2017 20:57:07 -0400 Subject: Allow bp in inline asm by tweaking measure --- measure.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'measure.c') diff --git a/measure.c b/measure.c index ea827f618..18f07468d 100644 --- a/measure.c +++ b/measure.c @@ -1,6 +1,6 @@ /* * Benchmarking utilities extracted from SUPERCOP by Andres Erbsen - * based on measure-anything.c version 20120328 and measure.c + * based on measure-anything.c version 20120328 and measure.c * by D. J. Bernstein * Public domain. */ @@ -85,15 +85,24 @@ void limits() void UUT(unsigned char*); -void measure(int n) +// place the call to UUT in a separate function, because gcc prohibits +// use of bp in inline assembly if you have a variable-length array or +// alloca in the code; see +// https://stackoverflow.com/questions/46248430/how-can-i-determine-preferably-at-compile-time-whether-gcc-is-using-rbp-based?noredirect=1#comment79462384_46248430 +void measure_helper(int n, unsigned char *buf, long long* cycles) { - unsigned char *buf = aligned_alloc(64, 1024); - long long* cycles = calloc(n + 1, sizeof(long long)); - for (int i = 0;i <= n;++i) { cycles[i] = cpucycles(); UUT(buf); } +} + +void measure(int n) +{ + unsigned char *buf = aligned_alloc(64, 1024); + long long* cycles = calloc(n + 1, sizeof(long long)); + + measure_helper(n, buf, cycles); for (int i = 0;i < n;++i) cycles[i] = cycles[i + 1] - cycles[i]; for (int i = 0;i < n;++i) printf("%lld\n", cycles[i]); -- cgit v1.2.3