Skip to content

Commit 1d9d6d0

Browse files
committed
Remove fixed point math [skip ci]
1 parent b9313c6 commit 1d9d6d0

File tree

1 file changed

+1
-68
lines changed

1 file changed

+1
-68
lines changed

src/bench.h

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -34,67 +34,6 @@ static int64_t gettime_i64(void) {
3434
#endif
3535
}
3636

37-
#define FP_EXP (6)
38-
#define FP_MULT (1000000LL)
39-
40-
/* Format fixed point number. */
41-
static void print_number(const int64_t x) {
42-
int64_t x_abs, y;
43-
int c, i, rounding, g; /* g = integer part size, c = fractional part size */
44-
size_t ptr;
45-
char buffer[30];
46-
47-
if (x == INT64_MIN) {
48-
/* Prevent UB. */
49-
printf("ERR");
50-
return;
51-
}
52-
x_abs = x < 0 ? -x : x;
53-
54-
/* Determine how many decimals we want to show (more than FP_EXP makes no
55-
* sense). */
56-
y = x_abs;
57-
c = 0;
58-
while (y > 0LL && y < 100LL * FP_MULT && c < FP_EXP) {
59-
y *= 10LL;
60-
c++;
61-
}
62-
63-
/* Round to 'c' decimals. */
64-
y = x_abs;
65-
rounding = 0;
66-
for (i = c; i < FP_EXP; ++i) {
67-
rounding = (y % 10) >= 5;
68-
y /= 10;
69-
}
70-
y += rounding;
71-
72-
/* Format and print the number. */
73-
ptr = sizeof(buffer) - 1;
74-
buffer[ptr] = 0;
75-
g = 0;
76-
if (c != 0) { /* non zero fractional part */
77-
for (i = 0; i < c; ++i) {
78-
buffer[--ptr] = '0' + (y % 10);
79-
y /= 10;
80-
}
81-
} else if (c == 0) { /* fractional part is 0 */
82-
buffer[--ptr] = '0';
83-
}
84-
buffer[--ptr] = '.';
85-
do {
86-
buffer[--ptr] = '0' + (y % 10);
87-
y /= 10;
88-
g++;
89-
} while (y != 0);
90-
if (x < 0) {
91-
buffer[--ptr] = '-';
92-
g++;
93-
}
94-
printf("%5.*s", g, &buffer[ptr]); /* Prints integer part */
95-
printf("%-*s", FP_EXP, &buffer[ptr + g]); /* Prints fractional part */
96-
}
97-
9837
static void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void*), void (*teardown)(void*, int), void* data, int count, int iter) {
9938
int i;
10039
int64_t min = INT64_MAX;
@@ -120,13 +59,7 @@ static void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setu
12059
sum += total;
12160
}
12261
/* ',' is used as a column delimiter */
123-
printf("%-30s, ", name);
124-
print_number(min * FP_MULT / iter);
125-
printf(" , ");
126-
print_number(((sum * FP_MULT) / count) / iter);
127-
printf(" , ");
128-
print_number(max * FP_MULT / iter);
129-
printf("\n");
62+
printf("%-30s, %.2f, %.2f, %.2f\n\n", name, (double)min / iter, (double)sum / count / iter, (double)max / iter);
13063
}
13164

13265
static int have_flag(int argc, char** argv, char *flag) {

0 commit comments

Comments
 (0)