1 from libc.stdint cimport *
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
9 cdef extern from '../SoftPosit/source/include/softposit.h':
11 # Transparent types so we can have access to the raw bits.
15 ctypedef struct posit8_t:
19 ctypedef struct quire8_t:
23 ctypedef struct posit16_t:
27 ctypedef struct quire16_t:
31 ctypedef struct posit32_t:
35 ctypedef struct quire32_t:
41 ctypedef struct posit8_t:
44 ctypedef struct posit16_t:
47 ctypedef struct posit32_t:
50 ctypedef struct quire8_t:
53 ctypedef struct quire16_t:
56 ctypedef struct quire32_t:
59 # /*----------------------------------------------------------------------------
60 # | Integer-to-posit conversion routines.
61 # *----------------------------------------------------------------------------*/
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 );
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 );
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 );
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 );
83 # /*----------------------------------------------------------------------------
84 # | 8-bit (quad-precision) posit operations.
85 # *----------------------------------------------------------------------------*/
87 bint isNaRP8UI( uint8_t );
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 );
94 posit16_t p8_to_p16( posit8_t );
95 # posit32_t p8_to_p32( posit8_t );
96 # posit64_t p8_to_p64( posit8_t );
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 );
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 );
114 bint isNaRQ8( quire8_t );
115 bint isQ8Zero( quire8_t );
116 quire8_t q8_clr( quire8_t );
117 quire8_t castQ8( uint32_t );
118 posit8_t castP8( uint8_t );
119 uint8_t castUI8( posit8_t );
120 posit8_t negP8( posit8_t );
123 double convertP8ToDouble( posit8_t );
124 posit8_t convertDoubleToP8( double );
126 # /*----------------------------------------------------------------------------
127 # | 16-bit (half-precision) posit operations.
128 # *----------------------------------------------------------------------------*/
130 bint isNaRP16UI( uint16_t );
132 uint_fast32_t p16_to_ui32( posit16_t );
133 uint_fast64_t p16_to_ui64( posit16_t );
134 int_fast32_t p16_to_i32( posit16_t);
135 int_fast64_t p16_to_i64( posit16_t );
136 posit8_t p16_to_p8( posit16_t );
137 # posit32_t p16_to_p32( posit16_t );
138 # posit64_t p16_to_p64( posit16_t );
140 posit16_t p16_roundToInt( posit16_t);
141 posit16_t p16_add( posit16_t, posit16_t );
142 posit16_t p16_sub( posit16_t, posit16_t );
143 posit16_t p16_mul( posit16_t, posit16_t );
144 posit16_t p16_mulAdd( posit16_t, posit16_t, posit16_t );
145 posit16_t p16_div( posit16_t, posit16_t );
146 posit16_t p16_sqrt( posit16_t );
147 bint p16_eq( posit16_t, posit16_t );
148 bint p16_le( posit16_t, posit16_t );
149 bint p16_lt( posit16_t, posit16_t );
152 quire16_t q16_fdp_add( quire16_t, posit16_t, posit16_t );
153 quire16_t q16_fdp_sub( quire16_t, posit16_t, posit16_t );
154 # posit16_t convertQ16ToP16( quire16_t );
155 posit16_t q16_to_p16( quire16_t );
157 bint isNaRQ16( quire16_t );
158 bint isQ16Zero( quire16_t );
159 # quire16_t q16_TwosComplement( quire16_t );
161 # void printBinary( uint64_t*, int );
162 # void printHex( uint64_t );
164 quire16_t q16_clr( quire16_t );
165 quire16_t castQ16( uint16_t, uint16_t );
166 posit16_t castP16( uint16_t );
167 uint16_t castUI16( posit16_t );
168 posit16_t negP16( posit16_t );
171 double convertP16ToDouble( posit16_t );
172 # posit16_t convertFloatToP16( float );
173 posit16_t convertDoubleToP16( double );