-
Notifications
You must be signed in to change notification settings - Fork 0
/
fp-precision.c
45 lines (36 loc) · 991 Bytes
/
fp-precision.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Counters for fp operation with variable precision */
#include <stdio.h>
#include <stdint.h>
#include <strings.h>
#include <sys/types.h>
#include "fp-soft-variable.h"
#define MAX32PRECISION 24
unsigned int fp_precision = MAX32PRECISION-1;
#define COUNTFOROPERATOR(operator) \
long long fp##operator##_count[MAX32PRECISION]; \
void fpInc##operator() { fp##operator##_count[fp_precision]++;} \
long long fpGet##operator##Count (int index){return fp##operator##_count[index];}
COUNTFOROPERATOR (sub);
COUNTFOROPERATOR (add);
COUNTFOROPERATOR (mul);
#undef COUNTFOROPERATOR
long long fpGetFmulCount (int index)
{
return fpmul_count[index];
}
void fpSetPrecision (int mantissa_bits)
{
fp_precision = mantissa_bits;
}
int fpGetPrecision()
{
return fp_precision;
}
void fpInitCount()
{
#define BZOPERATOR(operator) bzero(fp##operator##_count, MAX32PRECISION*sizeof (long long));
BZOPERATOR (add);
BZOPERATOR (sub);
BZOPERATOR (mul);
#undef BZOPERATOR
}