ARM7 example: source file routines.c
1 #include "types.h"
2 #include "routines.h"
3
4
5 void Count25 (uint *x)
6 {
7 count_t u = 25;
8
9 for (; u > 0; u -= 2)
10 {
11 *x = *x + u;
12 }
13 }
14
15
16 void Count (count_t u, uint *x)
17 {
18 for (; u > 0; u -= 2)
19 {
20 *x = *x + u;
21 }
22 }
23
24
25 void Foo (count_t num, uint *x)
26 {
27 Count (num + 3, x);
28 /* The loop in Count depends on Count.u = num + 3. */
29 }
30
31
32 void Foo7 (uint *x)
33 {
34 *x = *x + 10;
35
36 Count (7, x);
37 /* The loop in Count depends on Count.u = 7. */
38
39 *x = *x - 8;
40 }
41
42
43 void Solve (uint *x)
44 {
45 count_t i;
46 volatile count_t k;
47
48 for (i = 0; i < 8; i++)
49 /* The bounds on this loop are static. */
50 {
51 k = Ones (*x);
52 /* k is now the number of '1' bits in *x. */
53 /* This would be quite hard to analyse statically. */
54
55 if (k == 0) break;
56 /* This can make the for-loop stop before its full */
57 /* number of iterations. Bound-T uses the full number */
58 /* for the Worst Case Time. */
59
60 Count (k, x);
61 /* The loop in Count depends on Count.u = k, which is */
62 /* hard to analyse statically. An assertion is needed. */
63 }
64 }
65
66
67 count_t Ones (uint x)
68 {
69 count_t v = 0;
70
71 while (x)
72 /* This is not a 'counter' loop, so Bound-T cannot find */
73 /* its bounds automatically. An assertion is needed. */
74 {
75 if (x & 1) v ++;
76 x >>= 1;
77 }
78
79 return v;
80 }