Sujet : Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]
De : melahi_ahmed (at) *nospam* yahoo.fr (Ahmed)
Groupes : comp.lang.forthDate : 16. Sep 2024, 14:21:19
Autres entêtes
Organisation : novaBBS
Message-ID : <37b7979d508f516f88f7e1fa1967a1b1@www.novabbs.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Rocksolid Light
On Mon, 16 Sep 2024 12:47:10 +0000, dxf wrote:
On 16/09/2024 8:13 pm, mhx wrote:
[..]
FORTH> tnb
\ no locals: 5ns/call.
\ locals: 18.2ns/call.
\ globals: 6ns/call.
\ no locals2: 21.9ns/call. ok
>
This appears not to be a good idea.
The root cause is piling up too many
items on the F-stack (exceeding the
hardware FPU stack limits).
>
FVALUEs may be the way to go for hardware stack.
Is this any better?
>
: tri_mf ( f: x a b c -- mv)
3 fpick ( x) 3 fpick ( x a) f>=
3 fpick ( x) 2 fpick ( x b) f< and if
fdrop \ x a b
frot 2 fpick f- \ a b x-a
fswap frot f- \ x-a b-a
f/ exit
then
3 fpick ( x) 2 fpick ( x b) f>=
3 fpick ( x) 1 fpick ( x c) f< and if
frot fdrop \ x b c
frot fover fswap f- \ b c c-x
fswap frot f- \ c-x c-b
f/ exit
then
fdrop fdrop fdrop fdrop 0e
;
Your solution gives the best speed compared to others. With gforth under
wsl, I find 59ns/call
Here is the code:
\ here is your definition
: tri_mf ( f: x a b c -- mv)
3 fpick ( x) 3 fpick ( x a) f>=
3 fpick ( x) 2 fpick ( x b) f< and if
fdrop \ x a b
frot 2 fpick f- \ a b x-a
fswap frot f- \ x-a b-a
f/ exit
then
3 fpick ( x) 2 fpick ( x b) f>=
3 fpick ( x) 1 fpick ( x c) f< and if
frot fdrop \ x b c
frot fover fswap f- \ b c c-x
fswap frot f- \ c-x c-b
f/ exit
then
fdrop fdrop fdrop fdrop 0e
;
\ and then the code
: neg_big -1e308 -1e 0e tri_mf ;
: zero -1e 0e 1e tri_mf ;
: pos_big 0e 1e 1e308 tri_mf ;
: fuzzify ( f: x)
fdup neg_big cr f.
fdup zero cr f.
pos_big cr f.
;
: go 0 do -0.1e neg_big fdrop loop ;
utime 100000000 go utime d>f d>f f- 1e-8 f* f. 0.05871598 ok
utime 100000000 go utime d>f d>f f- 1e-8 f* f. 0.05926772 ok
utime 100000000 go utime d>f d>f f- 1e-8 f* f. 0.05896149 ok
utime 100000000 go utime d>f d>f f- 1e-8 f* f. 0.05899284 ok
Ahmed