Related articles |
---|
generating float point operation codef or complex formula in x87 truejaws%dcs.sec.samsung.co.kr@nic.sait.samsung.co (Han, Sangjin) (1996-10-08) |
Re: generating float point operation codef or complex formula in x87 simg@netcom.com (1996-10-10) |
From: | "Han, Sangjin" <truejaws%dcs.sec.samsung.co.kr@nic.sait.samsung.co.kr> |
Newsgroups: | comp.compilers |
Date: | 8 Oct 1996 01:23:50 -0400 |
Organization: | Compilers Central |
Keywords: | code, question, comment |
I'm designing a tiny compiler which supports integer value and
float point calculation.
And the compiler generates 80386/7 machine code.
BTW, 80387 coprocessor has a small stack of eight float point registors.
I can use the stack for float point arithmetic, such as,
f * (a + ( b * c + d * e )) .
Machine code will be generated in 3 step.
step.1 convert order
f, a, b, c, *, d, e, *, +, +, *
step.2 generate psuedo code
push f
push a
push b
push c
mul
push d
push e
mul
add
add
mul
step.3 convert to 80387 code
fld f
fld a
fld b
fld c
fmul
fld d
fld e
fmul
fadd
fadd
fmul
In this case, 80387's stack was used only 5 registers,
ST(0), ST(1), ST(2), ST(3), ST(4).
If the formula has 15 degree of nested operation,
the output code will occure stack overflow. ;-(
Is there any good method that generate a neat code
and allow 15 degree of nested operation ?
Sangjin Han
truejaws@unitel.co.kr
[For each expression, generate the code for the more complex subexpression
first. In the example above, reorganize to:
(( b * c + d * e ) + a) * f.
b, c, *, d, e, *, +, a, +, f, *
This keeps the stack depth down to 3 rather than 5 in this case. It's
my impression that once you've done this, there are very few
expressions in actual code that won't fit in 8 registers, so a lot of
compilers give up if they run out of register stack, and nobody
notices. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.