Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!travelers.mail.cornell.edu!news.kei.com!newshost.marcam.com!news.mathworks.com!newsfeed.internetmci.com!howland.reston.ans.net!torn!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: Smalltalk vs C vs C++ benchmark results [Fortran]
X-Nntp-Posting-Host: superior.carleton.ca
Message-ID: <DEx2C4.1yJ@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <DEw6yJ.CJx@cunews.carleton.ca> <439lpo$ibk@newsbf02.news.aol.com>
Date: Thu, 14 Sep 1995 22:26:28 GMT
Lines: 61

In article <439lpo$ibk@newsbf02.news.aol.com>,
Bytesmiths <bytesmiths@aol.com> wrote:
>Rick Hawkins <rhawkins@iastate.edu> wrote:
>    "I'd sure like an operator, though, that would do a direct integer
>addition.  eg, rather than proccessing the message myNum := myNum + 8,
>which, as i understand it, will send a message + 8 to mynum, which will
>return a value..."
>
>To which Dave Buck <dbuck@superior.carleton.ca> replies:
>    "The commercial Smalltalks have an optimization for this purpose..."
>
>The description was a bit off, but "primitive" methods for integer math
>also exist in GNU Smalltalk, and every other Smalltalk I've ever seen --
>it's part of the "Blue Book" definition.

Perhaps a clarification is in order here.  The '+' operation is
implemented as a bytecode.  If the bytecode detects incorrect
parameter types (i.e., not SmallIntegers) then it dispatches a '+'
message.  The primitive '+' method in SmallInteger is only invoked if
the '+' bytecode failed and the receiver was a SmallInteger.

>But this was apparently *not* what Rick was hoping for:
>    "I would like to see a int+ operator that will assume that myNum holds
>an integer and increment the word at the address pointed to by mnNum by
>8."
>
>You're mixing pointers with integers, Rick! If "myNum" holds an arbitrary
>integer, and you increment the word it points to, you will get
>Unpredictable Results!

In fact, it's downright dangerous.  More explanation below:

>In Smalltalk, SmallIntegers are always passed by value, never by
>reference. Almost all other objects (except for true, false, and nil on
>some systems) are passed by reference. I assure you, the speed of the
>SmallInteger "+" primitive method is almost certainly NOT the source of
>your program's slowness!

I would tend to agree.  For those who haven't seen the details:
SmallInteger is about the only object in Smalltalk which doesn't use
dynamically allocated space.  Normally, if I have a variable which
contains an object, the variable really contains a pointer to the
object (Not quite true, but good enough for now).  SmallIntegers are
different.  A SmallInteger actually fits into the pointer with the
highest bit set.  So, if you look at a variable and the most
significant bit is set, then the rest of the bits are the value of a
SmallInteger, otherwise it's a pointer to an object.

This means you never have a pointer to a SmallInteger.  The pointer IS
the SmallInteger.  In my benchmark, SmallInteger math operations were
5 to 10 times slower than long arithmetic in C.  Then again, I could
to 10,000,000 or so per second.  It's not a bottleneck.

David Buck
dbuck@ccs.carleton.ca

_________________________________
| David K. Buck                 |
| dbuck@ccs.carleton.ca         |
| The Object People             |
|_______________________________|
