Commit 9065ac74 authored by Cerlane Leong's avatar Cerlane Leong 💬

quire fixes for both p32 and pX2

parent 4111d4bf
......@@ -1708,7 +1708,7 @@ class posit8:
return self
def toBinary(self):
self.v.toBits()
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor(self.v.v, 8, 0))
def toHex(self):
self.v.toHex()
......@@ -2047,7 +2047,7 @@ class posit16:
return self
def toBinary(self):
self.v.toBits()
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor(self.v.v, 16, 1))
def toHex(self):
self.v.toHex()
......@@ -2391,7 +2391,7 @@ class posit32:
return self
def toBinary(self):
self.v.toBits()
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor(self.v.v, 32, 2))
def toHex(self):
self.v.toHex()
......@@ -2764,7 +2764,7 @@ class posit_2:
return self
def toBinary(self):
self.v.toBits(self.x)
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor((self.v.v)>>(32-self.x), self.x, 2))
def toHex(self):
self.v.toHex(self.x)
......
......@@ -338,7 +338,7 @@ class posit8:
return self
def toBinary(self):
self.v.toBits()
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor(self.v.v, 8, 0))
def toHex(self):
self.v.toHex()
......@@ -677,7 +677,7 @@ class posit16:
return self
def toBinary(self):
self.v.toBits()
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor(self.v.v, 16, 1))
def toHex(self):
self.v.toHex()
......@@ -1021,7 +1021,7 @@ class posit32:
return self
def toBinary(self):
self.v.toBits()
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor(self.v.v, 32, 2))
def toHex(self):
self.v.toHex()
......@@ -1394,7 +1394,7 @@ class posit_2:
return self
def toBinary(self):
self.v.toBits(self.x)
def toBinaryFormated(self):
def toBinaryFormatted(self):
print(convertToColor((self.v.v)>>(32-self.x), self.x, 2))
def toHex(self):
self.v.toHex(self.x)
......
/*============================================================================
This C source file is part of the SoftPosit Posit Arithmetic Package
......@@ -95,8 +96,12 @@ posit32_t q32_to_p32(quire32_t qA){
noLZ+=noLZtmp;
frac64A = tmp;
if (i!=7 && noLZtmp!=0)
if (i!=7 && noLZtmp!=0){
frac64A+= ( uZ.ui[i+1]>>(64-noLZtmp) );
if( uZ.ui[i+1] & (((uint64_t)0x1<<(64-noLZtmp))-1) )
bitsMore=1;
i++;
}
i++;
while(i<8){
if (uZ.ui[i]>0){
......
......@@ -96,8 +96,12 @@ posit_2_t qX2_to_pX2(quire_2_t qA, int x){
noLZ+=noLZtmp;
frac64A = tmp;
if (i!=7)
if (i!=7 && noLZtmp!=0){
frac64A+= ( uZ.ui[i+1]>>(64-noLZtmp) );
if( uZ.ui[i+1] & (((uint64_t)0x1<<(64-noLZtmp))-1) )
bitsMore=1;
i++;
}
i++;
while(i<8){
if (uZ.ui[i]>0){
......@@ -109,7 +113,6 @@ posit_2_t qX2_to_pX2(quire_2_t qA, int x){
break;
}
}
//default dot is between bit 271 and 272, extreme left bit is bit 0. Last right bit is bit 511.
//Equations derived from quire32_mult last_pos = 271 - (kA<<2) - expA and first_pos = last_pos - frac_len
int kA=(271-noLZ) >> 2;
......@@ -144,6 +147,7 @@ posit_2_t qX2_to_pX2(quire_2_t qA, int x){
//regime length is smaller than length of posit
if (regA<x){
if (regA<=(x-4)){
bitNPlusOne = (frac64A>>(shift+31-x)) & 0x1;
if ((frac64A<<(33-shift+x)) !=0) bitsMore=1;
}
......
......@@ -128,7 +128,8 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
}
expA += tmp>>29;
frac64Z = (uint_fast64_t) fracA * (((tmp<<2) | 0x80000000) & 0xFFFFFFFF);
//printf("frac64Z:\n");
//printBinary(&frac64Z, 64);
if (expA>3){
kA++;
expA&=0x3; // -=4
......@@ -149,7 +150,7 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
//Minpos is 120 position to the right of binary point (dot)
//Scale = 2^es * k + e => 2k + e
int firstPos = 271 - (kA<<2) - expA;
//printf("kA: %d expA: %d, firstPos: %d\n", kA, expA, firstPos);
//Moving in chunk of 64. If it is in first chunk, a part might be in the chunk right to it. Simply have to handle that.
int i;
for (i=0; i<8; i++){
......@@ -157,12 +158,13 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
//Need to check how much of the fraction is in the next 64 bits
shiftRight = firstPos - (i*64);
uZ2.ui[i] = frac64Z >> shiftRight;
if (i!=7) uZ2.ui[i+1] = frac64Z << (64 - shiftRight);
//printf("shiftRight: %d i: %d\n", shiftRight, i);
if (i!=7 && shiftRight!=0) uZ2.ui[i+1] = frac64Z << (64 - shiftRight);
break;
}
}
if(signZ1&signZ2){
/*if(signZ1&signZ2){
signZ = 1;
for (i=7; i>=0; i--){
if (uZ1.ui[i]>0){
......@@ -176,7 +178,7 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
}
}
}
else if (signZ2){
else*/ if (signZ2){
for (i=7; i>=0; i--){
if (uZ2.ui[i]>0){
uZ2.ui[i] = - uZ2.ui[i];
......@@ -208,7 +210,7 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
}
}
if(signZ){
/*if(signZ){
for (i=7; i>=0; i--){
if (uZ.ui[i]>0){
uZ.ui[i] = - uZ.ui[i];
......@@ -220,7 +222,7 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
break;
}
}
}
}*/
//Exception handling
if (isNaRQ32(uZ.q) ) uZ.q = q32_clr(uZ.q);
......
......@@ -158,14 +158,14 @@ quire32_t q32_fdp_sub( quire32_t q, posit32_t pA, posit32_t pB ){
//Need to check how much of the fraction is in the next 64 bits
shiftRight = firstPos - (i*64);
uZ2.ui[i] = frac64Z >> shiftRight;
if (i!=7) uZ2.ui[i+1] = frac64Z << (64 - shiftRight);
if (i!=7 && shiftRight!=0) uZ2.ui[i+1] = frac64Z << (64 - shiftRight);
break;
}
}
//This is the only difference from ADD (signZ2) and (!signZ2)
if (signZ1 && !signZ2){//sum of negative numbers
/*if (signZ1 && !signZ2){//sum of negative numbers
signZ=1;
for (i=7; i>=0; i--){
if (uZ1.ui[i]>0){
......@@ -179,7 +179,7 @@ quire32_t q32_fdp_sub( quire32_t q, posit32_t pA, posit32_t pB ){
}
}
}
else if (!signZ2){
else */if (!signZ2){
for (i=7; i>=0; i--){
if (uZ2.ui[i]>0){
uZ2.ui[i] = - uZ2.ui[i];
......@@ -212,7 +212,7 @@ quire32_t q32_fdp_sub( quire32_t q, posit32_t pA, posit32_t pB ){
}
}
if(signZ){
/*if(signZ){
for (i=7; i>=0; i--){
if (uZ.ui[i]>0){
uZ.ui[i] = - uZ.ui[i];
......@@ -224,7 +224,7 @@ quire32_t q32_fdp_sub( quire32_t q, posit32_t pA, posit32_t pB ){
break;
}
}
}
}*/
//Exception handling
if (isNaRQ32(uZ.q) ) uZ.q = q32_clr(uZ.q);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment