> Date: Tue, 22 Jan 2008 15:21:07 -0800
> From: [EMAIL PROTECTED]
> To: [email protected]
> Subject: Re: Is Scheme/Lisp somehow more "fundamental" than other languages?
> 
> begin  quoting [EMAIL PROTECTED] as of Tue, Jan 22, 2008 at 03:05:03PM -0800:
> > On Tue, Jan 22, 2008 at 02:38:29PM -0800, Andrew Lentvorski wrote:
> [snip]
> > > Stack is slow.  Registers are fast.  Nobody computes using the stack
> > > unless they absolutely have to.  Stack is really only used as a place to
> > > spill registers.
> > >
> > > Even all of those variables that C claims are going onto the "stack" are
> > > really only allocated in registers if the compiler can get away with it.
> > 
> > So are you saying the way to build a fast CPU is to have as many registers 
> > as
> > possible to avoid the stack as much as possible?
> 
> No, because too many registers really slow the machine down when you
> have a context switch or function call.  All those registers have to be
> saved off somewhere.
> 
No they don't.  Only the ones that will be used need to be saved on function 
call.  If you have 1000 registers, and use 5, the other 95 can remain untouched 
and unsaved.  Context switches do become more expensive, but they're far rarer 
so the cost increment isn't that much

The cost of registers is in the instruction.  If you have N registers, you need 
log(N) bits per register in the instruction to specify an operand.  Go too big, 
and you need to increase an instructions size, meaning you fit fewer in cache.  
Go beyond 4 bytes, and your RAM suddenly needs to be byte aligned instead of 
word aligned (or aligned to something bigger like 8 bytes and you eat the 
internal waste per instruction).  This, combined with decreasing marginal 
utility (if you have 5 registers, adding 1 more is likely to be used.  If you 
have 1000, the 1001 is unlikely to help) are the limiting factors on speedup 
due to registers.  And yes, the rule of thumb is the more registers the better. 
 Intel has 6 (eax, ebx, ecx, edx, esi, edi) and its far too few.  MIPS had 32.  
Titanium had 128.  

The other problem is cost.  Registers are transistors, lots of them.  Large 
register stacks take a lot of chip space, and increase the transistor count 
elsewhere as well.  When you have limited die space, you can't have everything. 
 These days cache is more of an issue than registers, but in the old days the 
registers were the big transistor count users.  Hence the 6 register intel 
architecture.

Gabe
 
_________________________________________________________________
Need to know the score, the latest news, or you need your HotmailĀ®-get your 
"fix".
http://www.msnmobilefix.com/Default.aspx--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to