README.md 11 KB
Newer Older
Cerlane Leong's avatar
Cerlane Leong committed
1
# <img src="https://posithub.org/images/NGA_logo.png"  width="90" height="50"/> SoftPosit
Cerlane Leong's avatar
Cerlane Leong committed
2

Cerlane Leong's avatar
Cerlane Leong committed
3
This version (0.4.1rc) supports:
Cerlane Leong's avatar
Cerlane Leong committed
4

Cerlane Leong's avatar
Cerlane Leong committed
5
    32-bit with two exponent bit (posit32_t).  -> Not exhaustively tested
Cerlane Leong's avatar
Cerlane Leong committed
6

Cerlane Leong's avatar
Cerlane Leong committed
7
    16-bit with one exponent bit (posit16_t). 
Cerlane Leong's avatar
Cerlane Leong committed
8
    
Cerlane Leong's avatar
Cerlane Leong committed
9
    8-bit with zero exponent bit (posit8_t). 
Cerlane Leong's avatar
Cerlane Leong committed
10
    
Cerlane Leong's avatar
Cerlane Leong committed
11
    2-bit to 32-bit with two exponent bits (posit_2_t) -> Not fast : Using 32-bits in the background to store all sizes.
Cerlane Leong's avatar
Cerlane Leong committed
12
        Exhaustively tested for X=(2:32) : pX2_rint, pX2_to_pX2, pX2_to_i32/64, pX2_to_ui32/64, pX2_sqrt, ui/i32_to_pX2
Cerlane Leong's avatar
Cerlane Leong committed
13
        Exhaustively tested for X=(2:13) : ui64_to_pX2, i64_to_pX2
Cerlane Leong's avatar
Cerlane Leong committed
14
        Exhaustively tested for X=(2:20) : pX2_add, pX2_sub, pX2_mul, pX2_div
Cerlane Leong's avatar
Cerlane Leong committed
15
        Exhaustively tested for X=(2:21) : pX2_mul
Cerlane Leong's avatar
Cerlane Leong committed
16
        Exhaustively tested for X=(2:15) : pX2_mulAdd
Cerlane Leong's avatar
Cerlane Leong committed
17
        Exhaustively tested for X=(2:14) : quireX2_fdp_add, quireX2_fdp_sub (using quire32 as the underlying code)
Cerlane Leong's avatar
Cerlane Leong committed
18
    
Cerlane Leong's avatar
Cerlane Leong committed
19
    
Cerlane Leong's avatar
Cerlane Leong committed
20 21 22

This code is tested on 

Cerlane Leong's avatar
Cerlane Leong committed
23 24
* GNU gcc (SUSE Linux) 4.8.5
* Apple LLVM version 9.1.0 (clang-902.0.39.2)
Cerlane Leong's avatar
Cerlane Leong committed
25 26 27
* Windows 10 (Mingw-w64)

Please note that the same Makefile in build/Linux-x86_64-GCC is used for all 3 operating systems.
Cerlane Leong's avatar
Cerlane Leong committed
28

Cerlane Leong's avatar
Cerlane Leong committed
29

Cerlane Leong's avatar
Cerlane Leong committed
30 31
 All posit8_t and posit16_t operations are exhaustively tested with exception of p16_mulAdd and q16_fdp_add/sub operations.
 
Cerlane Leong's avatar
Cerlane Leong committed
32
 **posit32_t operations are still being tested exhaustively for correctness. It will take weeks to months before these tests complete.**
Cerlane Leong's avatar
Cerlane Leong committed
33
 
Cerlane Leong's avatar
Cerlane Leong committed
34

Cerlane Leong's avatar
Cerlane Leong committed
35
 Versions are offered
Cerlane Leong's avatar
Cerlane Leong committed
36
 
