Sujet : Re: FP number syntax
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forthDate : 03. Jan 2025, 10:59:20
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Jan3.105920@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6
User-Agent : xrn 10.11
dxf <
dxforth@gmail.com> writes:
Well, I consider mixed-math to be genius :) Was it a Forth first -
or it pre-existed in some language/system?
I am not aware of any other non-assembly language that supports
mixed-width math. Some other programming languages have multiple
integer or FP widths, but they tend to define their operations as
first converting to a common width, and then producing a result of the
same width. This can be used to specify widening operations, e.g., as
follows (in C):
int64_t widening_mul(int32_t a, int32_t b)
{
return a * (int64_t)b;
}
but the compiler has to do extra work to recognize that this is a
widening multiplication (rather than first sign-extending the operands
and then performing a 64bit*64bit->64bit multiplication).
And for division there is no way to specify the likes of UM/MOD or
SM/REM in C such that it can be implemented with just the DIV or IDIV
instruction (plus maybe register-register moves) of IA-32 or AMD64.
Mixed-width multiplication and division is a natural outcome of
implementing multiplication and division using repeated addition,
subtraction and shifting, and of course the first PDP-11
implementation, the 8086, 68000 and MIPS R2000, which implemented
these operations internally in that way, provide mixed-width
instructions for them.
More recent CPUs use different implementation techniques, so recent
architectures tend not to provide mixed-width division instructions.
They tend to have support for mixed-width multiplication (but usually
split that into two instructions), probably because it's important for
implementing wide multiplication, which is important for cryptography.
- anton
-- M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.htmlcomp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: https://forth-standard.org/ EuroForth 2024: https://euro.theforth.net