programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: floating point

From: <wheath_at_comcast.net>
Date: Sat, 22 Apr 2006 15:21:54 +0000

Roger,

The floating point software stack used by Swiftforth has to be Initialized once and once only for each windows callback.
Each callback is a task that has its own mostly UNinitialized User variables and 'N0 is the task's floating point stack pointer
Fstack sets aside space for the software floating stack at HERE for the task.
Here IS initialized for the task but once FSTACK is called it moves up by that amount of space. So you see, if fstack is called several times the task runs out of ram. The last time I checked, eack task gets 16k of ram.
Running out of ram in a callback gives the Dictionary Full error message.

Here are some words I use to deal with the floating point windows issues.

\ <<F F>> pairs are usually needed to protect yourself from simultaneous use
\ of the float software stack by other tasks.
\ <<F pair within <<F pair ok
\ Other tasks may change the float stack giving incorrect answers or loss of
\ data that drops off empty or full stacks

\ Remember that windows has MANY 'simultaneous' tasks.
\ to name a few:
\ 1. your own tasks not in callbacks
\ 2. any windows timer useage is a task which continues forever unless you stop it.
\ 3. all windows callbacks are tasks - dialogs etc.
\ 4. individual messages in the SAME callback can also be separate tasks

\ <<F uses NDP semaphore
\ /NDP initializes the hardware float control registers and sets up the floating point
\ stack pointer ( 'N ) in forth from the task's 'N0
\ use once at begin of each individual fp calc word
: CLRFPERR ( - )
   <<F /NDP F>> ; \ /ndp contains /fstack

\ IF 'N0 IS SET FROM PREV ALLOC - DON'T CARE AS LONG AS CORRECT
\ DONE ABOVE original HERE IN WINDOWS CALLBACK
\ MAX SPACE = $4000 = 16k forth task min for all 532 bytes for ret stk
\ EACH FSTACK MOVES UP HERE BY N * |NUMERICS| ( 16*10 = 160 BYTES )

\ maximum float stack depth must be set according to how deep
\ your intermediate calculations need to go
\ I use short words and save the intermediate results in Fvariables
10 Constant FPDEP ( max floats on software stack )

: InitFP ( - \ once in each callback or task )
  <<F 'N0 @ HERE <> \ same Dialog has same ram for some messages
    IF FPDEP FSTACK \ once ONLY per callback or task so no ramoverflow
    THEN CLRFPERR F>> ; ok

\ use initfp in your callbacks that use floating point
:Noname ( -- res ) InitFP MSG loword FP-MESSAGES ; 4 CB: RunFP

\ individual calculation within the RunFP callback
: CALCFP ( -- )
    <<F \ only this task using float stack now
          CLRFPERR \ in case some other task changed the settings
                                \ your calculation here
    F>> ; \ now other tasks can have the float stack

Hope that helps, it drove me crazy for weeks.
Warren Heath
wheath_at_comcast.net

-------------- Original message --------------
From: "Dr. Roger Dube" <rogerdube_at_dathq.com>

> Content-Type: text/plain;
> charset="us-ascii"
> Content-Transfer-Encoding: 7bit
> As part of a large program, we include fpmath.f since we need floating point
> math. We use FVariable to declare space for a floating point variable, and
> then f! and f@ to write to and retrieve from that fvariable. For checking,
> we can use f. or f>s . to see what is there. Fdepth before and after
> running basic words reveal nothing left behind.
>
>
>
> The first time we write to the variable, all works fine. The SECOND time,
> it fails.
>
>
>
> Is there something we need to declare to set aside space? How do we use it,
> and how much space should be used for typical FP math functions?
>
>
>
> What is the difference between "32 FSTACK" and /NDP? Should both be used, or
> one, and what is the reason for a specific choice?
>

>
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Sat Apr 22 2006 - 08:22:37 PDT

This archive was generated by hypermail 2.2.0 : Thu Dec 04 2008 - 03:04:21 PST