Skip to content

Commit 3dc9ba9

Browse files
committed
formatting
1 parent 89a9a92 commit 3dc9ba9

21 files changed

+38
-1682
lines changed

benchrunner/cxx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ $(OUT): $(OBJFILES)
5454
$(CC) $(CFLAGS) -c -o $@ $^
5555

5656
clean:
57-
rm -f $(OUT)
57+
rm -f $(OUT) *.o
5858

5959
.PHONY: clean

benchrunner/cxx/benchmarks.h

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,17 @@
44
#include <stdlib.h>
55
#include <stdint.h>
66
#include <iostream>
7+
#include <chrono>
78

89
// Copied from stdlib.h for reference.
910
typedef int (*__compar_fn_t) (const void *, const void *);
1011

1112
// Sorting algorithms.
12-
void *insertionsort_glibc(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
13-
void insertionsort_glibc_inplace(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
14-
void *insertionsort_copy(void *const pbase, size_t total_elems, size_t size);
15-
void *insertionsort_cmp(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
16-
void insertionsort_inplace_cmp(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
1713
template<typename T> T *insertionsort_inplace(T *pbase, size_t total_elems);
18-
void *quicksort_glibc(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
19-
void quicksort_glibc_inplace(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
20-
void *quicksort_cmp(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
21-
void *quicksort(void *const pbase, size_t total_elems, size_t size);
22-
void quicksort_inplace_cmp(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
2314
template<typename T> T *quicksort_inplace(T *_a, size_t n);
24-
void *smergesort(void *const pbase, size_t total_elems, size_t size);
25-
void *smergesort_cmp(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
26-
void *mergesort_par(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
27-
void *cilksort(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
28-
void *cilksort_par(void *const pbase, size_t total_elems, size_t size, __compar_fn_t cmp);
2915
template <typename T> T *bottomUpMergeSort(T *a, T *b, int n);
16+
template <typename T> void bottomUpMerge(T *a, int left, int right, int end, T *b);
17+
template <typename T> void copyArray(T *b, T* a, int n);
3018

3119
// Relating to C++ templatized versions
3220
extern "C" {
@@ -36,15 +24,6 @@ extern int64_t *quicksort_cxx_int(int64_t *pbase, size_t total_elems);
3624
}
3725

3826
// Microbenchmarks.
39-
int64_t* __attribute__ ((noinline)) fill_array_seq(size_t total_elems, int64_t val);
40-
int64_t* __attribute__ ((noinline)) fill_array_par(size_t total_elems, int64_t val);
4127
int64_t* __attribute__ ((noinline)) fill_array_rand_seq(size_t total_elems);
42-
int64_t* __attribute__ ((noinline)) fill_array_ones_seq(size_t total_elems);
43-
int64_t __attribute__ ((noinline)) sum_array_seq(size_t total_elems, int64_t *nums);
44-
int64_t __attribute__ ((noinline)) sum_array_par(size_t total_elems, int64_t *nums);
45-
void __attribute__ ((noinline)) copy_seq(void *dst, void *src, size_t nbytes);
46-
void __attribute__ ((noinline)) copy_par(void *dst, void *src, size_t nbytes);
47-
int64_t fib(int64_t n);
48-
int64_t fib_par(int64_t n);
4928

5029
#endif

benchrunner/cxx/cbench.h

Lines changed: 0 additions & 128 deletions
This file was deleted.

benchrunner/cxx/helpers.h

Lines changed: 11 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -10,144 +10,20 @@
1010
#include <time.h>
1111
#include <assert.h>
1212

13-
#ifndef HAVE_GLIBC_COMPAR_FN_T
14-
typedef int (*__compar_fn_t)(const void *, const void *);
15-
#endif
16-
17-
// -----------------------------------------------------------------------------
18-
19-
static inline int compare_int64s(const void* a, const void* b);
20-
21-
static inline int compare_int64s(const void* a, const void* b)
22-
{
23-
int64_t arg1 = *(const int64_t*)a;
24-
int64_t arg2 = *(const int64_t*)b;
25-
26-
if (arg1 < arg2) return -1;
27-
if (arg1 > arg2) return 1;
28-
return 0;
29-
}
30-
31-
32-
static inline double difftimespecs(struct timespec* t0, struct timespec* t1)
33-
{
34-
return (double)(t1->tv_sec - t0->tv_sec)
35-
+ ((double)(t1->tv_nsec - t0->tv_nsec) / 1000000000.0);
36-
}
37-
38-
static inline bool prefix(const char *pre, const char *str)
39-
{
40-
return strncmp(pre, str, strlen(pre)) == 0;
41-
}
42-
43-
static inline void our_memcpy(void *dst, void *src, size_t nbytes)
44-
{
45-
memcpy(dst, src, nbytes);
46-
}
47-
48-
// Taken from glibc.
49-
static inline void SWAP(void *a, void *b, size_t elt_size)
50-
{
51-
size_t __size = elt_size;
52-
char *__a = (char*)a;
53-
char *__b = (char*)b;
54-
do {
55-
char __tmp = * __a;
56-
*__a++ = *__b;
57-
*__b++ = __tmp;
58-
} while (--__size > 0);
59-
}
60-
61-
template<typename T>
62-
static inline void SWAP2(T *a, int i, int j)
63-
{
64-
T _tmp = a[i];
65-
a[i] = a[j];
66-
a[j] = _tmp;
67-
}
68-
69-
// -----------------------------------------------------------------------------
70-
71-
typedef struct slice_t_ {
72-
void *base;
73-
size_t total_elems;
74-
size_t elt_size;
75-
} slice_t;
76-
77-
typedef struct slice_prod_t_ {
78-
slice_t left;
79-
slice_t right;
80-
} slice_prod_t;
81-
82-
static inline size_t slice_length(const slice_t *sl)
13+
int64_t* __attribute__ ((noinline)) fill_array_rand_seq(size_t total_elems)
8314
{
84-
return sl->total_elems;
85-
}
86-
87-
static inline void *slice_nth(const slice_t *sl, size_t n)
88-
{
89-
return (char*) sl->base + (n * sl->elt_size);
90-
}
91-
92-
static inline void slice_copy(slice_t *src, slice_t *dst)
93-
{
94-
our_memcpy(dst->base, src->base, (src->total_elems * src->elt_size));
95-
return;
96-
}
97-
98-
static inline void slice_inplace_update(slice_t *sl, size_t i, void* elt) {
99-
void* dst = slice_nth(sl, i);
100-
our_memcpy(dst, elt, sl->elt_size);
101-
}
102-
103-
// "idx" is the start index, "elems" is the length of the new slice.
104-
static inline slice_t slice_narrow(const slice_t *sl, size_t idx, size_t elems)
105-
{
106-
return (slice_t) { (char*) sl->base + (sl->elt_size * idx), elems, sl->elt_size };
107-
}
108-
109-
static inline slice_prod_t slice_split_at(const slice_t *sl, size_t idx)
110-
{
111-
/*
112-
slice_t left = (slice_t) { sl->base, idx, sl->elt_size };
113-
slice_t right = (slice_t) { (char*) sl->base + (sl->elt_size * idx),
114-
(sl->total_elems - idx),
115-
sl->elt_size };
116-
*/
117-
size_t len = slice_length(sl);
118-
slice_t left = slice_narrow(sl, 0, idx);
119-
slice_t right = slice_narrow(sl, idx, len-idx);
120-
return (slice_prod_t) { left, right };
121-
}
122-
123-
static inline void slice_print(const slice_t *sl)
124-
{
125-
printf("[");
126-
char *elt;
127-
for (size_t i = 0; i < sl->total_elems; i++) {
128-
elt = (char*) sl->base + (i * sl->elt_size);
129-
if (sl->elt_size == sizeof(int64_t)) {
130-
printf("%ld, ", *(int64_t*) elt);
131-
} else {
132-
printf("%p, ", (void*) elt);
133-
}
15+
void *nums;
16+
nums = (int64_t*) malloc(total_elems * sizeof(int64_t));
17+
if (nums == NULL) {
18+
fprintf(stderr, "Couldn't allocate memory for output array.\n");
19+
return NULL;
13420
}
135-
printf("]\n");
136-
}
137-
138-
static inline void slice_assert_sorted(__compar_fn_t cmp, const slice_t *sl)
139-
{
140-
size_t len = slice_length(sl);
141-
void *a, *b;
142-
for (size_t i = 0; i < len-1; i++) {
143-
a = slice_nth(sl, i);
144-
b = slice_nth(sl, i+1);
145-
if ((*cmp)(a,b) > 0) {
146-
fprintf(stderr, "Elements at %zu and %zu are not sorted.", i, i+1);
147-
exit(1);
148-
}
21+
int64_t *elt = (int64_t *) nums;
22+
for (uint64_t i = 0; i <= total_elems-1; i++) {
23+
elt = (int64_t*) nums + i;
24+
*elt = rand();
14925
}
150-
printf("Sorted: OK\n");
26+
return (int64_t *) nums;
15127
}
15228

15329
static inline void slice_assert_sorted_2(int64_t *arr, int size)

0 commit comments

Comments
 (0)