don't use quire clear macros, hopefully for windows compatibility
[sfpy.git] / sfpy / cposit.pxd
1 from libc.stdint cimport *
2
3 # As far as I can tell, this is never enabled when the library is comiled...
4 # The option will have to be synced manually, as by the time Cython's c is
5 # compiled the library will already be stored as a .a file and any compile-time
6 # options used to build it will be long gone.
7 DEF SOFTPOSIT_EXACT = 0
8
9 cdef extern from '../SoftPosit/source/include/softposit.h':
10
11 # Transparent types so we can have access to the raw bits.
12
13 IF SOFTPOSIT_EXACT:
14
15 ctypedef struct posit8_t:
16 uint8_t v;
17 bint exact;
18
19 ctypedef struct quire8_t:
20 uint32_t v;
21 bint exact;
22
23 ctypedef struct posit16_t:
24 uint16_t v;
25 bint exact;
26
27 ctypedef struct quire16_t:
28 uint64_t v[2];
29 bint exact;
30
31 ctypedef struct posit32_t:
32 uint32_t v;
33 bint exact;
34
35 ctypedef struct quire32_t:
36 uint64_t v[8];
37 bint exact;
38
39 ELSE:
40
41 ctypedef struct posit8_t:
42 uint8_t v;
43
44 ctypedef struct posit16_t:
45 uint16_t v;
46
47 ctypedef struct posit32_t:
48 uint32_t v;
49
50 ctypedef struct quire8_t:
51 uint32_t v;
52
53 ctypedef struct quire16_t:
54 uint64_t v[2];
55
56 ctypedef struct quire32_t:
57 uint64_t v[8];
58
59 # /*----------------------------------------------------------------------------
60 # | Integer-to-posit conversion routines.
61 # *----------------------------------------------------------------------------*/
62
63 posit8_t ui32_to_p8( uint32_t );
64 posit16_t ui32_to_p16( uint32_t );
65 posit32_t ui32_to_p32( uint32_t );
66 # posit64_t ui32_to_p64( uint32_t );
67
68 posit8_t ui64_to_p8( uint64_t );
69 posit16_t ui64_to_p16( uint64_t );
70 posit32_t ui64_to_p32( uint64_t );
71 # posit64_t ui64_to_p64( uint64_t );
72
73 posit8_t i32_to_p8( int32_t );
74 posit16_t i32_to_p16( int32_t );
75 posit32_t i32_to_p32( int32_t );
76 # posit64_t i32_to_p64( int32_t );
77
78 posit8_t i64_to_p8( int64_t );
79 posit16_t i64_to_p16( int64_t );
80 posit32_t i64_to_p32( int64_t );
81 # posit64_t i64_to_p64( int64_t );
82
83 # /*----------------------------------------------------------------------------
84 # | 8-bit (quad-precision) posit operations.
85 # *----------------------------------------------------------------------------*/
86
87 bint isNaRP8UI( uint8_t );
88
89 uint_fast32_t p8_to_ui32( posit8_t );
90 uint_fast64_t p8_to_ui64( posit8_t );
91 int_fast32_t p8_to_i32( posit8_t );
92 int_fast64_t p8_to_i64( posit8_t );
93
94 posit16_t p8_to_p16( posit8_t );
95 posit32_t p8_to_p32( posit8_t );
96 # posit64_t p8_to_p64( posit8_t );
97
98 posit8_t p8_roundToInt( posit8_t );
99 posit8_t p8_add( posit8_t, posit8_t );
100 posit8_t p8_sub( posit8_t, posit8_t );
101 posit8_t p8_mul( posit8_t, posit8_t );
102 posit8_t p8_mulAdd( posit8_t, posit8_t, posit8_t );
103 posit8_t p8_div( posit8_t, posit8_t );
104 posit8_t p8_sqrt( posit8_t );
105 bint p8_eq( posit8_t, posit8_t );
106 bint p8_le( posit8_t, posit8_t );
107 bint p8_lt( posit8_t, posit8_t );
108
109 # Quire 8
110 quire8_t q8_fdp_add( quire8_t, posit8_t, posit8_t );
111 quire8_t q8_fdp_sub( quire8_t, posit8_t, posit8_t );
112 posit8_t q8_to_p8( quire8_t );
113
114 bint isNaRQ8( quire8_t );
115 bint isQ8Zero( quire8_t );
116 #quire8_t q8_clr( quire8_t );
117 quire8_t q8Clr();
118 quire8_t castQ8( uint32_t );
119 posit8_t castP8( uint8_t );
120 uint8_t castUI8( posit8_t );
121 posit8_t negP8( posit8_t );
122
123 # Helper
124 double convertP8ToDouble( posit8_t );
125 posit8_t convertDoubleToP8( double );
126
127 # /*----------------------------------------------------------------------------
128 # | 16-bit (half-precision) posit operations.
129 # *----------------------------------------------------------------------------*/
130
131 bint isNaRP16UI( uint16_t );
132
133 uint_fast32_t p16_to_ui32( posit16_t );
134 uint_fast64_t p16_to_ui64( posit16_t );
135 int_fast32_t p16_to_i32( posit16_t);
136 int_fast64_t p16_to_i64( posit16_t );
137 posit8_t p16_to_p8( posit16_t );
138 posit32_t p16_to_p32( posit16_t );
139 # posit64_t p16_to_p64( posit16_t );
140
141 posit16_t p16_roundToInt( posit16_t);
142 posit16_t p16_add( posit16_t, posit16_t );
143 posit16_t p16_sub( posit16_t, posit16_t );
144 posit16_t p16_mul( posit16_t, posit16_t );
145 posit16_t p16_mulAdd( posit16_t, posit16_t, posit16_t );
146 posit16_t p16_div( posit16_t, posit16_t );
147 posit16_t p16_sqrt( posit16_t );
148 bint p16_eq( posit16_t, posit16_t );
149 bint p16_le( posit16_t, posit16_t );
150 bint p16_lt( posit16_t, posit16_t );
151
152 # Quire 16
153 quire16_t q16_fdp_add( quire16_t, posit16_t, posit16_t );
154 quire16_t q16_fdp_sub( quire16_t, posit16_t, posit16_t );
155 # posit16_t convertQ16ToP16( quire16_t );
156 posit16_t q16_to_p16( quire16_t );
157
158 bint isNaRQ16( quire16_t );
159 bint isQ16Zero( quire16_t );
160 quire16_t q16_TwosComplement( quire16_t );
161
162 # void printBinary( uint64_t*, int );
163 # void printHex( uint64_t );
164
165 #quire16_t q16_clr( quire16_t );
166 quire16_t q16Clr();
167 quire16_t castQ16( uint16_t, uint16_t );
168 posit16_t castP16( uint16_t );
169 uint16_t castUI16( posit16_t );
170 posit16_t negP16( posit16_t );
171
172 # Helper
173 double convertP16ToDouble( posit16_t );
174 # posit16_t convertFloatToP16( float );
175 posit16_t convertDoubleToP16( double );
176
177 # /*----------------------------------------------------------------------------
178 # | 32-bit (single-precision) posit operations.
179 # *----------------------------------------------------------------------------*/
180
181 bint isNaRP32UI( posit32_t );
182
183 uint_fast32_t p32_to_ui32( posit32_t );
184 uint_fast64_t p32_to_ui64( posit32_t);
185 int_fast32_t p32_to_i32( posit32_t );
186 int_fast64_t p32_to_i64( posit32_t );
187 posit8_t p32_to_p8( posit32_t );
188 posit16_t p32_to_p16( posit32_t );
189 # posit64_t p32_to_p64( posit32_t );
190
191 posit32_t p32_roundToInt( posit32_t );
192 posit32_t p32_add( posit32_t, posit32_t );
193 posit32_t p32_sub( posit32_t, posit32_t );
194 posit32_t p32_mul( posit32_t, posit32_t );
195 posit32_t p32_mulAdd( posit32_t, posit32_t, posit32_t );
196 posit32_t p32_div( posit32_t, posit32_t );
197 posit32_t p32_sqrt( posit32_t );
198 bint p32_eq( posit32_t, posit32_t );
199 bint p32_le( posit32_t, posit32_t );
200 bint p32_lt( posit32_t, posit32_t );
201
202 quire32_t q32_fdp_add( quire32_t, posit32_t, posit32_t );
203 quire32_t q32_fdp_sub( quire32_t, posit32_t, posit32_t );
204 posit32_t q32_to_p32( quire32_t );
205
206 bint isNaRQ32( quire32_t );
207 bint isQ32Zero( quire32_t );
208 quire32_t q32_TwosComplement( quire32_t );
209 #quire32_t q32_clr( quire32_t );
210 quire32_t q32Clr();
211 quire32_t castQ32( uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t );
212 posit32_t castP32( uint32_t );
213 posit32_t negP32( posit32_t );
214
215 # Helper
216 double convertP32ToDouble( posit32_t );
217 # posit32_t convertFloatToP32(float);
218 posit32_t convertDoubleToP32( double );