File Coverage

djbsort_src/int32_sort.c
Criterion Covered Total %
statement 40 40 100.0
branch 31 32 96.8
condition n/a
subroutine n/a
pod n/a
total 71 72 98.6


line stmt bran cond sub pod time code
1             #include "crypto_int32.h"
2             #include "int32_sort.h"
3             #define int32 crypto_int32
4             #define int32_MINMAX(a,b) crypto_int32_minmax(&(a),&(b))
5              
6 18           void int32_sort(int32 *x,long long n)
7             {
8             long long top,p,q,r,i,j;
9              
10 18 100         if (n < 2) return;
11 17           top = 1;
12 66 100         while (top < n - top) top += top;
13              
14 83 100         for (p = top;p >= 1;p >>= 1) {
15 66           i = 0;
16 1276 100         while (i + 2 * p <= n) {
17 5774 100         for (j = i;j < i + p;++j)
18 4564           int32_MINMAX(x[j],x[j+p]);
19 1210           i += 2 * p;
20             }
21 1027 100         for (j = i;j < n - p;++j)
22 961           int32_MINMAX(x[j],x[j+p]);
23              
24 66           i = 0;
25 66           j = 0;
26 193 100         for (q = top;q > p;q >>= 1) {
27 172 100         if (j != i) for (;;) {
28 52 50         if (j == n - q) goto done;
29 52           int32 a = x[j + p];
30 156 100         for (r = q;r > p;r >>= 1)
31 104           int32_MINMAX(a,x[j + r]);
32 52           x[j + p] = a;
33 52           ++j;
34 52 100         if (j == i + p) {
35 7           i += 2 * p;
36 7           break;
37             }
38             }
39 1301 100         while (i + p <= n - q) {
40 5522 100         for (j = i;j < i + p;++j) {
41 4348           int32 a = x[j + p];
42 23737 100         for (r = q;r > p;r >>= 1)
43 19389           int32_MINMAX(a,x[j+r]);
44 4348           x[j + p] = a;
45             }
46 1174           i += 2 * p;
47             }
48             /* now i + p > n - q */
49 127           j = i;
50 194 100         while (j < n - q) {
51 67           int32 a = x[j + p];
52 230 100         for (r = q;r > p;r >>= 1)
53 163           int32_MINMAX(a,x[j+r]);
54 67           x[j + p] = a;
55 67           ++j;
56             }
57              
58 127           done: ;
59             }
60             }
61             }