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


Groups > comp.lang.forth > #24047

Re: Euler 433 : analyzing euclids algo

Newsgroups comp.lang.forth
Date 2013-07-01 01:03 -0700
References <51d0db5a$0$3167$e4fe514c@dreader36.news.xs4all.nl>
Message-ID <49e3a208-0cc5-4722-9d4b-ce741ded40ea@googlegroups.com> (permalink)
Subject Re: Euler 433 : analyzing euclids algo
From m.a.m.hendrix@tue.nl

Show all headers | View raw


Albert writes:
> To my surprise at optimisation level O3 gcc generates the best
> assembler code possible, not only eliminating the tail recursion,
> keeping all calculations in registers, but also keeping the
> count in a register all the time, putting it back in d at the
> very last. It was practially identical to my assembly routine.

> Are there Forth compilers out there who would accomplish the same?
> (On this, untested, but it is about code generated anyway.)

( tested )
: gcd ( a b d -- c )
	>R 1 R@ +!
	OVER IF OVER MOD SWAP R>  RECURSE
	   ELSE SWAP R> 2DROP
	   THEN ;

And yes, iForth removes the recursion, even with the debugged code.
No, it doesn't keep values in registers, because it is single-pass
and does not restart when it uncovers that RECURSE is a simple branch
back. You give me ideas, though ...

-marcel

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


Thread

Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 01:28 +0000
  Re: Euler 433 : analyzing euclids algo m.a.m.hendrix@tue.nl - 2013-07-01 01:03 -0700
    Re: Euler 433 : analyzing euclids algo Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-01 03:20 -0500
      Re: Euler 433 : analyzing euclids algo m.a.m.hendrix@tue.nl - 2013-07-01 01:30 -0700
      Re: Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 09:59 +0000
  Re: Euler 433 : analyzing euclids algo anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-01 11:43 +0000
    Re: Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 19:01 +0000
      Re: Euler 433 : analyzing euclids algo anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-02 07:30 +0000
  Re: Euler 433 : analyzing euclids algo "WJ" <w_a_x_man@yahoo.com> - 2013-07-01 15:19 +0000
    Re: Euler 433 : analyzing euclids algo Alex McDonald <blog@rivadpm.com> - 2013-07-01 09:14 -0700
    Re: Euler 433 : analyzing euclids algo albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-01 19:05 +0000
    Re: Euler 433 : analyzing euclids algo Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-02 00:02 -0700
    Re: Euler 433 : analyzing euclids algo "WJ" <w_a_x_man@yahoo.com> - 2013-07-03 01:32 +0000
  Re: Euler 433 : analyzing euclids algo Paul Rubin <no.email@nospam.invalid> - 2013-07-01 17:37 -0700

csiph-web