File Coverage

djbsort_src/int64_sort.c
Criterion Covered Total %
statement 31 40 77.5
branch 24 32 75.0
condition n/a
subroutine n/a
pod n/a
total 55 72 76.3


line stmt bran cond sub pod time code
1             #include "crypto_int64.h"
2             #include "int64_sort.h"
3             #define int64 crypto_int64
4             #define int64_MINMAX(a,b) crypto_int64_minmax(&(a),&(b))
5              
6 7           void int64_sort(int64 *x,long long n)
7             {
8             long long top,p,q,r,i,j;
9              
10 7 50         if (n < 2) return;
11 7           top = 1;
12 21 100         while (top < n - top) top += top;
13              
14 28 100         for (p = top;p >= 1;p >>= 1) {
15 21           i = 0;
16 42 100         while (i + 2 * p <= n) {
17 49 100         for (j = i;j < i + p;++j)
18 28           int64_MINMAX(x[j],x[j+p]);
19 21           i += 2 * p;
20             }
21 28 100         for (j = i;j < n - p;++j)
22 7           int64_MINMAX(x[j],x[j+p]);
23              
24 21           i = 0;
25 21           j = 0;
26 42 100         for (q = top;q > p;q >>= 1) {
27 21 50         if (j != i) for (;;) {
28 0 0         if (j == n - q) goto done;
29 0           int64 a = x[j + p];
30 0 0         for (r = q;r > p;r >>= 1)
31 0           int64_MINMAX(a,x[j + r]);
32 0           x[j + p] = a;
33 0           ++j;
34 0 0         if (j == i + p) {
35 0           i += 2 * p;
36 0           break;
37             }
38             }
39 35 100         while (i + p <= n - q) {
40 28 100         for (j = i;j < i + p;++j) {
41 14           int64 a = x[j + p];
42 35 100         for (r = q;r > p;r >>= 1)
43 21           int64_MINMAX(a,x[j+r]);
44 14           x[j + p] = a;
45             }
46 14           i += 2 * p;
47             }
48             /* now i + p > n - q */
49 21           j = i;
50 28 100         while (j < n - q) {
51 7           int64 a = x[j + p];
52 14 100         for (r = q;r > p;r >>= 1)
53 7           int64_MINMAX(a,x[j+r]);
54 7           x[j + p] = a;
55 7           ++j;
56             }
57              
58 21           done: ;
59             }
60             }
61             }