aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/cfrac/pdefs.h
blob: 9c430991691f5ab4530e997aaf9b45892127bcee (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * +------------------------------------------------------------------+
 * |	     Private Math Library Definitions			      |
 * +------------------------------------------------------------------+
 */
/*
 * Optional assembly language
 */
#ifdef ASM
#include "machineop.h"		/* 16-bit integer machine operations */
#define uModDiv(n, d, qp)	umoddiv16(n, d, qp)   /* slight help */
#else
#define uModDiv(n, d, qp)	(*(qp) = (n) / (d), (n) % (d))
#endif
#define uMul(u, v)		((u) * (v))	      /* fast enough */

/*
 * Optional alternate memory allocator
 */

#ifndef MYALLOC

#    if defined(BWGC)
extern char *gc_malloc_atomic();
#define allocate(size)	(char *) gc_malloc_atomic(size)
#    elif defined(CUSTOM_MALLOC)
#define allocate(size)	CUSTOM_MALLOC(size)
#    else
/* extern char *malloc(); */
#define allocate(size)	(char *) malloc(size)
#    endif

#ifdef IGNOREFREE
#define deallocate(p)	{};
#    elif defined(CUSTOM_FREE)
#define deallocate(p)	CUSTOM_FREE(p)
#else
/*
extern int  free();
*/
#define deallocate(p)	free(p)
#endif

#else
extern char  *allocate();
extern void  deallocate();
#endif

/*
 * These next four types are used only used in this include file
 */
#include <stdint.h>
typedef	unsigned char	u8;				  /*  8 bits */
typedef uint16_t	u16;				  /* 16 bits */
typedef uint32_t	u32;			  	  /* 32 bits */
typedef u8           	boolean;		          /*  1 bit  */

#define BASE	  	65536		/* Base * (Base-1) <= MAXINT */

/*
 * Operations on Base (unsigned math)
 */
#define modBase(u)	((u) & 0xffff)		/* remainder on Base */
#define divBase(u)	((u) >> 16)		/* divide    by Base */
#define mulBase(u)	((u) << 16)		/* multiply  by Base */

/*
 * The type of a variable used to store intermediate results.
 * This should be the most efficient unsigned int on your machine.
 */
typedef u32		accumulator;	     /* 0..(Base * Base) - 1 */

/*
 * The type of a single digit
 */
typedef u16      	digit;				/* 0..Base-1 */

/*
 * The type of a digit index (the largest number of digits - 1)
 * Determines the maximum representable precision (not usually changed)
 */
typedef u16      	posit;				 /* 0..size  */

typedef unsigned short	prefc;			/* in precision.h also */
/*
 * End of area which needs to be modified
 */

#define false     	0
#define true	  	1

typedef digit	      	digitString[1];	 	 /* dummy array type */
typedef digit     	*digitPtr;

/*
 * A normalized integer has the following attributes:
 *   -0 cannot occur
 *   all digits >= size assumed to be 0.  (no leading zero's)
 *   size > 0
 */
typedef struct {
#ifndef BWGC
    prefc 	refcount;	/* reference count (must be 1st [for pref]) */
#endif
    posit	alloc;		/* allocated size      */
    posit       size;	 	/* number of digits    */
    boolean     sign;		/* sign: TRUE negative */
    digitString value;
} precisionType;

typedef precisionType	*precision;

/*
 * Overlay for cache of precisions
 */
typedef struct {
   precision 	next;		/* next item in list */
   short	count;		/* number of items in this sublist */
} cacheType;

typedef cacheType	*cachePtr;
/*
 * Maximum total memory consumed by cache =
 *    LIMIT * (1 + SIZE * (PrecisionSize + sizeof(digit) * (SIZE-1) / 2))
 */
#ifndef CACHESIZE
#define CACHESIZE	32 		/* size of allocation cache */
#endif
#define CACHELIMIT	128 		/* Determines max mem used by cache */

#define PrecisionSize	(sizeof(precisionType) - sizeof(digitString))

/*
 * Function definitions are all in the global include file "mathdefs.h".
 */
extern precision 	palloc();	/* semi-private */
extern int 		pfree();	/* semi-private */
extern void 		pnorm();	/* semi-private */