|
|
SoftPosit is based on Berkeley SoftFloat Release 3d to enable software comparison between posits and floats.
|
|
|
|
|
|
Version 0.2 it contains all functions in the expected Posit Standard for 16-bit posit with es=1 (posit16_t).
|
|
|
Version 0.2 it contains all functions in the expected Posit Standard for 16-bit posit with es=1 (posit16_t) and 8-bit posit with es=0 (posit8_t).
|
|
|
|
|
|
|
|
|
**Installation**
|
|
|
|
|
|
cd SoftPosit/build/Linux-x86_64-GCC
|
|
|
|
|
|
make all
|
|
|
make -j6 all
|
|
|
|
|
|
|
|
|
Please link to the archive (softposit.a) to use.
|
... | ... | @@ -20,91 +20,227 @@ Release v0.1 supports 16-bit posit with one exponent bit (posit16_t). This code |
|
|
|
|
|
An example on how to use the code to add:
|
|
|
|
|
|
`union ui16_p16 uA, uB, uZ;`
|
|
|
```
|
|
|
#include "softposit.h"
|
|
|
|
|
|
`uA.ui = 0x42;`
|
|
|
int main (int argc, char *argv[]){
|
|
|
|
|
|
`uB.ui = 0x23;`
|
|
|
|
|
|
`uZ.p = p16_add(uA.p, uB.p);`
|
|
|
|
|
|
`//To check answer`
|
|
|
posit16_t pA, pB, pZ;
|
|
|
pA = castP16(0x0FF2);
|
|
|
pB = castP16(0x2123);
|
|
|
|
|
|
`double dZ = convertP16ToDec_f(uZ.p);`
|
|
|
pZ = p8_mul(pA, pB);
|
|
|
|
|
|
`//To print result in binary`
|
|
|
//To check answer
|
|
|
double dZ = convertP16ToDouble(pZ);
|
|
|
|
|
|
`printBinary(&uZ.ui, 16);`
|
|
|
//To print result in binary
|
|
|
uint16_t uiZ = castUI16(pZ);
|
|
|
printBinary(&uiZ, 16);
|
|
|
|
|
|
|
|
|
**Features**
|
|
|
return 0;
|
|
|
}
|
|
|
```
|
|
|
------------------------------------------
|
|
|
|
|
|
Main Posit Functionalities:
|
|
|
1. Add
|
|
|
`posit16_t p16_add(posit16_t, posit_16)`
|
|
|
|
|
|
2. Subtract
|
|
|
`posit16_t p16_sub(posit16_t, posit_16)`
|
|
|
------------------------------------------
|
|
|
|
|
|
Add :
|
|
|
|
|
|
posit16_t p16_add(posit16_t, posit16_t)
|
|
|
|
|
|
posit8_t p8_add(posit8_t, posit8_t)
|
|
|
|
|
|
Subtract :
|
|
|
|
|
|
posit16_t p16_sub(posit16_t, posit16_t)
|
|
|
|
|
|
posit8_t p8_sub(posit8_t, posit8_t)
|
|
|
|
|
|
|
|
|
3. Divide
|
|
|
`posit16_t p16_div(posit16_t, posit_16)`
|
|
|
Divide :
|
|
|
|
|
|
4. Multiply
|
|
|
`posit16_t p16_mul(posit16_t, posit_16)`
|
|
|
posit16_t p16_div(posit16_t, posit16_t)
|
|
|
|
|
|
posit8_t p8_div(posit8_t, posit8_t)
|
|
|
|
|
|
5. Fused Multiply Add
|
|
|
`posit16_t p16_mulAdd(posit16_t, posit_16, posit_16)`
|
|
|
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
|
|
|
|
|
|
`p16_mulAdd(a, b, c) <=> a*b + c`
|
|
|
|
|
|
Main Quire Functionalities
|
|
|
------------------------------------------
|
|
|
|
|
|
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 :
|
|
|
|
|
|
quire16_t q16_clr(quire16_t)
|
|
|
|
|
|
quire8_t q8_clr(quire8_t)
|
|
|
|
|
|
Convert quire to posit :
|
|
|
|
|
|
posit16_t q16_to_p16(quire16_t)
|
|
|
|
|
|
posit8_t q8_to_p8(quire8_t)
|
|
|
|
|
|
|
|
|
Functionalites in Posit Standard
|
|
|
------------------------------------------
|
|
|
|
|
|
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) :
|
|
|
|
|
|
1. Fused dot product-add
|
|
|
`quire16_t q16_fdp_add(quire16_t, posit_16, posit_16)`
|
|
|
uint_fast32_t p16_to_ui32( posit16_t )
|
|
|
|
|
|
uint_fast32_t p8_to_ui32( posit8_t )
|
|
|
|
|
|
1. Fused dot product-subtract
|
|
|
`quire16_t q16_fdp_sub(quire16_t, posit_16, posit_16)`
|
|
|
Convert posit to unsigned long long integer (64 bits) :
|
|
|
|
|
|
1. Set quire variable to zero
|
|
|
`quire16_t q16_clr(quire16_t)`
|
|
|
uint_fast64_t p16_to_ui64( posit16_t)
|
|
|
|
|
|
uint_fast64_t p8_to_ui64( posit8_t)
|
|
|
|
|
|
Convert posit to integer (32 bits) :
|
|
|
|
|
|
1. Convert quire to posit
|
|
|
`posit_16 convertQ16ToP16(quire16_t)`
|
|
|
uint_fast32_t p16_to_i32( posit16_t )
|
|
|
|
|
|
uint_fast32_t p8_to_i32( posit8_t )
|
|
|
|
|
|
Additional Posit Functionalites
|
|
|
Convert posit to long long integer (64 bits) :
|
|
|
|
|
|
1. Square root
|
|
|
`posit16_t p16_sqrt(posit16_t)`
|
|
|
uint_fast64_t p16_to_i64( posit16_t)
|
|
|
|
|
|
uint_fast64_t p8_to_i64( posit8_t)
|
|
|
|
|
|
1. Round to nearest integer
|
|
|
`posit16_t p16_roundToInt(posit16_t)`
|
|
|
Convert posit to posit of another size :
|
|
|
|
|
|
1. Check equal
|
|
|
`bool p16_eq( posit16_t, posit16_t )`
|
|
|
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 )
|
|
|
|
|
|
1. Check less than equal
|
|
|
`bool p16_le( posit16_t, posit16_t )`
|
|
|
|
|
|
1. Check less than
|
|
|
`bool p16_lt( posit16_t, posit16_t )`
|
|
|
|
|
|
1. Convert p16 to integer (32 bits)
|
|
|
`int_fast32_t p16_to_i32( posit16_t )`
|
|
|
Helper Functionalites (NOT in Posit Standard)
|
|
|
---------------------------------------------
|
|
|
|
|
|
1. Convert p16 to long integer (64 bits)
|
|
|
`int_fast64_t p16_to_i64( posit16_t)`
|
|
|
Convert posit to double (64 bits) :
|
|
|
|
|
|
1. Convert p16 to unsigned integer (32 bits)
|
|
|
`uint_fast32_t p16_to_ui32( posit16_t )`
|
|
|
double convertP16ToDouble(posit16_t)
|
|
|
|
|
|
double convertP8ToDouble(posit8_t)
|
|
|
|
|
|
1. Convert p16 to unsigned long integer (64 bits)
|
|
|
`uint_fast64_t p16_to_ui64( posit16_t)`
|
|
|
Convert double (64 bits) to posit :
|
|
|
|
|
|
1. Convert p16 to p32 (posit<32, 2>)
|
|
|
`posit32_t p16_to_p32( posit16_t )`
|
|
|
posit16_t convertDoubleToP16(double)
|
|
|
|
|
|
posit8_t convertDoubleToP8(double)
|
|
|
|
|
|
Cast binary expressed in unsigned integer to posit :
|
|
|
|
|
|
1. Convert p16 to double (64 bits)
|
|
|
`double convertP16ToDec_f(posit16_t)`
|
|
|
posit16_t castP16(uint16_t)
|
|
|
|
|
|
posit8_t castP8(uint8_t)
|
|
|
|
|
|
Cast posit into binary expressed in unsigned integer
|
|
|
|
|
|
1. Convert double (64 bits) to posit
|
|
|
`posit16_t convertdoubleToP16(double)` |
|
|
\ No newline at end of file |
|
|
uint16_t castUI16(posit16_t)
|
|
|
|
|
|
uint8_t castUI8(posit8_t) |
|
|
\ No newline at end of file |