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


Groups > comp.lang.forth > #13161

Re: SEE in gforth 7.0.0 64 bits

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: SEE in gforth 7.0.0 64 bits
Date 2012-06-22 11:16 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2012Jun22.131649@mips.complang.tuwien.ac.at> (permalink)
References <m5zjxf.lgd@spenarnc.xs4all.nl> <7xlijgw00e.fsf@ruckus.brouhaha.com> <66e90eec-da8d-4b9c-862c-b4a4aef7f4b0@d6g2000vbe.googlegroups.com>

Show all headers | View raw


Mark Wills <markrobertwills@yahoo.co.uk> writes:
>On Jun 22, 3:31=A0am, Paul Rubin <no.em...@nospam.invalid> wrote:
>> Albert van der Horst <alb...@spenarnc.xs4all.nl> writes:
>>
>> > It is a 64 bit AMD system.
>>
>> > I encounter the following:
>> > =A0 =A0 =A0 =A0 SEE works fine, except for code words. Then it hangs.
>>
>> Works fine for me on an Intel Core 2:
>>
>> Gforth 0.7.0, Copyright (C) 1995-2008 Free Software Foundation, Inc.
>> Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
>> Type `bye' to exit
>> see dup
>> Code dup
>> 0x00000000004060be <gforth_engine+9470>: =A0 =A0 =A0 =A0mov
>> %rbx,0x23b63b(%rip) =A0 =A0 =A0 =A0# 0x641700 <saved_ip>
>> 0x00000000004060c5 <gforth_engine+9477>: =A0 =A0 =A0 =A0mov =A0 =A0(%r15)=
>,%rdx
>> 0x00000000004060c8 <gforth_engine+9480>: =A0 =A0 =A0 =A0mov =A0 =A0%r15,%=
>rax
>> 0x00000000004060cb <gforth_engine+9483>: =A0 =A0 =A0 =A0lea =A0 =A0-0x8(%=
>r15),%r15
>> 0x00000000004060cf <gforth_engine+9487>: =A0 =A0 =A0 =A0add =A0 =A0$0x8,%=
>rbx
>> 0x00000000004060d3 <gforth_engine+9491>: =A0 =A0 =A0 =A0mov =A0 =A0%rdx,-=
>0x8(%rax)
>> 0x00000000004060d7 <gforth_engine+9495>: =A0 =A0 =A0 =A0mov =A0 =A0-0x8(%=
>rbx),%rbp
>> 0x00000000004060db <gforth_engine+9499>: =A0 =A0 =A0 =A0mov =A0 =A0%rbp,%=
>rax
>> 0x00000000004060de <gforth_engine+9502>: =A0 =A0 =A0 =A0jmpq =A0 0x403c21
>> <gforth_engine+97>
>> end-code
>> =A0ok
>
>Wow. Don't want to hijack this thread, but why so much code for a DUP?

Why so many "=A0"s, when the posting you cite had none?

Anyway, I'll annotate it:

Code dup
mov %rbx,0x23b63b(%rip) save IP for the backtrace (if there is an exception)
mov  (%r15),%rdx        get TOS
mov  %r15,%rax          gcc sucks
lea  -0x8(%r15),%r15    decrement SP
add  $0x8,%rbx          increment IP
mov  %rdx,-0x8(%rax)    store new TOS
mov  -0x8(%rbx),%rbp    gcc sucks
mov  %rbp,%rax          gcc sucks
jmpq 0x403c21           gcc sucks really bad (this should be "jmp %eax")
end-code

On a gcc that sucks less (gcc-2.95), but unfortunately does not
generate AMD64 code, an IA-32 DUP looks as follows:

Code dup  
mov dword ptr 806256C , ebx  save IP
mov eax , dword ptr [esi]    get TOS
add esi , # -4               decrement SP
add ebx , # 4                increment IP
mov dword ptr [esi] , eax    store new TOS
mov eax , dword ptr FC [ebx] get code address of next word
jmp eax                      jump there
end-code

If gcc worked perfectly, it would generate "jmp dword ptr FC [ebx]"
instead of the last two instructions.  Actually I think that gcc-2.95
works as well as possible here for the code we give it, but the code
contains workarounds for getting decent performance out of other gcc
versions.

>I know it's apples and oranges, but DUP on my system is a single
>instruction, and my CPU doesn't even have a stack!
>
>DUP:  MOV *R4+,*R4

It's apples and oranges because you compare a DUP with NEXT to one
without, and because you compare the debugging version of Gforth to a
system that does not notice all stack underflows and probably cannot
pinpoint where an exception (like stack underflow) occured, whereas
the debugging version of Gforth can do both).

To make it a little more balanced, let's look at gforth-fast's DUP
(Gforth-fast does not notice all stack underflows and does not
pinpoint where an exception occured):

Code dup  
add     esi , # -4                decrement SP
add     ebx , # 4                 increment IP (NEXT)
mov     dword ptr 4 [esi] , ecx   store TOS
mov     eax , dword ptr FC [ebx]  code address of next word (NEXT)
mov     esi , esi                 two-byte NOP
jmp     eax                       jump there (NEXT)
end-code

- 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 2012: http://www.euroforth.org/ef12/

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


Thread

SEE in gforth 7.0.0 64 bits Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-21 21:05 +0000
  Re: SEE in gforth 7.0.0 64 bits Josh Grams <josh@qualdan.com> - 2012-06-21 22:52 +0000
    Re: SEE in gforth 7.0.0 64 bits Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-22 11:25 +0000
    Re: SEE in gforth 7.0.0 64 bits Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-22 12:23 +0000
      Re: SEE in gforth 7.0.0 64 bits anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-22 11:57 +0000
        Re: SEE in gforth 7.0.0 64 bits Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-22 20:42 +0000
          Re: SEE in gforth 7.0.0 64 bits rugxulo@gmail.com - 2012-06-24 05:28 -0700
  Re: SEE in gforth 7.0.0 64 bits Paul Rubin <no.email@nospam.invalid> - 2012-06-21 19:31 -0700
    Re: SEE in gforth 7.0.0 64 bits Mark Wills <markrobertwills@yahoo.co.uk> - 2012-06-22 00:54 -0700
      Re: SEE in gforth 7.0.0 64 bits anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-22 11:16 +0000
        Re: SEE in gforth 7.0.0 64 bits "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-06-22 16:17 -0400
          Re: SEE in gforth 7.0.0 64 bits anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-23 13:51 +0000
            Re: SEE in gforth 7.0.0 64 bits "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-06-24 04:06 -0400
              Re: SEE in gforth 7.0.0 64 bits Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-24 06:55 -0500
              Re: SEE in gforth 7.0.0 64 bits anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-24 13:24 +0000
                Re: SEE in gforth 7.0.0 64 bits "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-06-24 18:44 -0400
                Re: SEE in gforth 7.0.0 64 bits Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-25 05:00 -0500
                Re: SEE in gforth 7.0.0 64 bits "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-06-25 17:54 -0400
                Re: SEE in gforth 7.0.0 64 bits Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-26 03:41 -0500
            Re: SEE in gforth 7.0.0 64 bits rugxulo@gmail.com - 2012-06-24 05:25 -0700
              Re: SEE in gforth 7.0.0 64 bits anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-24 14:08 +0000
                Re: SEE in gforth 7.0.0 64 bits rugxulo@gmail.com - 2012-06-25 07:56 -0700
        OT: fixing Mark's A0's, was [Re: SEE in gforth 7.0.0 64 bits] "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-06-22 16:18 -0400
          Re: OT: fixing Mark's A0's, was [Re: SEE in gforth 7.0.0 64 bits] Marc Olschok <nobody@nowhere.invalid> - 2012-06-25 12:42 +0000
            Re: OT: fixing Mark's A0's, was [Re: SEE in gforth 7.0.0 64 bits] Mark Wills <markrobertwills@yahoo.co.uk> - 2012-06-25 06:30 -0700
              Re: OT: fixing Mark's A0's, was [Re: SEE in gforth 7.0.0 64 bits] rugxulo@gmail.com - 2012-06-25 08:04 -0700
                Re: OT: fixing Mark's A0's, was [Re: SEE in gforth 7.0.0 64 bits] Mark Wills <markrobertwills@yahoo.co.uk> - 2012-06-25 11:00 -0700
                Re: OT: fixing Mark's A0's, was [Re: SEE in gforth 7.0.0 64 bits] "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-06-25 17:47 -0400
      Re: SEE in gforth 7.0.0 64 bits "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-06-22 16:01 -0400
  Re: SEE in gforth 7.0.0 64 bits Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2012-06-24 15:15 +0100

csiph-web