From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id 363D42EFD9 for ; Mon, 2 Oct 2000 16:02:43 -0400 (EDT) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id e92GWSQ18849 for axp-list@listman.redhat.com; Mon, 2 Oct 2000 12:32:28 -0400 Received: from voicenet.com (mail11.voicenet.com [207.103.0.37]) by mail.redhat.com (8.11.0/8.8.7) with SMTP id e92GWSD18845 for ; Mon, 2 Oct 2000 12:32:28 -0400 Received: (qmail 5656 invoked from network); 2 Oct 2000 16:32:23 -0000 Received: from dialpool0216-pri.dialpool02.voicenet.com (HELO voicenet.com) (209.71.85.81) by mail11.voicenet.com with SMTP; 2 Oct 2000 16:32:23 -0000 Message-ID: <39D8B8DF.8ABEB868@voicenet.com> Date: Mon, 02 Oct 2000 11:33:35 -0500 From: Uncle George Organization: GatWorks X-Mailer: Mozilla 4.72 [en] (X11; I; Linux 2.2.16 alpha) X-Accept-Language: en MIME-Version: 1.0 To: axp-list@redhat.com Subject: [Fwd: conversion of a denorm float -> double is busted] Content-Type: multipart/mixed; boundary="------------D9D977764545BCDD5E807A62" X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0beta4 Precedence: bulk Reply-To: axp-list@redhat.com List-Id: Linux and Red Hat on Alpha processors This is a multi-part message in MIME format. --------------D9D977764545BCDD5E807A62 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I mailed this to the axp-list earlier this morning, but so far this msg has not been email'd back to me - so I am trying again. --------------D9D977764545BCDD5E807A62 Content-Type: message/rfc822 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Mozilla-Status2: 00000000 Message-ID: <39D885F6.8558CDDA@voicenet.com> Date: Mon, 02 Oct 2000 07:56:23 -0500 From: Uncle George Organization: GatWorks X-Mailer: Mozilla 4.72 [en] (X11; I; Linux 2.2.16 alpha) X-Accept-Language: en MIME-Version: 1.0 To: axp-list@redhat.com CC: redhat-devel@redhat.com Subject: conversion of a denorm float -> double is busted Content-Type: multipart/mixed; boundary="------------4E59CF9C59D898AD585A0EBD" This is a multi-part message in MIME format. --------------4E59CF9C59D898AD585A0EBD Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit conversion of a denorm float -> double is busted on the alpha. from the attached program , the iteration at I=-126 fails to properly convert the first denormal float number into a corresponding double ( the double is not denormal ). The exponent for the double should have been 896 ( 1 less than the previous iteration ( at i=-125), and frac=0. /gat does anyone know if the sparc, or ppc fails also ? alpha results: I=-126 prev=2.3509887016446e-38, d=1.1754943508223e-38 Value: f=800000, s=(0,0), exp=(1,1), frac=(0,0) V\=2.0 f=400000, s=(0,0), exp=(0,0), frac=(4194304,400000) Conversion: f=8000000000000, s=(0,0), exp=(0,0), frac=(2251799813685248,8000000000000) reverted: f=0, s=(0,0), exp=(0,0), frac=(0,0) Conversion failed i386 results: I=-126 prev=2.3509887016446e-38, d=1.1754943508223e-38 Value: f=800000, s=(0,0), exp=(1,1), frac=(0,0) V\=2.0 f=400000, s=(0,0), exp=(0,0), frac=(4194304,400000) Conversion: f=0, s=(0,0), exp=(896,380), frac=(0,0) reverted: f=400000, s=(0,0), exp=(0,0), frac=(4194304,400000) --------------4E59CF9C59D898AD585A0EBD Content-Type: text/plain; charset=us-ascii; name="e.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="e.c" #include 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; int main() { int errout; #if defined(__alpha__) unsigned long fpcr; asm( "excb; mf_fpcr %0" : "=f"(fpcr)); printf(" fpcr = %p\n", fpcr ); #if 1 fpcr |= (1L << 47); /* DNOD Not avail in 21264(a) */ fpcr &= ~(1L << 48 ); /* DNZ idenormal Operands to Zero */ fpcr |= (1L << 49); /* DNOD Not avail in 21264(a) */ fpcr &= ~(1L << 60 ); /* UNDZ underflow to zero OFF */ fpcr |= (1L << 61); /* UNFD underflow disable ON */ /* fpcr |= (1L << 62); UNFD */ asm volatile ( "mt_fpcr %0 ; excb" : : "f"(fpcr)); #endif asm( "excb; mf_fpcr %0" : "=f"(fpcr)); printf(" fpcr = %p\n", fpcr ); #endif underflow(); } 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--) { 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; } }; printf("i = %d, expLimit= %d\n",i,expLimit); if (i > expLimit) printf("Oops, didnt do all denormal numbers\n"); return; } void printF( float d, char *msg ) { uf.flt = d; 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; 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 ); } --------------4E59CF9C59D898AD585A0EBD-- --------------D9D977764545BCDD5E807A62--