global variables as structure in VM.

John M McIntosh johnmci at smalltalkconsulting.com
Sat Apr 6 04:57:26 UTC 2002


>Is there any cost?

Yes for 68K, it must load the structure address into a register on 
entry to a routine, and depending on how other things are within the 
routine, it might reuse the address reg, and need to load the address 
again, then it uses that register plus an offset. Right now it can do 
Program Counter +/- offset so we avoid having to load that address 
register.

>
>Wow, that's a huge difference!!! Sounds like the Mac runtime system
>for 68K just isn't as efficient as the linux one. I once lost a bet with Dan
>based on the performance of the 68K VM; I wouldn't have lost it with
>the 68K Unix VM, I think...
>
>	-- John

It's the actual assembler code generated. CodeWarrior stuff is really stupid.

int popthenPush(int nItems, int oop) {
     int sp;

	longAtput(sp = stackPointer - ((nItems - 1) * 4), oop);
	stackPointer = sp;
}


mac codewarrior does
Hunk:	Kind=HUNK_GLOBAL_CODE  Name="popthenPush"(1365)  Size=40
00000000: 2A51               MOVEA.L   (A1),A5
00000002: 594F               SUBQ.W    #$4,A7
00000004: 202F 0008          MOVE.L    $0008(A7),D0
00000008: 5380               SUBQ.L    #$1,D0
0000000A: E588               LSL.L     #$2,D0
0000000C: 206D 0000          MOVEA.L   _#stackPointer,A0
00000010: 2210               MOVE.L    (A0),D1
00000012: 9280               SUB.L     D0,D1
00000014: 2E81               MOVE.L    D1,(A7)
00000016: 2041               MOVEA.L   D1,A0
00000018: 20AF 000C          MOVE.L    $000C(A7),(A0)
0000001C: 206D 0000          MOVEA.L   _#stackPointer,A0
00000020: 2081               MOVE.L    D1,(A0)
00000022: 584F               ADDQ.W    #$4,A7
00000024: 4E74 0008          RTD       #$0008


gcc does

_popthenPush:
         movel sp@(4),d0
         subql #1,d0
         lsll #2,d0
         movel _stackPointer,a0
         subl d0,a0
         movel sp@(8),a0@
         movel a0,_stackPointer
         rts

8 instructions versus 15, no wonder the gcc version is *way* faster...

-- 
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================



More information about the Squeak-dev mailing list