use the con_float include file
This commit is contained in:
		
							parent
							
								
									008a907894
								
							
						
					
					
						commit
						463a0e7f40
					
				
					 1 changed files with 31 additions and 67 deletions
				
			
		| 
						 | 
				
			
			@ -46,78 +46,42 @@ con_mult(sz) word sz; {
 | 
			
		|||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * The next function is difficult to do when not running on a PDP 11 or VAX
 | 
			
		||||
 * The strategy followed is to assume the code generator is running on a PDP 11
 | 
			
		||||
 * unless the ACK_ASS define  is on.
 | 
			
		||||
 */
 | 
			
		||||
#define PDPFLOAT
 | 
			
		||||
#include <con_float>
 | 
			
		||||
 | 
			
		||||
con_float() {
 | 
			
		||||
#ifdef ACK_ASS
 | 
			
		||||
	double f;
 | 
			
		||||
	double atof(), frexp();
 | 
			
		||||
	int i, j;
 | 
			
		||||
	int sign = 0;
 | 
			
		||||
	int fraction ;
 | 
			
		||||
 | 
			
		||||
	if (argval != 4 && argval != 8)
 | 
			
		||||
		fatal("bad fcon size");
 | 
			
		||||
	f = atof(str);
 | 
			
		||||
	if (f == 0) {
 | 
			
		||||
		if (argval == 8) fprintf(codefile, ".data2 0, 0\n");
 | 
			
		||||
		fprintf(codefile, ".data2 0, 0\n");
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	f = frexp(f, &i);
 | 
			
		||||
	if (f < 0) {
 | 
			
		||||
		f = -f;
 | 
			
		||||
		sign = 1;
 | 
			
		||||
	}
 | 
			
		||||
	while (f < 0.5) {
 | 
			
		||||
		f += f;
 | 
			
		||||
		i --;
 | 
			
		||||
	}
 | 
			
		||||
	f = 2*f - 1.0;		/* hidden bit */
 | 
			
		||||
	i = (i + 128) & 0377;
 | 
			
		||||
	fraction = (sign << 15) | (i << 7);
 | 
			
		||||
	for (j = 6; j>= 0; j--) {
 | 
			
		||||
		f *= 2;
 | 
			
		||||
		if (f >= 1.0) {
 | 
			
		||||
			fraction |= (1 << j);
 | 
			
		||||
			f -= 1.0;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	fprintf(codefile, ".data2 0%o", fraction);
 | 
			
		||||
	for (i = argval / 2 - 1; i; i--) {
 | 
			
		||||
		fraction = 0;
 | 
			
		||||
		for (j = 15; j>= 0; j--) {
 | 
			
		||||
			f *= 2;
 | 
			
		||||
			if (f >= 1.0) {
 | 
			
		||||
				fraction |= (1 << j);
 | 
			
		||||
				f -= 1.0;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		fprintf(codefile, ", 0%o", fraction);
 | 
			
		||||
	}
 | 
			
		||||
	putc('\n', codefile);
 | 
			
		||||
#else
 | 
			
		||||
	double f;
 | 
			
		||||
	double atof();
 | 
			
		||||
con_float()
 | 
			
		||||
{
 | 
			
		||||
	char buf[8];
 | 
			
		||||
	int rval = float_cst(str, argval, buf);
 | 
			
		||||
	int i;
 | 
			
		||||
	short *p;
 | 
			
		||||
 | 
			
		||||
	if (argval != 4 && argval != 8)
 | 
			
		||||
		fatal("bad fcon size");
 | 
			
		||||
	f = atof(str);
 | 
			
		||||
	p = (short *) &f;
 | 
			
		||||
	i = *p++;
 | 
			
		||||
	if (argval == 8) {
 | 
			
		||||
		fprintf(codefile,"\t%o;%o;",i,*p++);
 | 
			
		||||
		i = *p++;
 | 
			
		||||
	}
 | 
			
		||||
	fprintf(codefile,"\t%o;%o\n",i,*p++);
 | 
			
		||||
        if (rval == 1) {
 | 
			
		||||
                fprintf(stderr,"float constant size = %d\n",argval);
 | 
			
		||||
                fatal("bad fcon size");
 | 
			
		||||
        }
 | 
			
		||||
#ifdef ACK_ASS
 | 
			
		||||
        fprintf(codefile,"! float %s sz %d\n", str, argval);
 | 
			
		||||
#else
 | 
			
		||||
        fprintf(codefile,"/ float %s sz %d\n", str, argval);
 | 
			
		||||
#endif
 | 
			
		||||
        if (rval == 2) {
 | 
			
		||||
                fprintf(stderr, "Warning: overflow in floating point constant %s\n", str);
 | 
			
		||||
        }
 | 
			
		||||
#ifdef ACK_ASS
 | 
			
		||||
        fprintf(codefile, ".data1 0%o", buf[1] & 0377);
 | 
			
		||||
        for (i = 1; i < argval; i++) {
 | 
			
		||||
		/* use little trick to get bytes out in swapped order ... */
 | 
			
		||||
                fprintf(codefile, ",0%o", buf[i^1] & 0377);
 | 
			
		||||
        }
 | 
			
		||||
#else
 | 
			
		||||
        for (i = 0; i < argval; i++) {
 | 
			
		||||
		/* use little trick to get bytes out in swapped order ... */
 | 
			
		||||
                fprintf(codefile, "??? %o", buf[i^1] & 0377);
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
        putc('\n', codefile);
 | 
			
		||||
}
 | 
			
		||||
#endif /* ACK_ASS */
 | 
			
		||||
 | 
			
		||||
#ifdef REGVARS
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue