1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/* floatop.c - software operations on floats and doubles for bcc */
/* Copyright (C) 1992 Bruce Evans */
#include "bcc.h"
#include "gencode.h"
#include "reg.h"
#include "sc.h"
#include "scan.h"
#include "type.h"
/*-----------------------------------------------------------------------------
f_indirect(target leaf)
make the float or double target indirect if it is not already
return nonzero iff the result is a temp double on the base of the stack
-----------------------------------------------------------------------------*/
PUBLIC bool_pt f_indirect(target)
struct symstruct *target;
{
if (target->indcount == 0)
{
if (target->storage == CONSTANT)
{
#ifdef I80386
if (i386_32)
{
if (target->type->scalar & FLOAT)
{
float val;
val = *target->offset.offd;
push(constsym(((value_t *) &val)[0]));
}
else
{
push(constsym(((value_t *) target->offset.offd)[1]));
push(constsym(((value_t *) target->offset.offd)[0]));
}
}
else
#endif
{
if (target->type->scalar & FLOAT)
{
float val = *target->offset.offd;
push(constsym( ((unsigned short*) &val)[1] ));
push(constsym( ((unsigned short*) &val)[0] ));
}
else
{
push(constsym(((unsigned short*) target->offset.offd)[3]));
push(constsym(((unsigned short*) target->offset.offd)[2]));
push(constsym(((unsigned short*) target->offset.offd)[1]));
push(constsym(((unsigned short*) target->offset.offd)[0]));
}
}
}
else if (target->type->scalar & FLOAT)
pushlist(target->storage); /* XXX - floatregs */
else
pushlist(doubleregs);
onstack(target);
}
return target->flags == TEMP && target->type->scalar & DOUBLE
&& target->offset.offi == sp;
}
/*-----------------------------------------------------------------------------
float1op(operation code, source leaf)
handles all flop unary operations except inc/dec
result is double on stack (or in condition codes for EQOP)
-----------------------------------------------------------------------------*/
PUBLIC void float1op(op, source)
op_pt op;
struct symstruct *source;
{
saveopreg();
pointat(source);
if ((op_t) op == NEGOP)
call("Fneg");
else /* op == EQOP */
call("Ftst");
outntypechar(source->type);
if ((op_t) op != EQOP)
justpushed(source);
restoreopreg();
}
/*-----------------------------------------------------------------------------
floatop(operation code, source leaf, target leaf)
handles all flop binary operations
result is double on stack (or in condition codes for EQOP)
----------------------------------------------------------------------------*/
PUBLIC void floatop(op, source, target)
op_pt op;
struct symstruct *source;
struct symstruct *target;
{
store_t regmark;
bool_t sflag;
regmark = reguse;
saveopreg();
(void) f_indirect(source);
if (!(reguse & OPREG) && (source->storage == OPREG))
{
reguse |= source->storage;
saveopreg();
}
fpush(target);
sflag = TRUE;
if (source->flags != TEMP || source->offset.offi != sp + dtypesize)
{
sflag = FALSE;
if (source->storage == OPREG)
restoreopreg();
pointat(source);
}
switch ((op_t) op)
{
case ADDOP:
call("Fadd");
break;
case DIVOP:
call("Fdiv");
break;
case EQOP:
call("Fcomp");
sp += dtypesize; /* target is popped */
break; /* target symbol now invalid but is not used */
case MULOP:
call("Fmul");
break;
case SUBOP:
call("Fsub");
break;
}
if (sflag)
{
outnl();
sp += dtypesize; /* source is popped */
}
else
outntypechar(source->type);
onstack(target);
reguse = regmark; /* early so opreg is not reloaded if source */
restoreopreg();
}
/*-----------------------------------------------------------------------------
fpush(source leaf of scalar type)
converts source to double and pushes it to stack
OPREG must be free
-----------------------------------------------------------------------------*/
PUBLIC void fpush(source)
struct symstruct *source;
{
scalar_t scalar;
if ((scalar = source->type->scalar) & RSCALAR)
{
if (f_indirect(source))
return;
pointat(source);
}
else if (scalar & DLONG)
load(source, OPREG);
else
load(source, DREG);
call("Fpush");
if (scalar & UNSIGNED)
outbyte('u');
outntypechar(source->type);
justpushed(source);
}
/*-----------------------------------------------------------------------------
justpushed(target leaf)
records that target has just been pushed to a double on the stack
-----------------------------------------------------------------------------*/
PUBLIC void justpushed(target)
struct symstruct *target;
{
sp -= dtypesize;
onstack(target);
target->type = dtype;
}
|