Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!SCFVM.BITNET!ZMLEB From: ZMLEB@SCFVM.BITNET (Lee Brotzman) Newsgroups: comp.lang.forth Subject: Re: Multiple Stacks Message-ID: <8905241402.AA11788@jade.berkeley.edu> Date: 24 May 89 13:36:18 GMT References: Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 55 >When is it useful to implement additional stacks? What characteristics >of a programming problem suggest that multiple stacks would be a good >solution? The most common use of additional stacks that I know of is the floating point stack. All floating point numbers are maintained on a stack separate from the normal data stack. All floating point operators, such as F+ FSIN etc., take their operands from the FP stack. Having more than one stack can allow you to write code that just doesn't look like it should work. For instance, given that + adds two single-precision integers on the data stack and replaces them with the sum, and the F+ does the same, only on the floating point stack, does the following execute correctly? 1 1.0E0 2 2.0E0 + F+ The answer is yes. The 1 and 2 go to the data stack, the 1.0E0 and 2.0E0 go to the FP stack. They look like this: Data FP SP --> +-------+ +-------+ <-- FSP | 2 | | 2.0E0 | +-------+ +-------+ | 1 | | 1.0E0 | +-------+ +-------+ After executing + the value 3 is left on the data stack. After F+ 3.0E0 is left on the FP stack. It is because of this kind of intermixing of data types and operators that it is very important to know whether your floating point package uses a separate stack or not. I believe that the standard floating point word set that the ANSI committee is working on stipulates a separate stack. > >More specifically, when applying Forth to graphics, would it be useful >to use imitate the stacks that PostScript uses? Would it be useful to >create even more stacks for specific classes of operations? I'm not a graphics programmer, but I think that like everything in programming, there are tradeoffs here. Additional stacks can make programs easier to write and, in my humble opinion, easier to read (if you avoid doing something like my silly example above). But, the more stacks you have, the more stack pointers you need, and that can slow down the system. If all the stack pointers can not be kept in registers -- and even the 68000 and VAX processors have a limited number of registers that can be dedicated to the purpose -- they have to be kept in memory. That means additional memory accesses for each stack operation, i.e. slower execution. How many stacks did you have in mind? -- Lee Brotzman (FIGI-L Moderator) -- BITNET: ZMLEB@SCFVM SPAN: CHAMP::BROTZMAN -- Internet: zmleb@scfvm.gsfc.nasa.gov GEnie: L.BROTZMAN -- The government and my company don't know what I'm saying. -- Let's keep it that way. -- Isn't Cold Fusion how Eskimos are made?