ack/modules/src/flt_arith/flt_nrm.c
George Koehler daeeb5aca3 Simplify flt_arith now that mantissa uses uint32_t.
It seems that someone wanted to build flt_arith with a compiler that
had long but not unsigned long.  This required extra code to
accomplish unsigned right shift, unsigned division, and unsigned
comparison using the signed operations.  Now that we use uint32_t, we
can simply use the unsigned operations and remove the ucmp() function.
We have similar code in mach/proto/fp/ and in
lang/cem/libcc.ansi/stdlib/ext_comp.c where we use the unsigned
operations.

Some long variables become uint32_t, and some masks with 0xFFFFFFFF
disappear because uint32_t has only 32 bits.

Update flt_arith.3 to show that mantissa uses uint32_t.

Provide a target to install modules/src/flt_arith/test.c as flt_test
so I can run the tests.
2016-11-05 21:51:53 -04:00

40 lines
696 B
C

/*
(c) copyright 1989 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#include <stdint.h>
#include "flt_misc.h"
void
flt_nrm(e)
register flt_arith *e;
{
if ((e->m1 | e->m2) == 0L) {
e->flt_exp = 0;
e->flt_sign = 0;
return;
}
/* if top word is zero mov low word */
/* to top word, adjust exponent value */
if (e->m1 == 0L) {
e->m1 = e->m2;
e->m2 = 0L;
e->flt_exp -= 32;
}
if ((e->m1 & 0x80000000UL) == 0) {
uint32_t l = 0x40000000UL;
int cnt = -1;
while (! (l & e->m1)) {
l >>= 1;
cnt--;
}
e->flt_exp += cnt;
flt_b64_sft(&(e->flt_mantissa), cnt);
}
}