1From 25738bb9c75f94b451201acfd6bcab13bdeee512 Mon Sep 17 00:00:00 2001
2From: Roy Li <rongqing.li@windriver.com>
3Date: Thu, 5 May 2016 09:52:01 +0800
4Subject: [PATCH] [PATCH] avoid gcc optimize-away the loops
5
6Upstream-Status: Pending
7
8Change expression used in do_integer_mul and do_uint64_mul
9benchmarks so GCC doesn't optimize-away the loops, other
10things are same:
11-               TEN(r *= s;); r -= t;
12+               i = 0;
13+               while ( i++ < 10)
14+                       r *= s;
15+               r -= t;
16
17and TEN is macro:
18	#define TEN(a) a a a a a a a a a a
19
20Signed-off-by: Roy Li <rongqing.li@windriver.com>
21
22---
23 src/lat_ops.c | 30 +++++++++++++++++++++++++-----
24 1 file changed, 25 insertions(+), 5 deletions(-)
25
26diff --git a/src/lat_ops.c b/src/lat_ops.c
27index d343ff3..457072b 100644
28--- a/src/lat_ops.c
29+++ b/src/lat_ops.c
30@@ -126,11 +126,23 @@ do_integer_mul(iter_t iterations, void* cookie)
31 	struct _state *pState = (struct _state*)cookie;
32 	register int r = pState->N + 37431;
33 	register int s = pState->N + 4;
34-	register int t = r * s * s * s * s * s * s * s * s * s * s - r;
35+	register int t = r;
36+	int i = 0;
37+
38+	while ( i++ < 10)
39+		t *= s;
40+	t -= r;
41
42 	while (iterations-- > 0) {
43-		TEN(r *= s;); r -= t;
44-		TEN(r *= s;); r -= t;
45+		i = 0;
46+		while ( i++ < 10)
47+			r *= s;
48+		r -= t;
49+
50+		i = 0;
51+		while ( i++ < 10)
52+			r *= s;
53+		r -= t;
54 	}
55 	use_int(r);
56 }
57@@ -207,13 +219,21 @@ do_int64_mul(iter_t iterations, void* cookie)
58 	register int64 r = (int64)pState->N + 37420;
59 	register int64 s = (int64)pState->N + 4;
60 	register int64 t;
61+	int i = 0;
62
63 	r += (int64)(pState->N + 6)<<32;
64 	t = r * s * s * s * s * s * s * s * s * s * s - r;
65
66 	while (iterations-- > 0) {
67-		TEN(r *= s;); r -= t;
68-		TEN(r *= s;); r -= t;
69+		i = 0;
70+		while ( i++ < 10)
71+			r *= s;
72+		r -= t;
73+
74+		i = 0;
75+		while ( i++ < 10)
76+			r *= s;
77+		r -= t;
78 	}
79 	use_int((int)r);
80 }
81