Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #135449

Re: F>R, FR@ and FR> Float to return stack words

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: F>R, FR@ and FR> Float to return stack words
Date 2026-08-28 06:50 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2026Aug28.085007@mips.complang.tuwien.ac.at> (permalink)
References <20260828000428.00007e53@tin.it>

Show all headers | View raw


peter <peter.noreply@tin.it> writes:
>: z*    ( f: x y u v -- x*u-y*v  x*v+y*u)
>  zdup f+ f>r                           ( f: x y u v  r: u+v)
>  fover f- f>r                          ( f: x y u  r: u+v v-u)
>  frot fdup fr>                         ( f: y u x x v-u r: u+v)
>  f*                                    ( f: y u x x*'v-u' r: u+v)
>  fr> fswap f>r f>r                     ( f: y u x r: x*'v-u' u+v)
>  frot fdup fr>                         ( f: u x y y u+v r: x*'v-u')
>  f* f>r                                ( f: u x y r: x*'v-u' y*'u+v')
>  f+ f* fdup fr> f- fswap fr>           ( f: x*u-y*v u*[x+y] x*[v-u])
>  f+ ;                                  ( f: x*u-y*v x*v+y*u)
[...]
>seea Z*
>0x428A50  C4C17B584D00         vaddsd xmm1, xmm0, qword ptr [r13]
>0x428A56  C4C17B5C4500         vsubsd xmm0, xmm0, qword ptr [r13]
>0x428A5C  C4C17B594510         vmulsd xmm0, xmm0, qword ptr [r13+0x10]
>0x428A62  C4C173594D08         vmulsd xmm1, xmm1, qword ptr [r13+0x8]
>0x428A68  C4C17B105508         vmovsd xmm2, qword ptr [r13+0x8]
>0x428A6E  C4C16B585510         vaddsd xmm2, xmm2, qword ptr [r13+0x10]
>0x428A74  C4C16B595500         vmulsd xmm2, xmm2, qword ptr [r13]
>0x428A7A  C5EB5CD9             vsubsd xmm3, xmm2, xmm1
>0x428A7E  C5FB58C2             vaddsd xmm0, xmm0, xmm2
>0x428A82  C4C17B115D10         vmovsd qword ptr [r13+0x10], xmm3
>0x428A88  4D8D6D10             lea r13, [r13+0x10]
>0x428A8C  C3                   ret
>61 bytes, 12 instructions

Nice.

>An alternative I considered was to introduce float locals. It would probably 
>have been more complicated. The result, in the best case, would be equal in
>the generated code. The problem with locals is the scope, that is to the end 
>of the word. Of course the source would be more readable!
>
>I might still implement float locals.
>
>What do you have in your system?

Gforth has had FP locals since 1994.  We recently added F>R, FR> and
FR@.  The reason why we did not have them was that the return-stack
pointer is not necessarily aligned for FP loads and stores, so on many
hardware platforms of the 1990s F>R and FR> would have been expensive
operations.

With 64-bit cells becoming mainstream, 64-bit floats (what we use in
Gforth), and the death of most architectures that do not support
unaligned accesses, the balance has changed in the meantime.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: https://forth-standard.org/
EuroForth 2026 CFP: http://www.euroforth.org/ef26/cfp.html

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

F>R, FR@ and FR> Float to return stack words peter <peter.noreply@tin.it> - 2026-08-28 00:04 +0200
  Re: F>R, FR@ and FR> Float to return stack words dxf <dxforth@gmail.com> - 2026-08-28 14:44 +1000
  Re: F>R, FR@ and FR> Float to return stack words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-08-28 06:50 +0000
  Re: F>R, FR@ and FR> Float to return stack words marcel hendrix <mhx@iae.nl> - 2026-08-28 19:35 +0200
  Re: F>R, FR@ and FR> Float to return stack words peter <peter.noreply@tin.it> - 2026-08-30 10:06 +0200
    Re: F>R, FR@ and FR> Float to return stack words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-08-30 13:31 +0000
      Re: F>R, FR@ and FR> Float to return stack words peter <peter.noreply@tin.it> - 2026-08-30 15:58 +0200
        Re: F>R, FR@ and FR> Float to return stack words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-08-30 15:12 +0000

csiph-web