* Conversion of float denorm values
@ 2000-10-16 13:06 Uncle George
0 siblings, 0 replies; only message in thread
From: Uncle George @ 2000-10-16 13:06 UTC (permalink / raw)
To: axp-list, james.paradis; +Cc: Richard Henderson, linux-kernel@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 1579 bytes --]
in arch/alpha/math-emu/math.c, one needs to disassemble the 32bit float
value as 32 bit integer, and not presuppose it to be a 64 bit value with
a double mentality. One this change is applied, then my sample test
works everywhere.
/gat
case FOP_FNC_CVTxS:
/* It is irritating that DEC encoded CVTST with
SRC == T_floating. It is also interesting
that
the bit used to tell the two apart is /U...
*/
if (insn & 0x2000) {
FP_CONV(S,D,1,1,SR,DB);
goto pack_s;
} else {
/* CVTST need do nothing else but copy
the
bits and repack. */
#if 0
DR_c = DB_c;
DR_s = DB_s;
DR_e = DB_e;
DR_f = DB_f;
#else
/* Not exactly, vb needs to be in a 32
bit
float form, and UNPACK'ed as such! */
vb = alpha_read_fp_reg_s(fb);
FP_UNPACK_SP(SB, &vb);
DR_c = SB_c;
DR_s = SB_s;
DR_e = SB_e;
DR_f = SB_f << ( 52 - 23 );
#endif
goto pack_d;
}
[-- Attachment #2: f.c --]
[-- Type: application/octet-stream, Size: 2015 bytes --]
#include <stdio.h>
int printing = 0 ;
/* on alpha build with cc -g -mieee */
int main()
{
int errout;
#if defined(__alpha__)
unsigned long fpcr;
long l;
for ( l = 0; l < 4; l++ ) {
fpcr = ( l << 58 ); /* */
asm volatile ( "mt_fpcr %0 ; excb" : : "f"(fpcr));
underflow();
}
#else
underflow();
#endif
}
void printF( float, char *);
void printD( double, char *);
int underflow()
{
int dsb=32-9, dme=-126;
int expLimit = dme - dsb + 1;
float divisor = 2.0;
float d = 1.0, e;
float prev=0;
int i;
double conversion;
for (i=0; i>=expLimit; i--) {
if ( printing ) {
printf("I=%d\t prev=%16.14g, d=%16.14g\n",i, prev, d);
printF( d, "Value:\t");
}
prev = d;
if ((d /= divisor) >= prev) {
printf("Oops. growing larger ? \n");
return;
}
else if (d == 0)
break;
conversion = d; /* double <= float */
e = conversion; /* float <= double */
printF( d, "V\\=2.0\t");
printD( conversion, "Conversion:");
printF( e, "reverted:");
if ( d != e ){ /* Still same ? */
printf(" Conversion failed \n");
break;
}
};
if (i > expLimit)
printf("Oops, didnt do all denormal numbers\n");
return;
}
union _FP_UNION_D
{
double flt;
long l;
struct {
unsigned long long frac : 64-12;
unsigned exp : 11 ;
unsigned sign : 1;
} bits __attribute__((packed));
} ud;
union _FP_UNION_S
{
float flt;
int i;
struct {
unsigned int frac : 32-9;
unsigned exp : 8 ;
unsigned sign : 1;
} bits __attribute__((packed));
} uf;
void
printF( float d, char *msg )
{
uf.flt = d;
if ( printing )
printf("%s\tf=%x, s=(%d,%x), exp=(%d,%x), frac=(%d,%x)\n",
msg,
uf.i,
uf.bits.sign, uf.bits.sign,
uf.bits.exp, uf.bits.exp,
uf.bits.frac, uf.bits.frac );
}
void
printD( double d, char *msg)
{
ud.flt = d;
if( printing )
printf("%s\tf=%lx, s=(%d,%x), exp=(%d,%x), frac=(%ld,%lx)\n",
msg,
ud.l,
ud.bits.sign, ud.bits.sign,
ud.bits.exp, ud.bits.exp,
ud.bits.frac, ud.bits.frac );
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-10-16 13:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-10-16 13:06 Conversion of float denorm values Uncle George
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox