RetroForum Welcome, Guest. Please login or register.
March 11, 2010, 11:57:42 PM
Home Help Search Calendar Login Register

RetroForth Discussion  |  Older Boards  |  Bugs  |  Topic: "if" short jump fix « previous next »
Pages: 1 Go Down Print
Author Topic: "if" short jump fix  (Read 2837 times)
Alexey Abramov
Library Contributor
Jr. Member
***

Karma: +0/-0
Offline Offline

Posts: 47

YO! Forth Forever!


View Profile WWW
"if" short jump fix
« on: September 01, 2005, 05:13:17 PM »

My code:
Code:
: if $c009 2, m: drop $840f 2, here 0 , ;
: (if) $063b 2, m: drop m: drop $0f 1, 1, here 0 , ;
: <>if $84 m: (if) ;
: =if $85 m: (if) ;
: <if $8e m: (if) ;
: >if $8d m: (if) ;
: ?if $063b 2, $820f 2, here 0 , ;
: then dup here swap - 4 - swap ! ;
: else $e9 1, here 0 , swap dup here swap - 4 - swap ! ;

Now You can nesting many code in "if/else/then" blocks!
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: "if" short jump fix
« Reply #1 on: September 01, 2005, 06:35:49 PM »

Out of curiosity, has anyone run into problems with the short-jump form of "if" that's currently used in RetroForth? If so, can you share the code that needs a longer form? I'd like to know if this is actually a bug before I switch to using long jumps in the conditional words.
Logged
ron
Contributor
Full Member
****

Karma: +0/-0
Offline Offline

Posts: 88


View Profile WWW
Re: "if" short jump fix
« Reply #2 on: September 01, 2005, 09:29:28 PM »

Reva figures out whether to use a short or long jump, so it's (supposedly) using the fastest/smallest instruction.
Logged
Helmar
Library Contributor
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 129

TUCK what??? SWAP OVER!!!


View Profile
Re: "if" short jump fix
« Reply #3 on: September 05, 2005, 05:52:25 PM »

Reva figures out whether to use a short or long jump, so it's (supposedly) using the fastest/smallest instruction.

Reva would need multiple compilation/assembler passes to decide what's the right jump size for foreward references. How does Reva do this? To decide what's the right size for backward references is no problem. HelFORTH does this since a very long time too.

Bis dann,
Helmar
Logged
Helmar
Library Contributor
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 129

TUCK what??? SWAP OVER!!!


View Profile
Re: "if" short jump fix
« Reply #4 on: September 05, 2005, 09:13:14 PM »

Out of curiosity, has anyone run into problems with the short-jump form of "if" that's currently used in RetroForth?

I ran often into this problem. I used debugging code like

." Here I am"

inside an "if"-"then"-construct. Most things do not need longer jumps. But to make the FORTH a little more universal it's a good thing to use longer jumps. I would suggest to put the longer jumps in a library. They are useful eg. if someone wants to target Retro/(Reva?)/HelFORTH from another compiler or code generator. For hand-made code it's not really a problem (well, an error message would be a fine thing).

-Helmar
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: "if" short jump fix
« Reply #5 on: September 06, 2005, 01:41:48 AM »

Quote
I would suggest to put the longer jumps in a library

And this is what I will do. An optimizing version of the conditional words (selecting short or long forms automatically) will be included in the optimizer library I'm writing. (Expect to see this within two weeks, depending on how busy I am at work)
Logged
ron
Contributor
Full Member
****

Karma: +0/-0
Offline Offline

Posts: 88


View Profile WWW
Re: "if" short jump fix
« Reply #6 on: September 06, 2005, 03:05:07 AM »

Reva would need multiple compilation/assembler passes to decide what's the right jump size for foreward references. How does Reva do this?
You are absolutely correct, and Reva does *not* do forward jumps.  So far, none of the primitives does a forward jump (but I would use a long jump, and possibly modify it when the consuming word is executed).
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: "if" short jump fix
« Reply #7 on: September 06, 2005, 02:35:35 PM »

Quote
Reva does *not* do forward jumps

Hmm... conditionals have to skip over the code between if and then if the condition is false... how do you do this without forward jumps?   Wink
Logged
ron
Contributor
Full Member
****

Karma: +0/-0
Offline Offline

Posts: 88


View Profile WWW
Re: "if" short jump fix
« Reply #8 on: September 06, 2005, 09:04:40 PM »

Ouch!  Smiley

Yes, I was thinking about my loop stuff.  The 'if' etc. fix up the condition and patch in 90h "nop" codes - but actually it might be faster to do the long jump rather than short jump; nop; nop; nop ...

Of course, one could realize a short jump was needed and then move the code block over three bytes - which would not be a big gain overall unless the code were executed enough times.
Logged
ron
Contributor
Full Member
****

Karma: +0/-0
Offline Offline

Posts: 88


View Profile WWW
Re: "if" short jump fix
« Reply #9 on: September 06, 2005, 09:52:46 PM »

Actually, nevermind ... my 'if' code doesn't try to be jump-size smart - only the looping constructs (loop, while) do.
Logged
Pages: 1 Go Up Print 
RetroForth Discussion  |  Older Boards  |  Bugs  |  Topic: "if" short jump fix « previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC2 | SMF © 2001-2005, Lewis Media Valid XHTML 1.0! Valid CSS!