Cerlane Leong's avatar
Cerlane Leong committed
37 38 39 40
 * [Fast C version](#cversion) : The main source code where all other versions are based on.
 * [User friendly C++ version](#cppversion)  : Documentation can be found below.
 * [User friendly Python version](https://gitlab.com/cerlane/SoftPosit-Python/) : https://gitlab.com/cerlane/SoftPosit-Python/
 * [Julia](#jversion)  : Currently only simple .so support. Documentation can be found below.
Cerlane Leong's avatar
Cerlane Leong committed
41
 
Cerlane Leong's avatar
Cerlane Leong committed
42

Cerlane Leong's avatar
Cerlane Leong committed
43

Cerlane Leong's avatar
Cerlane Leong committed
44
## <a name="cversion"/>Fast C version 
Cerlane Leong's avatar
Cerlane Leong committed
45

Cerlane Leong's avatar
Cerlane Leong committed
46

Cerlane Leong's avatar
Cerlane Leong committed
47
### Examples
Cerlane Leong's avatar
Cerlane Leong committed
48

Cerlane Leong's avatar
Cerlane Leong committed
49
#### A 8-bit example on how to use the code to add:
Cerlane Leong's avatar
Cerlane Leong committed
50

Cerlane Leong's avatar
Cerlane Leong committed
51

Cerlane Leong's avatar
Cerlane Leong committed
52
```
Cerlane Leong's avatar
Cerlane Leong committed
53 54 55 56 57 58 59 60 61 62
#include "softposit.h"

int main (int argc, char *argv[]){

    posit8_t pA, pB, pZ;
    pA = castP8(0xF2);
    pB = castP8(0x23);

    pZ = p8_add(pA, pB);

Cerlane Leong's avatar
Cerlane Leong committed
63
    //To check answer by converting it to double
Cerlane Leong's avatar
Cerlane Leong committed
64
    double dZ = convertP8ToDouble(pZ);
Cerlane Leong's avatar
Cerlane Leong committed
65
    printf("dZ: %.15f\n", dZ);
Cerlane Leong's avatar
Cerlane Leong committed
66 67

    //To print result in binary
Cerlane Leong's avatar
Cerlane Leong committed
68
    uint8_t uiZ = castUI(pZ);
Cerlane Leong's avatar
Cerlane Leong committed
69
    printBinary((uint64_t*)&uiZ, 8);
Cerlane Leong's avatar
Cerlane Leong committed
70 71
    
    return 0;
Cerlane Leong's avatar
Cerlane Leong committed
72

Cerlane Leong's avatar
Cerlane Leong committed
73
}
Cerlane Leong's avatar
Cerlane Leong committed
74
```
Cerlane Leong's avatar
Cerlane Leong committed
75

Cerlane Leong's avatar
Cerlane Leong committed
76

Cerlane Leong's avatar
Cerlane Leong committed
77
#### A 16-bit example on how to use the code to multiply:
Cerlane Leong's avatar
Cerlane Leong committed
78

Cerlane Leong's avatar
Cerlane Leong committed
79
```
Cerlane Leong's avatar
Cerlane Leong committed
80
#include "softposit.h"
Cerlane Leong's avatar
Cerlane Leong committed
81

Cerlane Leong's avatar
Cerlane Leong committed
82
int main (int argc, char *argv[]){
Cerlane Leong's avatar
Cerlane Leong committed
83

Cerlane Leong's avatar
Cerlane Leong committed
84 85 86 87
    posit16_t pA, pB, pZ;
    pA = castP16(0x0FF2);
    pB = castP16(0x2123);

Cerlane Leong's avatar
Cerlane Leong committed
88
    pZ = p16_mul(pA, pB);
Cerlane Leong's avatar
Cerlane Leong committed
89

Cerlane Leong's avatar
Cerlane Leong committed
90
   //To check answer by converting it to double
Cerlane Leong's avatar
Cerlane Leong committed
91
    double dZ = convertP16ToDouble(pZ);
Cerlane Leong's avatar
Cerlane Leong committed
92
    printf("dZ: %.15f\n", dZ);
Cerlane Leong's avatar
Cerlane Leong committed
93 94

    //To print result in binary
Cerlane Leong's avatar
Cerlane Leong committed
95
    uint16_t uiZ = castUI(pZ);
Cerlane Leong's avatar
Cerlane Leong committed
96 97
    printBinary((uint64_t*)&uiZ, 16);

Cerlane Leong's avatar
Cerlane Leong committed
98
    return 0;
Cerlane Leong's avatar
Cerlane Leong committed
99
}
Cerlane Leong's avatar
Cerlane Leong committed
100 101
```

Cerlane Leong's avatar
Cerlane Leong committed
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
#### A 24-bit (es=2) example on how to use the code:


```
#include "softposit.h"

int main (int argc, char *argv[]){

    posit_2_t pA, pB, pZ;
    pA = {.v = 0xF2}; //this is to set the bits (method 1)
    pB = castPX2(0x23); //this is to set the bits (method 2)

    pZ = pX2_add(pA, pB, 24);

    //To check answer by converting it to double
    double dZ = convertPX2ToDouble(pZ);
    printf("dZ: %.15f\n", dZ);

    //To print result in binary
    printBinaryPX((uint32_t*)&pZ.v, 24);
    
    //To print result as double
    printf("result: %.13f\n", convertPX2ToDouble(pZ));
    
    return 0;

}
```
Cerlane Leong's avatar
Cerlane Leong committed
130

Cerlane Leong's avatar
Cerlane Leong committed
131
#### For deep learning, please use quire.
Cerlane Leong's avatar
Cerlane Leong committed
132

Cerlane Leong's avatar
Cerlane Leong committed
133 134 135

```
//Convert double to posit
Cerlane Leong's avatar
Cerlane Leong committed
136 137 138 139
posit16_t pA = convertDoubleToP16(1.02783203125 );
posit16_t pB = convertDoubleToP16(0.987060546875);
posit16_t pC = convertDoubleToP16(0.4998779296875);
posit16_t pD = convertDoubleToP16(0.8797607421875);
Cerlane Leong's avatar
Cerlane Leong committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

quire16_t qZ;

//Set quire to 0
qZ = q16_clr(qZ);

//accumulate products without roundings
qZ = q16_fdp_add(qZ, pA, pB);
qZ = q16_fdp_add(qZ, pC, pD);

//Convert back to posit
posit16_t pZ = q16_to_p16(qZ);

//To check answer
double dZ = convertP16ToDouble(pZ);
```

Cerlane Leong's avatar
Cerlane Leong committed
157
### Build and link
Cerlane Leong's avatar
Cerlane Leong committed
158

Cerlane Leong's avatar
Cerlane Leong committed
159
#### Build - softposit.a
Cerlane Leong's avatar
Cerlane Leong committed
160

Cerlane Leong's avatar
Cerlane Leong committed
161

Cerlane Leong's avatar
Cerlane Leong committed
162 163
Please note that only 64-bit systems are supported. For Mac OSX and Linux, the same Makefile is used. 

Cerlane Leong's avatar
Cerlane Leong committed
164 165
Note that architecture specific optimisation is removed. To get maximum speed, please update OPTIMISATION flag in build/Linux-x86_64-GCC/Makefile.

Cerlane Leong's avatar
Cerlane Leong committed
166

Cerlane Leong's avatar
Cerlane Leong committed
167
```
Cerlane Leong's avatar
Cerlane Leong committed
168 169 170
cd SoftPosit/build/Linux-x86_64-GCC
make -j6 all

Cerlane Leong's avatar
Cerlane Leong committed
171 172
```

Cerlane Leong's avatar
Cerlane Leong committed
173
#### Link - softposit.a
Cerlane Leong's avatar
Cerlane Leong committed
174

Cerlane Leong's avatar
Cerlane Leong committed
175 176 177 178 179 180

If your source code is for example "main.c" and you want to create an executable "main".
Assume that SoftPosit is installed and installed in the same directory (installing in the same directory is NOT recommended).

```
gcc -lm -o main \
Cerlane Leong's avatar
Cerlane Leong committed
181
    main.c SoftPosit/build/Linux-x86_64-GCC/softposit.a  -ISoftPosit/source/include -O2 
Cerlane Leong's avatar
Cerlane Leong committed
182 183

```
Cerlane Leong's avatar
Cerlane Leong committed
184

Cerlane Leong's avatar
Cerlane Leong committed
185
### Features
Cerlane Leong's avatar
Cerlane Leong committed
186

Cerlane Leong's avatar
Cerlane Leong committed
187

Cerlane Leong's avatar
Cerlane Leong committed
188
#### Main Posit Functionalities:
Cerlane Leong's avatar
Cerlane Leong committed
189

Cerlane Leong's avatar
Cerlane Leong committed
190

Cerlane Leong's avatar
Cerlane Leong committed
191
Add : 
Cerlane Leong's avatar
Cerlane Leong committed
192

Cerlane Leong's avatar
Cerlane Leong committed
193 194 195
     posit16_t p16_add(posit16_t, posit16_t)
     
     posit8_t p8_add(posit8_t, posit8_t)
Cerlane Leong's avatar
Cerlane Leong committed
196

Cerlane Leong's avatar
Cerlane Leong committed
197
Subtract : 
Cerlane Leong's avatar
Cerlane Leong committed
198

Cerlane Leong's avatar
Cerlane Leong committed
199 200 201 202
    posit16_t p16_sub(posit16_t, posit16_t)
    
    posit8_t p8_sub(posit8_t, posit8_t)
    
Cerlane Leong's avatar
Cerlane Leong committed
203

Cerlane Leong's avatar
Cerlane Leong committed
204
Divide : 
Cerlane Leong's avatar
Cerlane Leong committed
205

Cerlane Leong's avatar
Cerlane Leong committed
206 207 208
    posit16_t p16_div(posit16_t, posit16_t)
    
    posit8_t p8_div(posit8_t, posit8_t)
Cerlane Leong's avatar
Cerlane Leong committed
209

Cerlane Leong's avatar
Cerlane Leong committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
Multiply : 

    posit16_t p16_mul(posit16_t, posit16_t)
    
    posit8_t p8_mul(posit8_t, posit8_t)
    

Fused Multiply Add : 
    
    posit16_t p16_mulAdd(posit16_t, posit16_t, posit16_t)
    
    posit8_t p8_mulAdd(posit8_t, posit8_t, posit8_t)
    
    
    Note: p16_mulAdd(a, b, c) <=> a*b + c
Cerlane Leong's avatar
Cerlane Leong committed
225 226


Cerlane Leong's avatar
Cerlane Leong committed
227
#### Main Quire Functionalities
Cerlane Leong's avatar
Cerlane Leong committed
228

Cerlane Leong's avatar
Cerlane Leong committed
229

Cerlane Leong's avatar
Cerlane Leong committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
Fused dot product-add  : 

    quire16_t q16_fdp_add(quire16_t, posit16_t, posit16_t)
    
    quire8_t q16_fdp_add(quire8_t, posit8_t, posit8_t)
    
    Note: q8_fdp_add (a, b, c) <=> a + b*c

Fused dot product-subtract  : 

    quire16_t q16_fdp_sub(quire16_t, posit16_t, posit16_t)
    
    quire8_t q8_fdp_sub(quire8_t, posit8_t, posit8_t)

Set quire variable to zero : 
Cerlane Leong's avatar
Cerlane Leong committed
245

Cerlane Leong's avatar
Cerlane Leong committed
246 247 248
    quire16_t q16_clr(quire16_t)
    
    quire8_t q8_clr(quire8_t)
Cerlane Leong's avatar
Cerlane Leong committed
249

Cerlane Leong's avatar
Cerlane Leong committed
250
Convert quire to posit : 
Cerlane Leong's avatar
Cerlane Leong committed
251

Cerlane Leong's avatar
Cerlane Leong committed
252 253 254
    posit16_t q16_to_p16(quire16_t)
    
    posit8_t q8_to_p8(quire8_t)
Cerlane Leong's avatar
Cerlane Leong committed
255 256


Cerlane Leong's avatar
Cerlane Leong committed
257
#### Functionalites in Posit Standard
Cerlane Leong's avatar
Cerlane Leong committed
258

Cerlane Leong's avatar
Cerlane Leong committed
259

Cerlane Leong's avatar
Cerlane Leong committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
Square root : 

    posit16_t p16_sqrt(posit16_t)
    
    posit8_t p8_sqrt(posit8_t)

Round to nearest integer : 

    posit16_t p16_roundToInt(posit16_t)
    
    posit8_t p8_roundToInt(posit8_t)

Check equal : 

    bool p16_eq( posit16_t, posit16_t )
    
    bool p8_eq( posit8_t, posit8_t )

Check less than equal : 

    bool p16_le( posit16_t, posit16_t )
    
    bool p8_le( posit8_t, posit8_t )

Check less than : 

    bool p16_lt( posit16_t, posit16_t )
    
    bool p8_lt( posit8_t, posit8_t )

Convert posit to integer (32 bits) : 

    int_fast32_t p16_to_i32( posit16_t )
    
    int_fast32_t p8_to_i32( posit8_t )

Convert posit to long long integer (64 bits) : 

    int_fast64_t p16_to_i64( posit16_t)
    
    int_fast64_t p8_to_i64( posit8_t)

Convert unsigned integer (32 bits) to posit: 

    posit16_t ui32_to_p16( uint32_t a )
    
    posit8_t ui32_to_p8( uint32_t a )

Convert unsigned long long int (64 bits) to posit: 

    posit16_t ui64_to_p16( uint64_t a )
    
    posit8_t ui64_to_p8( uint64_t a )

Convert integer (32 bits) to posit: 

    posit16_t i32_to_p16( int32_t a )
    
    posit8_t i32_to_p8( uint32_t a )

Convert long integer (64 bits) to posit: 

    posit16_t i64_to_p16( int64_t a )
    
    posit8_t i64_to_p8( uint64_t a )

Convert posit to unsigned integer (32 bits) : 

    uint_fast32_t p16_to_ui32( posit16_t )
    
    uint_fast32_t p8_to_ui32( posit8_t )

Convert posit to unsigned long long integer (64 bits) : 
Cerlane Leong's avatar
Cerlane Leong committed
333

Cerlane Leong's avatar
Cerlane Leong committed
334 335 336 337 338
    uint_fast64_t p16_to_ui64( posit16_t)
    
    uint_fast64_t p8_to_ui64( posit8_t)
    
Convert posit to integer (32 bits) : 
Cerlane Leong's avatar
Cerlane Leong committed
339

Cerlane Leong's avatar
Cerlane Leong committed
340 341 342
    uint_fast32_t p16_to_i32( posit16_t )
    
    uint_fast32_t p8_to_i32( posit8_t )
Cerlane Leong's avatar
Cerlane Leong committed
343

Cerlane Leong's avatar
Cerlane Leong committed
344
Convert posit to long long integer (64 bits) : 
Cerlane Leong's avatar
Cerlane Leong committed
345

Cerlane Leong's avatar
Cerlane Leong committed
346 347 348
    uint_fast64_t p16_to_i64( posit16_t)
    
    uint_fast64_t p8_to_i64( posit8_t)
Cerlane Leong's avatar
Cerlane Leong committed
349

Cerlane Leong's avatar
Cerlane Leong committed
350
Convert posit to posit of another size : 
Cerlane Leong's avatar
Cerlane Leong committed
351

Cerlane Leong's avatar
Cerlane Leong committed
352 353 354 355 356 357 358
    posit8_t p16_to_p8( posit16_t )
    
    posit32_t p16_to_p32( posit16_t )
    
    posit16_t p8_to_p16( posit8_t )
    
    posit32_t p8_to_p32( posit8_t )
Cerlane Leong's avatar
Cerlane Leong committed
359

360 361


Cerlane Leong's avatar
Cerlane Leong committed
362
#### Helper Functionalites (NOT in Posit Standard)
363

Cerlane Leong's avatar
Cerlane Leong committed
364
Convert posit to double (64 bits) : 
365

Cerlane Leong's avatar
Cerlane Leong committed
366 367 368
    double convertP16ToDouble(posit16_t)
    
    double convertP8ToDouble(posit8_t)
Cerlane Leong's avatar
Cerlane Leong committed
369

Cerlane Leong's avatar
Cerlane Leong committed
370
Convert double (64 bits) to posit  : 
Cerlane Leong's avatar
Cerlane Leong committed
371

Cerlane Leong's avatar
Cerlane Leong committed
372 373 374 375 376
    posit16_t convertDoubleToP16(double)
    
    posit8_t convertDoubleToP8(double)
    
Cast binary expressed in unsigned integer to posit :
Cerlane Leong's avatar
Cerlane Leong committed
377

Cerlane Leong's avatar
Cerlane Leong committed
378 379 380 381 382
    posit16_t castP16(uint16_t)
    
    posit8_t castP8(uint8_t)
    
Cast posit into binary expressed in unsigned integer
Cerlane Leong's avatar
Cerlane Leong committed
383

384
    uint16_t castUI(posit16_t)
Cerlane Leong's avatar
Cerlane Leong committed
385
    
386
    uint8_t castUI(posit8_t)
Cerlane Leong's avatar
Cerlane Leong committed
387
    
Cerlane Leong's avatar
Cerlane Leong committed
388

Cerlane Leong's avatar
Cerlane Leong committed
389
## <a name="cppversion"/>Easy to use C++ version 
Cerlane Leong's avatar
Cerlane Leong committed
390

Cerlane Leong's avatar
Cerlane Leong committed
391

Cerlane Leong's avatar
Cerlane Leong committed
392
### Build and Link
Cerlane Leong's avatar
Cerlane Leong committed
393 394 395

**Build and link your C++ program to SoftPosit.a (C)**

Cerlane Leong's avatar
Cerlane Leong committed
396 397
Please compile your executable with g++ and not gcc.

Cerlane Leong's avatar
Cerlane Leong committed
398 399 400 401 402 403 404
```
g++ -std=gnu++11 -o main \
	../source/testmain.cpp \
	../../SoftPosit/source/../build/Linux-x86_64-GCC/softposit.a  \
	-I../../SoftPosit/source/../build/Linux-x86_64-GCC  -O2
```

Cerlane Leong's avatar
Cerlane Leong committed
405
### Example
Cerlane Leong's avatar
Cerlane Leong committed
406

Cerlane Leong's avatar
Cerlane Leong committed
407
#### Example of testmain.cpp
Cerlane Leong's avatar
Cerlane Leong committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422

```
#include "softposit_cpp.h"

int main(int argc, char *argv[]){
	posit16 x = 1;
	posit16 y = 1.5;
	posit8 x8 = 1;
	quire16 q;
	quire8 q8;

	x += p16(1.5)*5.1;

	printf("%.13f  sizeof: %d\n", x.toDouble(), sizeof(posit16));

Cerlane Leong's avatar
Cerlane Leong committed
423
	x = q.qma(4, 1.2).toPosit();
Cerlane Leong's avatar
Cerlane Leong committed
424 425
	printf("%.13f  sizeof: %d\n", x.toDouble(), sizeof(quire16));

Cerlane Leong's avatar
Cerlane Leong committed
426
	x8 = q8.qma(4, 1.2).toPosit();
Cerlane Leong's avatar
Cerlane Leong committed
427
	printf("%.13f  sizeof: %d\n", x8.toDouble(), sizeof(quire8));
Cerlane Leong's avatar
Cerlane Leong committed
428 429
	
	std::cout << x;
Cerlane Leong's avatar
Cerlane Leong committed
430 431 432 433 434 435 436

	return 0;
}


```

Cerlane Leong's avatar
Cerlane Leong committed
437
### Functionalities
Cerlane Leong's avatar
Cerlane Leong committed
438

Cerlane Leong's avatar
Cerlane Leong committed
439
#### Main functionalities
Cerlane Leong's avatar
Cerlane Leong committed
440 441 442

* Posit types: posit16, posit8
* Fused-multiply-add: 
Cerlane Leong's avatar
Cerlane Leong committed
443 444
  * posit16 fma(posit16, posit16, posit16)
  * posit18 fma(posit18, posit18, posit8)
Cerlane Leong's avatar
Cerlane Leong committed
445
* Square root: 
Cerlane Leong's avatar
Cerlane Leong committed
446 447
  * posit16 sqrt(posit16)
  * posit8 sqrt(posit8)
Cerlane Leong's avatar
Cerlane Leong committed
448
* roundToInt: 
Cerlane Leong's avatar
Cerlane Leong committed
449 450
  * posit16 rint(posit16)
  * posit8 rint(posit8)
Cerlane Leong's avatar
Cerlane Leong committed
451
* Supported operators
Cerlane Leong's avatar
Cerlane Leong committed
452
  * \+
Cerlane Leong's avatar
Cerlane Leong committed
453
  * +=
Cerlane Leong's avatar
Cerlane Leong committed
454 455 456 457
  * \-
  * \-=
  * &ast;
  * &ast;=
Cerlane Leong's avatar
Cerlane Leong committed
458 459 460 461
  * /
  * /=
  * <<
  * <<=
Cerlane Leong's avatar
Cerlane Leong committed
462 463
  * &#62;&#62;
  * &#62;&#62;=
Cerlane Leong's avatar
Cerlane Leong committed
464 465 466 467
  * &
  * &=
  * |
  * |=
Cerlane Leong's avatar
Cerlane Leong committed
468 469
  * ^
  * ^=
Cerlane Leong's avatar
Cerlane Leong committed
470 471 472 473 474
  * &&
  * ||
  * ++
  * --
  * ==
Cerlane Leong's avatar
Cerlane Leong committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
  * ~
  * !
  * !=
  * &ast;
  * <
  * &ast;=
  * <=
* Posit to Double:
  * double (instance of posit).toDouble()
* Double to Posit:
  * posit16 p16(double)
  * posit8 p8(double)
* Posit to NaR:
  * posit16 (instance of posit16).toNaR()
  * posit8 (instance of posit8).toNaR()

#### Quire functionalities (particularly for deep learning)
Cerlane Leong's avatar
Cerlane Leong committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507

* Quire types: quire16, quire8 (when declared, quire is initiated to zero)
* Clear quire to zero: 
   * (instance of quire16).clr()
* Quire multiply add (fused)
   * (instance of quire16).fma(quire16)
   * (instance of quire8).fma(quire8)
* Quire multiply subtract (fused)
   * (instance of quire16).fms(quire16)
   * (instance of quire8).fms(quire8)
* Convert quire to Posit
   * posit16 (instance of quire16).toPosit()
   * posit8 (instance of quire8).toPosit()
* Check if quire is NaR
   * bool (instance of quire).isNaR()
   
Cerlane Leong's avatar
Cerlane Leong committed
508
## <a name="jversion"/>Julia 
Cerlane Leong's avatar
Cerlane Leong committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528

Credits to Milan Klöwer.

### Build shared library

```
cd SoftPosit/build/Linux_x86_64_GCC/
make -j6 julia
```

### Simple Tests

```
julia> t = ccall((:convertDoubleToP16, "/path/to/SoftPosit/build/Linux-x86_64-GCC/softposit.so"), UInt16, (Float64,),1.0)
0x4000

julia> t = ccall((:convertDoubleToP16, "/path/to/SoftPosit/build/Linux-x86_64-GCC/softposit.so"), UInt16, (Float64,),-1.0)
0xc000

```
Cerlane Leong's avatar
Cerlane Leong committed
529
   
Cerlane Leong's avatar
Cerlane Leong committed
530