Commit a174c245 authored by cerlane's avatar cerlane

Initial commit

parents
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SoftPosit</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.config.gnu.exe.debug.727204151" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="502090454853061292" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="cdt.managedbuild.config.gnu.exe.release.921305419" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="502090454853061292" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
#============================================================================
#
#This C source file is part of the SoftPosit Posit Arithmetic Package
#by S. H. Leong (Cerlane).
#
#Copyright 2017, 2018 A*STAR. All rights reserved.
#
#This C source file was based on SoftFloat IEEE Floating-Point Arithmetic
#Package, Release 3d, by John R. Hauser.
#
#
# Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
# University of California. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#=============================================================================
SOURCE_DIR ?= ../../source
SPECIALIZE_TYPE ?= 8086-SSE
SOFTPOSIT_OPTS ?= \
-DINLINE_LEVEL=5
# -DSOFTPOSIT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTPOSIT_FAST_DIV32TO16 \
# -DSOFTPOSIT_FAST_DIV64TO32 #-DSOFTPOSIT_EXACT
#-lquadmath
DELETE = rm -f
C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include
OPTIMISATION = -march=core-avx2 -O2
COMPILE_C = \
gcc -c -Werror-implicit-function-declaration -DSOFTPOSIT_FAST_INT64 -DQUADSUPPORT \
$(SOFTPOSIT_OPTS) $(C_INCLUDES) $(OPTIMISATION) \
-o $@
MAKELIB = ar crs $@
OBJ = .o
LIB = .a
.PHONY: all
all: softposit$(LIB)
OBJS_PRIMITIVES =
OBJS_SPECIALIZE =
OBJS_OTHERS = \
s_addMagsP16$(OBJ) \
s_subMagsP16$(OBJ) \
s_mulAddP16$(OBJ) \
p16_to_ui32$(OBJ) \
p16_to_ui64$(OBJ) \
p16_to_i32$(OBJ) \
p16_to_i64$(OBJ) \
p16_to_p32$(OBJ) \
p16_roundToInt$(OBJ) \
p16_add$(OBJ) \
p16_sub$(OBJ) \
p16_mul$(OBJ) \
p16_mulAdd$(OBJ) \
p16_div$(OBJ) \
p16_eq$(OBJ) \
p16_le$(OBJ) \
p16_lt$(OBJ) \
p16_sqrt$(OBJ) \
quire16_fdp_add$(OBJ) \
quire16_fdp_sub$(OBJ) \
quire_helper$(OBJ) \
s_approxRecipSqrt_1Ks$(OBJ) \
c_convertDecToPosit16$(OBJ) \
c_convertPosit16ToDec$(OBJ) \
c_convertQuire16ToPosit16$(OBJ)
OBJS_ALL = $(OBJS_PRIMITIVES) $(OBJS_SPECIALIZE) $(OBJS_OTHERS)
$(OBJS_ALL): \
platform.h $(SOURCE_DIR)/include/primitiveTypes.h \
$(SOURCE_DIR)/include/primitives.h
$(OBJS_SPECIALIZE) $(OBJS_OTHERS): \
$(SOURCE_DIR)/include/softposit_types.h $(SOURCE_DIR)/include/internals.h \
$(SOURCE_DIR)/$(SPECIALIZE_TYPE)/specialize.h \
$(SOURCE_DIR)/include/softposit.h
$(OBJS_PRIMITIVES) $(OBJS_OTHERS): %$(OBJ): $(SOURCE_DIR)/%.c
$(COMPILE_C) $(SOURCE_DIR)/$*.c
$(OBJS_SPECIALIZE): %$(OBJ): $(SOURCE_DIR)/$(SPECIALIZE_TYPE)/%.c
$(COMPILE_C) $(SOURCE_DIR)/$(SPECIALIZE_TYPE)/$*.c
softposit$(LIB): $(OBJS_ALL)
$(DELETE) $@
$(MAKELIB) $^
.PHONY: clean
clean:
$(DELETE) $(OBJS_ALL) softposit$(LIB)
/*============================================================================
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
Package, Release 3d, by John R. Hauser.
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#define LITTLEENDIAN 1
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#ifdef __GNUC_STDC_INLINE__
#define INLINE inline
#else
#define INLINE extern inline
#endif
/*============================================================================
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
Package, Release 3d, by John R. Hauser.
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef specialize_h
#define specialize_h 1
#include <stdbool.h>
#include <stdint.h>
#include "../include/softposit_types.h"
#endif
This diff is collapsed.
/*============================================================================
This C source file is part of the SoftPosit Posit Arithmetic Package
by S. H. Leong (Cerlane).
Copyright 2017, 2018 A*STAR. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "softposit.h"
#include "platform.h"
#include "internals.h"
#include "specialize.h"
/*#include <stdio.h>
void printstringasbinary0(uint64_t * s, int size) {
int bitSize = size-1;
int i;
for (i = bitSize; i >= 0; --i){
putchar( (*s & (1 << i)) ? '1' : '0' );
}
putchar('\n');
}*/
double convertP16ToDec_f(posit16_t a){
posit16 b = convertP16ToDec(a);
return b.f;//
}
posit16 convertP16ToDec(posit16_t a){
//printstringasbinary0(&a, 16);
union ui16_p16 uZ;
posit16 p16;
uZ.p = a;
if (uZ.ui==0){
p16.f = 0;
return p16;
}
else if(uZ.ui==0x7FFF){ //maxpos -> 32767
p16.f = 268435456;
return p16;
}
else if (uZ.ui==0x8001){ //-maxpos -> 32769
p16.f = -268435456;
return p16;
}
else if (uZ.ui == 0x8000){ //NaR -> 32768
p16.f = INFINITY;
return p16;
}
bool regS, sign;
uint_fast16_t reg, shift=2, frac;
int_fast16_t k=0;
int_fast8_t exp;
double fraction_max;
sign = signP16UI( uZ.ui );
if (sign)
uZ.ui = -uZ.ui & 0xFFFF;
regS = signregP16UI( uZ.ui );
uint_fast16_t tmp = (uZ.ui<<2) & 0xFFFF;
if (regS){
while (tmp>>15){
k++;
shift++;
tmp= (tmp<<1) & 0xFFFF;
}
reg = k+1;
}
else{
k=-1;
while (!(tmp>>15)){
k--;
shift++;
tmp= (tmp<<1) & 0xFFFF;
}
tmp&=0x7FFF;
reg =-k;
}
exp = tmp>>14;
frac = (tmp & 0x3FFF) >> shift;
fraction_max = pow(2, 13-reg) ;
p16.f = (double)( pow(4, k)* pow(2, exp) * (1+((double)frac/fraction_max)) );
if (sign)
p16.f = -p16.f;
return p16;
}
/*============================================================================
This C source file is part of the SoftPosit Posit Arithmetic Package
by S. H. Leong (Cerlane).
Copyright 2017, 2018 A*STAR. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "softposit.h"
#include "platform.h"
#include "internals.h"
#include "specialize.h"
posit16_t convertQ16ToP16(quire16_t qA){
union ui128_q16 uZ;
union ui16_p16 uA;
uint_fast16_t regA, fracA = 0, shift=0, regime;
uint_fast64_t frac64A;
bool sign, regSA=0, bitNPlusOne=0, bitsMore=0;
int_fast8_t expA = 0;
if (isQ16Zero(qA)){
uA.ui=0;
return uA.p;
}
//handle NaR
else if (isNaRQ16(qA)){
uA.ui=0x8000;
return uA.p;
}
uZ.q = qA;
sign = uZ.ui.left64>>63;
if(sign){
//probably need to do two's complement here before the rest.
if (uZ.ui.right64==0){
uZ.ui.left64 = -uZ.ui.left64;
}
else{
uZ.ui.right64 = -uZ.ui.right64;
uZ.ui.left64 = ~(uZ.ui.left64);
}
}
int noLZ =0;
if (uZ.ui.left64 == 0){
noLZ+=64;
uint_fast64_t tmp = uZ.ui.right64;
while(!(tmp>>63)){
noLZ++;
tmp<<=1;
}
frac64A = tmp;
}
else{
uint_fast64_t tmp = uZ.ui.left64;
int noLZtmp = 0;
while(!(tmp>>63)){
noLZtmp++;
tmp<<=1;
}
noLZ+=noLZtmp;
frac64A = tmp;
frac64A+= ( uZ.ui.right64>>(64-noLZtmp) );
if (uZ.ui.right64<<noLZtmp)bitsMore = 1;
}
//default dot is between bit 71 and 72, extreme left bit is bit 0. Last right bit is bit 127.
//Equations derived from quire16_mult last_pos = 71 - (kA<<1) - expA and first_pos = last_pos - frac_len
int kA=(71-noLZ) >> 1;
expA = 71 - noLZ - (kA<<1) ;
if(kA<0){
regA = (-kA & 0xFFFF);
regSA = 0;
regime = 0x4000>>regA;
}
else{
regA = kA+1;
regSA=1;
regime = 0x7FFF - (0x7FFF>>regA);
}
if(regA>14){
//max or min pos. exp and frac does not matter.
(regSA) ? (uA.ui= 0x7FFF): (uA.ui=0x1);
}
else{
//remove hidden bit
frac64A&=0x7FFFFFFFFFFFFFFF;
shift = regA+50; //1 es bit, 1 sign bit and 1 r terminating bit , 16+31+3
fracA = frac64A>>shift;
if (regA!=14){
bitNPlusOne = (frac64A>>(shift-1)) & 0x1;
if(frac64A<<(65-shift)) bitsMore = 1;
}
else if (fracA>0){
fracA=0;
bitsMore=1;
}
if (regA==14 && expA) bitNPlusOne = 1;
uA.ui = packToP16UI(regime, regA, expA, fracA);
if (bitNPlusOne){
uA.ui += (uA.ui&1) | bitsMore;
}
}
if (sign) uA.ui = -uA.ui & 0xFFFF;
return uA.p;
}
/*============================================================================
This C source file is part of the SoftPosit Posit Arithmetic Package
by S. H. Leong (Cerlane).
Copyright 2017, 2018 A*STAR. All rights reserved.
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
Package, Release 3d, by John R. Hauser.
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef internals_h
#define internals_h 1
#include <stdbool.h>
#include <stdint.h>
#include "primitives.h"
#include "softposit_types.h"
#include <stdio.h>
#ifdef SOFTPOSIT_EXACT
typedef struct { uint8_t v; bool exact; } uint8e_t;
typedef struct { uint16_t v; bool exact; } uint16e_t;
typedef struct { uint32_t v; bool exact; } uint32e_t;
typedef struct { uint64_t v; bool exact; } uint64e_t;
typedef struct { uint64_t v[2]; bool exact; } uint128e_t;
union ui8_p8 { uint8e_t ui; posit8_t p; };
union ui16_p16 { uint16e_t ui; posit16_t p; };
union ui32_p32 { uint32e_t ui; posit32_t p; };
union ui64_p64 { uint64e_t ui; posit64_t p; };
union ui128_q16 { uint64_t ui[2]; quire16_t q; };
#else
union ui8_p8 { uint8_t ui; posit8_t p; };
union ui16_p16 { uint16_t ui; posit16_t p; };
union ui32_p32 { uint32_t ui; posit32_t p; };
union ui64_p64 { uint64_t ui; posit64_t p; };
union ui128_p128c {uint64_t ui[2]; posit128_t p;}; //c to differentiate from original implementation
union ui32_q8 {
uint32_t ui;
quire8_t q;
};
union ui128_q16 {
struct{
uint64_t left64;
uint64_t right64;
} ui;
quire16_t q;
};
union ui512_q32 {
uint64_t ui[8];
quire32_t q;
};
#endif
#ifndef max
#define max( a, b ) ( ((int_fast8_t)(a) > (int_fast8_t)(b)) ? (a) : (b) )
#endif
//#ifdef SOFTPOSIT_FAST_INT64
//union extP80M_extP80 { struct extPosit80M pM; extPosit80_t p; };
//union ui128_p128 { struct uint128 ui; posit128_t p; };
//#endif
enum {
softposit_mulAdd_subC = 1,
softposit_mulAdd_subProd = 2
};
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
/*#define signP8UI( a ) ((bool) ((uint8_t) (a)>>7))
#define signregP8UI( a ) ((bool) (((uint8_t) (a)>>6) & 0x1))
#define packToP8UI( regime, fracA) ((uint8_t) regime + ((uint8_t)(fracA)) )
uint_fast16_t reglengthP8UI (uint8_t);
int regkP8UI (uint8_t);
#define regP8UI( a ) (( ((uint8_t) (a) & (0x7F)) >> max(0, 6-reglengthP8UI(a) ) ))
#define useed8P 2;
#define expP8UI(a) ((int_fast8_t) 0)
#define expP8sizeUI 0;
uint_fast16_t fracP8UI(uint8_t);
#define isNaRP8UI( a ) ( ((a) ^ 0x80) == 0 )
posit8_t softposit_addMagsP8( uint_fast8_t, uint_fast8_t );
posit8_t softposit_subMagsP8( uint_fast8_t, uint_fast8_t );
posit8_t softposit_mulAddP8( uint_fast8_t, uint_fast8_t, uint_fast8_t, uint_fast8_t );
double convertP8ToDec_f(posit8_t);
posit8 convertP8ToDec(posit8_t);
posit8_t convertDoubleToP8(double);
posit8_t convertDecToP8(posit8);
//Quire 8
quire8_t q8_fdp_add(quire8_t, posit8_t, posit8_t);
quire8_t q8_fdp_sub(quire8_t, posit8_t, posit8_t);
posit8_t convertQ8ToP8(quire8_t);
#define isNaRQ8( q ) ( q.v==0x80000000 )
#define isQ8Zero(q) ( q.v==0 )
#define q8_clr(q) ({\
q.v=0;\
q;\
})*/
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#define signP16UI( a ) ( (bool) ( ( uint16_t ) (a)>>15 ) )
#define signregP16UI( a ) ( (bool) (((uint16_t) (a)>>14) & 0x1) )
#define expP16UI( a, regA ) ((int_fast8_t) ((a)>>(13-regA) & 0x0001))
#define packToP16UI( regime, regA, expA, fracA) ((uint16_t) regime + ((uint16_t) (expA)<< (13-regA)) + ((uint16_t)(fracA)) )
uint_fast16_t reglengthP16UI ( uint_fast16_t );
int_fast8_t regkP16UI ( bool , uint_fast16_t );
uint_fast16_t fracP16UI( uint_fast16_t, uint_fast16_t);
#define regP16UI( a, regLen ) ( ( uint_fast16_t ) (((a) & (0x7FFF)) >> (14-regLen)) )
#define USEED16P 4;
#define MAXPOS16P 0x7FFF; //integer value (not actual posit computed value)
#define expP16sizeUI 1;
double convertP16ToDec_f(posit16_t);
posit16 convertP16ToDec(posit16_t);
posit16_t convertDecToP16(posit16);
posit16_t convertfloatToP16(float);
posit16_t convertdoubleToP16(double);
//posit16_t convertdoubleToP16(double);
//__float128 convertP16ToQuadDec(posit16_t);
//posit16_t convertQuadToP16(__float128);
posit16 p16_dec_add(posit16, posit16 );
posit16 p16_dec_sub(posit16, posit16 );
posit16 p16_dec_mul(posit16, posit16 );
float p16_dec_add_f(float, float );
float p16_dec_sub_f(float, float );
float p16_dec_mul_f(float, float );
#define isNaRP16UI( a ) ( ((a) ^ 0x8000) == 0 )
int_fast64_t p16_to_i64_2( posit16_t );
//Quire 16
//quire16_t quire16_add(quire16_t, quire16_t);