Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #55927

Re: When to use !name vs. name! ?

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: When to use !name vs. name! ?
Date 2017-03-19 16:03 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2017Mar19.170308@mips.complang.tuwien.ac.at> (permalink)
References (6 earlier) <oakgpo$mjn$1@gioia.aioe.org> <oakpjr$lf6$1@dont-email.me> <bJmdndkW2_YCc1DFnZ2dnUU7-U_NnZ2d@supernews.com> <oakv5o$qc1$2@dont-email.me> <L_6dnTsdnMh9olPFnZ2dnUU7-QXNnZ2d@supernews.com>

Show all headers | View raw


"Elizabeth D. Rather" <erather@forth.com> writes:
>On 3/18/17 5:53 PM, rickman wrote:
>> On 3/18/2017 10:36 PM, Elizabeth D. Rather wrote:
>>> On 3/18/17 4:18 PM, rickman wrote:
>>>> But the fetch and store operations have an operator @ and !.  Usage is
>>>> <name> @ or <name> !.  Combining these words into one operator the
>>>> convention would be name@ or name!.  I've seen this guideline explicitly
>>>> stated for cases like 1+ or 2* and many others.
>>>
>>> The trivial case, combining <name> @/! into one, is hardly worth doing.
>>> 1+ and 2*, on the other hand, are worth defining in code on ITC
>>> implementations because they can resolve to a single machine
>>> instruction, which is why they're in CORE.
>>
>> I think that depends entirely on what is required to perform the read or
>> write.  Some registers have a protocol.  So if you are condensing a
>> number of operations into one it can be worth defining a word.

Sure, if you do an access to an 8086 port or something, you could call
the reading word BLA@ and the writing word BLA!.

>In most ITC Forths, the stack pointer is in a register, and an increment 
>or shift is one instruction (possibly indirect). There is no read or 
>write. I don't remember any instruction sets in which it is not possible 
>to increment or shift left the TOS in one instruction. A C 
>implementation, of course, may be much less efficient.

Just to illustrate this, here's what you get in gforth-fast:

: foo 1+ 2* ;  ok
: bar 1 + 2 * ;  ok
see-code foo 
$7F2CA4B88390 1+
7F2CA4AF6505:   add     rbx,$08   \ update ip (of threaded code)   
7F2CA4AF6509:   add     r14,$01   \ tos = tos + 1
$7F2CA4B88398 2*
7F2CA4AF650D:   add     rbx,$08   \ update ip (of threaded code)   
7F2CA4AF6511:   add     r14,r14   \ tos = tos + tos
$7F2CA4B883A0 ;s
see-code bar 
$7F2CA4B883E0 lit
$7F2CA4B883E8 <$1> 
$7F2CA4B883F0 <$0>                \ actually +, but combined with LIT
7F2CA4AF6529:   add     r14,[rbx] \ tos = tos + *ip
7F2CA4AF652C:   add     rbx,$18   \ update ip (of threaded code)
$7F2CA4B883F8 noop                \ actually LIT, decompiler acting up
$7F2CA4B88400 <$2> 
7F2CA4AF6530:   mov     [r15],r14
7F2CA4AF6533:   sub     r15,$08
7F2CA4AF6537:   mov     rax,rbx
7F2CA4AF653A:   lea     rbx,$10[rbx]
7F2CA4AF653E:   mov     r14,[rax]
$7F2CA4B88408 *
7F2CA4AF6541:   mov     rax,r15
7F2CA4AF6544:   lea     r15,$08[r15]
7F2CA4AF6548:   add     rbx,$08
7F2CA4AF654C:   imul    r14,$08[rax]
$7F2CA4B88410 ;s ok

In the BAR example you see that Gforth-fast has a static
superinstruction for "lit <num> +", but none for "lit <num> *".  So
for the "2 *" you see all the stack access overhead.  You don't see
threaded-code overhead apart from the ip updates thanks to dynamic
superinstructions.  And it looks like we are now using Intel assembler
syntax in the disassembler.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2016: http://www.euroforth.org/ef16/

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

When to use  !name  vs.  name! ? "HAA" <someone@microsoft.com> - 2017-03-14 11:15 +1100
  Re: When to use  !name  vs.  name! ? hughaguilar96@gmail.com - 2017-03-13 18:27 -0700
    Re: When to use  !name  vs.  name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-14 01:33 -0700
  Re: When to use  !name  vs.  name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-14 01:30 -0700
  When to use  !name  vs.  name! ? NN <november.nihal@gmail.com> - 2017-03-14 02:56 -0700
    Re: When to use  !name  vs.  name! ? "HAA" <someone@microsoft.com> - 2017-03-16 08:59 +1100
      Re: When to use  !name  vs.  name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-16 02:11 -0700
        Re: When to use  !name  vs.  name! ? "HAA" <someone@microsoft.com> - 2017-03-17 11:19 +1100
  Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-16 20:46 -0400
    Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-16 21:34 -1000
      Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-18 09:49 +1100
        Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-17 13:08 -1000
          Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-17 19:35 -0400
            Re: When to use !name vs. name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-18 00:51 -0700
            Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-19 10:47 +1100
              Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-18 22:18 -0400
                Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-18 16:36 -1000
                Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-18 23:53 -0400
                Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-18 22:22 -1000
                Re: When to use !name vs. name! ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-19 16:03 +0000
                Re: When to use !name vs. name! ? Alex <alex@rivadpm.com> - 2017-03-19 17:42 +0000
                Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-19 13:10 -1000
                Re: When to use !name vs. name! ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-03-19 13:34 +0100
                Re: When to use !name vs. name! ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-19 16:23 +0000
                Re: When to use !name vs. name! ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-03-19 20:47 +0100
                Re: When to use !name vs. name! ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-03-20 03:47 -0500
                Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-20 09:41 +1100
                Re: When to use !name vs. name! ? Coos Haak <htrofhc@gmail.com> - 2017-03-20 01:24 +0100
                Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-21 12:10 +1100
                Re: When to use !name vs. name! ? hughaguilar96@gmail.com - 2017-03-20 18:45 -0700
                Re: When to use !name vs. name! ? Coos Haak <htrofhc@gmail.com> - 2017-03-21 14:58 +0100
                Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-22 19:49 +1100
          Re: When to use !name vs. name! ? hughaguilar96@gmail.com - 2017-03-17 16:46 -0700
  Re: When to use  !name  vs.  name! ? Lars Brinkhoff <lars.spam@nocrew.org> - 2017-04-12 08:13 +0200

csiph-web