begin quoting Gabriel Sechan as of Tue, Jan 22, 2008 at 05:43:06PM -0600: > [snip] > > 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
If you're using lots of registers, you have to save lots of registers. And yes, if the callee saves, it can save off *just* the registers it uses, and no others. For some reason I think in terms of caller saves, versus callee saves. > 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. Yup. > 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). That can be taken care of by the CPU. No need to impose byte-alignment constraints on memory, unless you don't want to put that logic on the CPU. It's not like it hasn't been done. > 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. M68k had 16. How many did the VAX have? Isn't the SPARC register window 32 registers, but they can put as many registers on the CPU as they want? > The other problem is cost. Registers are transistors, lots of them. Yup. > 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. Just one of the reasons I loathe the intel architecture. -- Marketing always comes in for the win 'Cuz in marketing lying's not a sin. Stewart Stremler -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
