Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 116,407 of 117,927    |
|    Krishna Myneni to dxf    |
|    Re: Floating point implementations on AM    |
|    14 Apr 24 07:50:42    |
   
   From: krishna.myneni@ccreweb.org   
      
   On 4/14/24 03:02, dxf wrote:   
   > On 14/04/2024 5:03 pm, mhx wrote:   
   >> Anton Ertl wrote:   
   >> [..]   
   >>   
   >>> iForth:   
   >>> $10226000 : foo                          
   488BC04883ED088F4500Â Â Â Â Â H.@H.m..E.   
   >>> $1022600A fld          [r13 0 +] tbyte41DB6D00   
   Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â A[m.   
   >>> $1022600E fld          [r13 #16 +] tbyte   
   >>>                                 
   Â Â Â Â Â Â Â Â Â 41DB6D10Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â A[m.   
   >>> $10226012 fxch         ST(2)         D   
   CAÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â YJ   
   >>> $10226014 lea          r13, [r13 #32 +] qword   
   >>>                                 
   Â Â Â Â Â Â Â Â Â 4D8D6D20Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â M.m $10226018Â    
   faddp        ST(1), ST     DEC1            
    Â Â Â Â Â Â Â Â Â Â Â ^A   
   >>> $1022601A fxch         ST(1)         D   
   C9Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â YI   
   >>> $1022601C fpopswap,                      
   1DB6D00D9CA4D8D6D10Â Â Â Â Â A[m.YJM.m.   
   >>> $10226026 fmulp        ST(1), ST     DEC9    
    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ^I   
   >>> $10226028 fpush,                         
   4D8D6DF0D9C941DB7D00Â Â Â Â Â M.mpYIA[}.   
   >>> $10226032Â ;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â    
   488B45004883C508FFE0Â Â Â Â Â H.E.H.E..` ok   
   >>   
   >>> So apparently the 8 hardware FP stack items are enough for SwiftForth   
   >>> and VFX, while iForth prefers to use an FP stack in memory to allow   
   >>> for a deeper FP stack.   
   >>   
   >> Turbo Pascal had a fast FP mode that used the FPU stack. I found almost   
   >> immediately that that is unusable for serious work.   
   >   
   > Were that the case Intel had plenty opportunity to change it. They had   
   > an academic advising them.   
   >   
      
   Let's take a non-trivial example to illustrate why the 8-deep fp stack   
   may not be that useful for numerical computation. This example is   
   actually from the FSL demo. The word computes the Lorenz equations,   
   which give rise to the famous butterfly attractor. This is a system of   
   three nonlinear first order differential equations in three variables,   
   x, y, z, which are time dependent. The Lorenz equations define the   
   instantaneous derivatives of these variables:   
      
   dx/dt = sigma*(y - x)   
   dy/dt = x*(rho -z) - y   
   dz/dt = x*y - beta*z   
      
   where sigma, rho, and beta are constant parameters.   
      
   Let's say we want to write a word DERIVS which computes and stores the   
   derivatives, given the instantaneous values of x, y, z. This is the   
   basis for any numerical code which solves the trajectory in time,   
   starting from an initial condition.   
      
   DERIVS ( F: x y z -- )   
      
   Hence, we want to place some values x, y, and z onto the fp stack and   
   compute the three derivatives. Ideally these three values remain on the   
   fp stack and don't need to be fetched from memory constantly until the   
   three derivatives are computed, especially if one is using the hardware   
   fp stack. We allow the constant parameters to be fetched from memory and   
   the results of the derivative computation to be stored to memory so they   
   don't overflow the stack. This should be doable with the 8-element   
   hardware fp stack.   
      
   Below I give Forth code which computes the derivatives. This code is   
   usable only on systems with a separate FP stack. It will be interesting   
   to see the compiled code given by Forth systems using the hardware fpu   
   stack to compute the results. While this example may behave properly, if   
   we go to a fourth order system or higher, it gets less likely that the   
   hardware stack remains usable.   
      
   --   
   Krishna   
      
   == begin fpstack-test.4th ==   
   \ fpstack-test.4th   
   \   
   \ Compute the Lorenz equations, a set of three coupled   
   \ nonlinear differential equations.   
   \   
   \ dx/dt = sigma*(y - x)   
   \ dy/dt = x*(rho -z) - y   
   \ dz/dt = x*y - beta*z   
   \   
   \ sigma, rho, and beta are constant parameters.   
   \   
   \ The following code requires a separate fp stack   
      
   include ans-words \ only for kForth64   
   include fsl/fsl-util   
      
      
   [UNDEFINED] FPICK [IF]   
   cr .( Your system may not use a separate floating point stack!)   
   ABORT   
   [THEN]   
      
   [UNDEFINED] F2OVER [IF]   
   : f2over ( F: r1 r2 r3 r4 -- r1 r2 r3 r4 r1 r2 )   
    3 fpick 3 fpick ;   
   [THEN]   
      
   [UNDEFINED] F+! [IF]   
   : f+! ( a -- ) ( F: r -- ) dup f@ f+ f! ;   
   [THEN]   
      
   16.0e0 fconstant sigma   
   45.92e0 fconstant rho   
   4.0e0 fconstant beta   
      
   \ Compute the derivatives given the instantaneous values   
   \ x, y, z for a given time t.   
      
   \ xdot{ is an array consisting of dx/dt, dy/dt, dz/dt   
   3 float array xdot{   
      
   : derivs ( F: x y z -- )   
    fdup f2over \ F: x y z z x y   
    f- sigma f* fnegate   
    xdot{ 0 } f! \ F: x y z z   
    rho fover f- \ F: x y z z rho-z   
    4 fpick f* \ F: x y z z x*(rho - z)   
    3 fpick f-   
    xdot{ 1 } f! \ F: x y z z   
    fdrop   
    beta f* fnegate   
    xdot{ 2 } f!   
    f* xdot{ 2 } f+!   
      
      
   0 [IF]   
   include ttester   
   \ Test DERIVS   
   1e-15 set-near   
   t{ 0.1e 0.6e 4.0e derivs -> }t   
   t{ xdot{ 0 } f@ -> 8.0e0 }t   
   t{ xdot{ 1 } f@ -> 3.592e0 }t   
   t{ xdot{ 2 } f@ -> -15.94e0 }t   
   [THEN]   
      
   == end fpstack-test.4th ==   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca