Commit 7437276a authored by Cerlane Leong's avatar Cerlane Leong 💬

p32 - not exhaustively tested

parent 4669cf06
......@@ -33,21 +33,15 @@ 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>
posit32_t q32_to_p32(quire32_t qA){
//printstringasbinary0(&a, 16);
union ui512_q32 uZ;
union ui32_p32 uA;
uint_fast32_t regA, fracA = 0, shift=0, regime;
......@@ -66,11 +60,6 @@ posit32_t q32_to_p32(quire32_t qA){
return uA.p;
}
/*printf("in convertQ16ToP16\n");
printstringasbinary0(&a.v[0], 64);
printstringasbinary0(&a.v[1], 64);*/
uZ.q = qA;
sign = uZ.ui[0]>>63;
......@@ -90,11 +79,6 @@ posit32_t q32_to_p32(quire32_t qA){
}
//minpos and maxpos
/*printPositQuireAsBinary(&uZ.ui.left64, 64);
printPositQuireAsBinary(&uZ.ui.right64, 64);*/
//int noTZ = 64;
int noLZ =0;
for (i=0; i<8; i++){
......@@ -126,15 +110,12 @@ posit32_t q32_to_p32(quire32_t qA){
}
}
//printf("Convert Q2P: noLZ: %d expA: %d\n", noLZ, expA);
//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;
expA = 271 - noLZ - (kA<<2) ;
//printf("Convert Q2P: kA: %d noLZ: %d expA: %d\n", kA, noLZ, expA);
if(kA<0){
//regA = (-kA & 0xFFFF);
regA = -kA;
......@@ -153,18 +134,14 @@ posit32_t q32_to_p32(quire32_t qA){
(regSA) ? (uA.ui= 0x7FFFFFFF): (uA.ui=0x1);
}
else{
//printPositQuireAsBinary(&frac64A, 64);
//printf("bitsMore: %d\n", bitsMore);
//remove hidden bit
frac64A&=0x7FFFFFFFFFFFFFFF;
//printf("\n");
//printPositQuireAsBinary(&frac64A, 64);
shift = regA+35; //2 es bit, 1 sign bit and 1 r terminating bit , 31+4
//printf("shift: %d regA: %d\n", shift, regA);
fracA = frac64A>>shift;
//printPositQuireAsBinary(&fracA, 32);
//printPositQuireAsBinary(&fracA, 32);
//printf("p32_mul: regA: %d expA: %d\n", regA, expA);
if (regA<=28){
bitNPlusOne = (frac64A>>(shift-1)) & 0x1;
expA<<= (28-regA);
......@@ -191,10 +168,7 @@ posit32_t q32_to_p32(quire32_t qA){
if (bitNPlusOne)
uA.ui += (uA.ui&1) | bitsMore;
}
if (sign) uA.ui = -uA.ui & 0xFFFFFFFF;
return uA.p;
......
......@@ -32,17 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include "softposit.h"
#include "platform.h"
#include "internals.h"
#include "specialize.h"
//#include <stdio.h>
quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
......@@ -74,8 +67,6 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
else if (uiA==0 || uiB==0)
return q;
//printPositQuireAsBinary(&uiA, 32);
//printPositQuireAsBinary(&uiB, 32);
//max pos (sign plus and minus)
signA = signP32UI( uiA );
......@@ -84,8 +75,7 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
if(signA) uiA = (-uiA & 0xFFFFFFFF);
if(signB) uiB = (-uiB & 0xFFFFFFFF);
//printPositQuireAsBinary(&uiA, 32);
//printPositQuireAsBinary(&uiB, 32);
regSA = signregP32UI(uiA);
regSB = signregP32UI(uiB);
......@@ -105,11 +95,10 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
tmp&=0x7FFFFFFF;
}
expA = tmp>>29; //to get 2 bits
//fracA = ((tmp<<1) | 0x40000000) & 0x7FFFFFFF;
fracA = ((tmp<<2) | 0x80000000) & 0xFFFFFFFF;
//printf("kA: %d expA: %d \n", kA, expA);
//printPositQuireAsBinary(&fracA, 16);
tmp = (uiB<<2) & 0xFFFFFFFF;
if (regSB){
while (tmp>>31){
......@@ -126,12 +115,9 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
tmp&=0x7FFFFFFF;
}
expA += tmp>>29;
//frac64Z = (uint_fast64_t) fracA * (((tmp<<1) | 0x40000000) & 0x7FFFFFFF);
frac64Z = (uint_fast64_t) fracA * (((tmp<<2) | 0x80000000) & 0xFFFFFFFF);
//printf("kA: %d expA: %d \n", kA, expA);
//printPositQuireAsBinary(&tmp, 16);
//printPositQuireAsBinary(&frac32Z, 32);
if (expA>3){
kA++;
expA&=0x3; // -=4
......@@ -144,20 +130,15 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
kA ++;
expA&=0x3;
}
//frac64Z>>=1;
}
else
frac64Z<<=1;
//printPositQuireAsBinary(&frac32Z, 32);
//default dot is between bit 271 and 272, extreme left bit is bit 0. Last right bit is bit 512.
//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("firstPos: %d kA: %d expA: %d \n",firstPos, kA, expA);
//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++){
......@@ -170,9 +151,6 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
}
}
//printf("shiftRight: %d\n", shiftRight);
//if (signZ2) uZ2.q = q16_TwosComplement(uZ2.q);
if (signZ2){
for (i=7; i>=0; i--){
if (uZ2.ui[i]>0){
......@@ -186,15 +164,7 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
}
}
//int m=0;
//printf("\n");
//for (m=0; m<8; m++){
// printPositQuireAsBinary(&uZ1.ui[m], 64);
//}
//printf("\n");
//for (m=0; m<8; m++){
// printPositQuireAsBinary(&uZ2.ui[m], 64);
//}
//Addition
for (i=7; i>=0; i--){
b1 = uZ1.ui[i] & 0x1;
......@@ -215,12 +185,6 @@ quire32_t q32_fdp_add( quire32_t q, posit32_t pA, posit32_t pB ){
}
}
//printf("\n");
//int m;
//for (m=0; m<8; m++){
// printPositQuireAsBinary(&uZ.ui[m], 64);
//}
//Exception handling
if (isNaRQ32(uZ.q) ) uZ.q = q32_clr(uZ.q);
......
......@@ -32,15 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include "softposit.h"
#include "platform.h"
#include "internals.h"
#include "specialize.h"
//c-(a*b)
......
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