aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/binary_search
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-06 10:46:04 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-06 10:46:04 +0200
commit4938c455062ed72a41edaddbf212086efaae7570 (patch)
tree40da9fe937ebc8da4f7af7630a54079cb45ca3d2 /test/monniaux/binary_search
parentee711720964905a34fd78669f2f3e996287c8d33 (diff)
downloadcompcert-kvx-4938c455062ed72a41edaddbf212086efaae7570.tar.gz
compcert-kvx-4938c455062ed72a41edaddbf212086efaae7570.zip
goto end
Diffstat (limited to 'test/monniaux/binary_search')
-rw-r--r--test/monniaux/binary_search/binary_search.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/test/monniaux/binary_search/binary_search.c b/test/monniaux/binary_search/binary_search.c
index 8cc6f565..0a69998d 100644
--- a/test/monniaux/binary_search/binary_search.c
+++ b/test/monniaux/binary_search/binary_search.c
@@ -38,6 +38,22 @@ int my_bsearch2 (data *a, index n, data x) {
return -1;
}
+int my_bsearch3 (data *a, index n, data x) {
+ index i = 0, j = n - 1, k;
+ while (i <= j) {
+ k = (i + j) / 2;
+ if (a[k] == x) {
+ goto end;
+ return k;
+ }
+ i = TERNARY32(a[k] < x, k+1, i);
+ j = TERNARY32(a[k] > x, k-1, j);
+ }
+ k=-1;
+ end:
+ return k;
+}
+
void random_ascending_fill(data *a, index n) {
unsigned r = 41;
data v = 0;
@@ -67,12 +83,19 @@ int main () {
index pos2 = my_bsearch2(buf, n, v);
timestamp2 = get_current_cycle()-timestamp2;
+ cycle_t timestamp3 = get_current_cycle();
+ index pos3 = my_bsearch3(buf, n, v);
+ timestamp3 = get_current_cycle()-timestamp3;
+
printf("position1: %d\n"
"position2: %d\n"
+ "position3: %d\n"
"random fill cycles: %" PRIu64 "\n"
"search1 cycles: %" PRIu64 "\n"
- "search2 cycles: %" PRIu64 "\n",
- pos1, pos2, timestamp0, timestamp1, timestamp2);
+ "search2 cycles: %" PRIu64 "\n"
+ "search3 cycles: %" PRIu64 "\n",
+ pos1, pos2, pos3,
+ timestamp0, timestamp1, timestamp2, timestamp3);
free(buf);
}