Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)    fp_arith.c: floating-point math routines for the Linux-m68k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)    floating point emulator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)    Copyright (c) 1998-1999 David Huggins-Daines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)    Somewhat based on the AlphaLinux floating point emulator, by David
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)    Mosberger-Tang.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "fp_emu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "multi_arith.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "fp_arith.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) const struct fp_ext fp_QNaN =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	.exp = 0x7fff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	.mant = { .m64 = ~0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) const struct fp_ext fp_Inf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	.exp = 0x7fff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /* let's start with the easy ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) fp_fabs(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	dprint(PINSTR, "fabs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	fp_monadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	dest->sign = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) fp_fneg(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	dprint(PINSTR, "fneg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	fp_monadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	dest->sign = !dest->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /* Now, the slightly harder ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /* fp_fadd: Implements the kernel of the FADD, FSADD, FDADD, FSUB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)    FDSUB, and FCMP instructions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) fp_fadd(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	dprint(PINSTR, "fadd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	fp_dyadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (IS_INF(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		/* infinity - infinity == NaN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		if (IS_INF(src) && (src->sign != dest->sign))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (IS_INF(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		fp_copy_ext(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (IS_ZERO(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (IS_ZERO(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			if (src->sign != dest->sign) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				if (FPDATA->rnd == FPCR_ROUND_RM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 					dest->sign = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 					dest->sign = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			fp_copy_ext(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	dest->lowmant = src->lowmant = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if ((diff = dest->exp - src->exp) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		fp_denormalize(src, diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	else if ((diff = -diff) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		fp_denormalize(dest, diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (dest->sign == src->sign) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (fp_addmant(dest, src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			if (!fp_addcarry(dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (dest->mant.m64 < src->mant.m64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			fp_submant(dest, src, dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			dest->sign = !dest->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			fp_submant(dest, dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* fp_fsub: Implements the kernel of the FSUB, FSSUB, and FDSUB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)    instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)    Remember that the arguments are in assembler-syntax order! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) fp_fsub(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	dprint(PINSTR, "fsub ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	src->sign = !src->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return fp_fadd(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) fp_fcmp(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	dprint(PINSTR, "fcmp ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	FPDATA->temp[1] = *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	src->sign = !src->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return fp_fadd(&FPDATA->temp[1], src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) fp_ftst(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	dprint(PINSTR, "ftst\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	(void)dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) fp_fmul(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	union fp_mant128 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	dprint(PINSTR, "fmul\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	fp_dyadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* calculate the correct sign now, as it's necessary for infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	dest->sign = src->sign ^ dest->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	/* Handle infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (IS_INF(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		if (IS_ZERO(src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (IS_INF(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (IS_ZERO(dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			fp_copy_ext(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	/* Of course, as we all know, zero * anything = zero.  You may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	   not have known that it might be a positive or negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	   zero... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (IS_ZERO(dest) || IS_ZERO(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		dest->exp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		dest->mant.m64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		dest->lowmant = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	exp = dest->exp + src->exp - 0x3ffe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	/* shift up the mantissa for denormalized numbers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	   so that the highest bit is set, this makes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	   shift of the result below easier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if ((long)dest->mant.m32[0] >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		exp -= fp_overnormalize(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if ((long)src->mant.m32[0] >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		exp -= fp_overnormalize(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	/* now, do a 64-bit multiply with expansion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	fp_multiplymant(&temp, dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* normalize it back to 64 bits and stuff it back into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	   destination struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if ((long)temp.m32[0] > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		exp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		fp_putmant128(dest, &temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		fp_putmant128(dest, &temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (exp >= 0x7fff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		fp_set_ovrflw(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	dest->exp = exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (exp < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		fp_set_sr(FPSR_EXC_UNFL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		fp_denormalize(dest, -exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* fp_fdiv: Implements the "kernel" of the FDIV, FSDIV, FDDIV and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)    FSGLDIV instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)    Note that the order of the operands is counter-intuitive: instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)    of src / dest, the result is actually dest / src. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) fp_fdiv(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	union fp_mant128 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	int exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	dprint(PINSTR, "fdiv\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	fp_dyadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* calculate the correct sign now, as it's necessary for infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	dest->sign = src->sign ^ dest->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/* Handle infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (IS_INF(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		/* infinity / infinity = NaN (quiet, as always) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		if (IS_INF(src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		/* infinity / anything else = infinity (with approprate sign) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (IS_INF(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		/* anything / infinity = zero (with appropriate sign) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		dest->exp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dest->mant.m64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		dest->lowmant = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* zeroes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (IS_ZERO(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		/* zero / zero = NaN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		if (IS_ZERO(src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		/* zero / anything else = zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (IS_ZERO(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		/* anything / zero = infinity (with appropriate sign) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		fp_set_sr(FPSR_EXC_DZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		dest->exp = 0x7fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		dest->mant.m64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	exp = dest->exp - src->exp + 0x3fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	/* shift up the mantissa for denormalized numbers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	   so that the highest bit is set, this makes lots
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	   of things below easier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if ((long)dest->mant.m32[0] >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		exp -= fp_overnormalize(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if ((long)src->mant.m32[0] >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		exp -= fp_overnormalize(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	/* now, do the 64-bit divide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	fp_dividemant(&temp, dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/* normalize it back to 64 bits and stuff it back into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	   destination struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (!temp.m32[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		exp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		fp_putmant128(dest, &temp, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		fp_putmant128(dest, &temp, 31);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (exp >= 0x7fff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		fp_set_ovrflw(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	dest->exp = exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (exp < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		fp_set_sr(FPSR_EXC_UNFL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		fp_denormalize(dest, -exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) fp_fsglmul(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	int exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	dprint(PINSTR, "fsglmul\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	fp_dyadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* calculate the correct sign now, as it's necessary for infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	dest->sign = src->sign ^ dest->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	/* Handle infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (IS_INF(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		if (IS_ZERO(src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (IS_INF(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		if (IS_ZERO(dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			fp_copy_ext(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/* Of course, as we all know, zero * anything = zero.  You may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	   not have known that it might be a positive or negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	   zero... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (IS_ZERO(dest) || IS_ZERO(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		dest->exp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		dest->mant.m64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		dest->lowmant = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	exp = dest->exp + src->exp - 0x3ffe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* do a 32-bit multiply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	fp_mul64(dest->mant.m32[0], dest->mant.m32[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		 dest->mant.m32[0] & 0xffffff00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		 src->mant.m32[0] & 0xffffff00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (exp >= 0x7fff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		fp_set_ovrflw(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	dest->exp = exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (exp < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		fp_set_sr(FPSR_EXC_UNFL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		fp_denormalize(dest, -exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) fp_fsgldiv(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	int exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	unsigned long quot, rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	dprint(PINSTR, "fsgldiv\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	fp_dyadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	/* calculate the correct sign now, as it's necessary for infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	dest->sign = src->sign ^ dest->sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	/* Handle infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (IS_INF(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		/* infinity / infinity = NaN (quiet, as always) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		if (IS_INF(src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		/* infinity / anything else = infinity (with approprate sign) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (IS_INF(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		/* anything / infinity = zero (with appropriate sign) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		dest->exp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		dest->mant.m64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		dest->lowmant = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	/* zeroes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (IS_ZERO(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		/* zero / zero = NaN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		if (IS_ZERO(src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		/* zero / anything else = zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (IS_ZERO(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		/* anything / zero = infinity (with appropriate sign) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		fp_set_sr(FPSR_EXC_DZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		dest->exp = 0x7fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		dest->mant.m64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	exp = dest->exp - src->exp + 0x3fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	dest->mant.m32[0] &= 0xffffff00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	src->mant.m32[0] &= 0xffffff00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	/* do the 32-bit divide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (dest->mant.m32[0] >= src->mant.m32[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		fp_sub64(dest->mant, src->mant);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		fp_div64(quot, rem, dest->mant.m32[0], 0, src->mant.m32[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		dest->mant.m32[0] = 0x80000000 | (quot >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		dest->mant.m32[1] = (quot & 1) | rem;	/* only for rounding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		fp_div64(quot, rem, dest->mant.m32[0], 0, src->mant.m32[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		dest->mant.m32[0] = quot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		dest->mant.m32[1] = rem;		/* only for rounding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		exp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (exp >= 0x7fff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		fp_set_ovrflw(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	dest->exp = exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (exp < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		fp_set_sr(FPSR_EXC_UNFL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		fp_denormalize(dest, -exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* fp_roundint: Internal rounding function for use by several of these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)    emulated instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)    This one rounds off the fractional part using the rounding mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)    specified. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static void fp_roundint(struct fp_ext *dest, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	union fp_mant64 oldmant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	unsigned long mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (!fp_normalize_ext(dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	/* infinities and zeroes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (IS_INF(dest) || IS_ZERO(dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	/* first truncate the lower bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	oldmant = dest->mant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	switch (dest->exp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	case 0 ... 0x3ffe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		dest->mant.m64 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	case 0x3fff ... 0x401e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		dest->mant.m32[0] &= 0xffffffffU << (0x401e - dest->exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		dest->mant.m32[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		if (oldmant.m64 == dest->mant.m64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	case 0x401f ... 0x403e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		dest->mant.m32[1] &= 0xffffffffU << (0x403e - dest->exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		if (oldmant.m32[1] == dest->mant.m32[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	fp_set_sr(FPSR_EXC_INEX2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	/* We might want to normalize upwards here... however, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	   we know that this is only called on the output of fp_fdiv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	   or with the input to fp_fint or fp_fintrz, and the inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	   to all these functions are either normal or denormalized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	   (no subnormals allowed!), there's really no need.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	   In the case of fp_fdiv, observe that 0x80000000 / 0xffff =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	   0xffff8000, and the same holds for 128-bit / 64-bit. (i.e. the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	   smallest possible normal dividend and the largest possible normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	   divisor will still produce a normal quotient, therefore, (normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	   << 64) / normal is normal in all cases) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	case FPCR_ROUND_RN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		switch (dest->exp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		case 0 ... 0x3ffd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		case 0x3ffe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			/* As noted above, the input is always normal, so the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 			   guard bit (bit 63) is always set.  therefore, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 			   only case in which we will NOT round to 1.0 is when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			   the input is exactly 0.5. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			if (oldmant.m64 == (1ULL << 63))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		case 0x3fff ... 0x401d:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			mask = 1 << (0x401d - dest->exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 			if (!(oldmant.m32[0] & mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			if (oldmant.m32[0] & (mask << 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			if (!(oldmant.m32[0] << (dest->exp - 0x3ffd)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 					!oldmant.m32[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		case 0x401e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			if (oldmant.m32[1] & 0x80000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 			if (oldmant.m32[0] & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			if (!(oldmant.m32[1] << 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		case 0x401f ... 0x403d:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			mask = 1 << (0x403d - dest->exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			if (!(oldmant.m32[1] & mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			if (oldmant.m32[1] & (mask << 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 			if (!(oldmant.m32[1] << (dest->exp - 0x401d)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	case FPCR_ROUND_RZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		if (dest->sign ^ (mode - FPCR_ROUND_RM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	switch (dest->exp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	case 0 ... 0x3ffe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		dest->exp = 0x3fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		dest->mant.m64 = 1ULL << 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	case 0x3fff ... 0x401e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		mask = 1 << (0x401e - dest->exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if (dest->mant.m32[0] += mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		dest->mant.m32[0] = 0x80000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		dest->exp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	case 0x401f ... 0x403e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		mask = 1 << (0x403e - dest->exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		if (dest->mant.m32[1] += mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		if (dest->mant.m32[0] += 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)                         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		dest->mant.m32[0] = 0x80000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)                 dest->exp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /* modrem_kernel: Implementation of the FREM and FMOD instructions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)    (which are exactly the same, except for the rounding used on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)    intermediate value) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) modrem_kernel(struct fp_ext *dest, struct fp_ext *src, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	struct fp_ext tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	fp_dyadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	/* Infinities and zeros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	if (IS_INF(dest) || IS_ZERO(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (IS_ZERO(dest) || IS_INF(src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	/* FIXME: there is almost certainly a smarter way to do this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	fp_copy_ext(&tmp, dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	fp_fdiv(&tmp, src);		/* NOTE: src might be modified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	fp_roundint(&tmp, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	fp_fmul(&tmp, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	fp_fsub(dest, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	/* set the quotient byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	fp_set_quotient((dest->mant.m64 & 0x7f) | (dest->sign << 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* fp_fmod: Implements the kernel of the FMOD instruction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)    Again, the argument order is backwards.  The result, as defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)    the Motorola manuals, is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)    fmod(src,dest) = (dest - (src * floor(dest / src))) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) fp_fmod(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	dprint(PINSTR, "fmod\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	return modrem_kernel(dest, src, FPCR_ROUND_RZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /* fp_frem: Implements the kernel of the FREM instruction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)    frem(src,dest) = (dest - (src * round(dest / src)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) fp_frem(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	dprint(PINSTR, "frem\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	return modrem_kernel(dest, src, FPCR_ROUND_RN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) fp_fint(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	dprint(PINSTR, "fint\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	fp_copy_ext(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	fp_roundint(dest, FPDATA->rnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) fp_fintrz(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	dprint(PINSTR, "fintrz\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	fp_copy_ext(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	fp_roundint(dest, FPCR_ROUND_RZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct fp_ext *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) fp_fscale(struct fp_ext *dest, struct fp_ext *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	int scale, oldround;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	dprint(PINSTR, "fscale\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	fp_dyadic_check(dest, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	/* Infinities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (IS_INF(src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		fp_set_nan(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	if (IS_INF(dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	/* zeroes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	if (IS_ZERO(src) || IS_ZERO(dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	/* Source exponent out of range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if (src->exp >= 0x400c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		fp_set_ovrflw(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	/* src must be rounded with round to zero. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	oldround = FPDATA->rnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	FPDATA->rnd = FPCR_ROUND_RZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	scale = fp_conv_ext2long(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	FPDATA->rnd = oldround;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	/* new exponent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	scale += dest->exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	if (scale >= 0x7fff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		fp_set_ovrflw(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	} else if (scale <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		fp_set_sr(FPSR_EXC_UNFL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		fp_denormalize(dest, -scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		dest->exp = scale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)