Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: rickman Newsgroups: comp.lang.forth Subject: Re: EXIT THEN Date: Sun, 12 Feb 2017 00:49:07 -0500 Organization: A noiseless patient Spider Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 12 Feb 2017 05:47:19 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="bcd4e40d385429cbbc91bb66fff9b0f0"; logging-data="977"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rOIk4TAdXAzoAi1I+a/H5" User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 In-Reply-To: Cancel-Lock: sha1:z89a0ODeRxoEoKC3RuuyK0TtcCU= Xref: csiph.com comp.lang.forth:54803 On 2/10/2017 9:13 PM, hughaguilar96@gmail.com wrote: > On Friday, February 10, 2017 at 6:43:56 PM UTC-7, HAA wrote: >> Coding style may influence this. For SwiftForth 0= IF NOT IF appear >> 200 times compared to ?EXIT (151) EXIT-THEN (227). >> >> Numbers matter but decisions are made on less. Take ANS words NIP >> and TUCK. SwiftForth: NIP (158) TUCK (56) >> NIP and TUCK are conveniences - additions to the language that don't >> fundamentally change anything. > > ANS-Forth was designed by Forth Inc. that in 1994 was using ITC and knew essentially nothing about code optimization. > > NIP is the same as: SWAP DROP > TUCK is the same as: SWAP OVER NIP is often a no brainer as it only require a pop while writing to the top of the stack the same value that is there, or if the top of stack is cached doing nothing to it. TUCK is a different matter. It involves pushing the stack, but writing three values. Again, if the top of stack is cached this means not writing the top of stack, but still requires two writes to the actual stack. It would only require a single write if the top two levels of the stack are cached. In software caching the top two stack values is costly in terms of code, both space and execution time. In hardware its not a "big" deal, but requires not only the extra register, but extra multiplexers as well. When designing CPUs the multiplexers will blow up your logic counts if you aren't careful. So in a stack processor it is not likely to see TUCK as a hardware primitive unless it uses multiple clock cycles (anathema in my designs). -- Rick C