[Nottingham] The Wed Kernal Talk/Meeting

Rob Andrews nottingham at mailman.lug.org.uk
Wed May 14 14:33:00 2003


[14-May-2003 15:03.06 (BST) / James Gibbon]
 > The single thing that sticks in my mind about Dave's excellent talk
 > is the 'altinstructions' idea [snip]
 > This strikes me as being a deeply repugnant, thoroughly despicable
 > hack, frankly - imagine having kernel code which will never be used
 > taking up valuable memory.  I can only infer that the criminal who
 > came up with this idea didn't learn to program on a ZX81 like I
 > did.

Well, in all truth... the idea isn't all that bad. Take memcpy() for
example, a normally quite intensive instruction as far as memory bus usage
and CPU usage is concerned. This can be optimised by using SSE, MMX, and the
least-demanding instructions and correctly aligned routines for your CPU.

The idea can be implemented in two ways: at boot time, modify the function
pointer table to the address of the optimal routine. Then any future calls
to that function will go to the optimal routine.

The second way would be to create a function with the name of the routine
you are going to map optimally. At boot time, set a global (whether global
to that routine, or kernel-wide) that points to the optimal routine (i.e.
function pointer). Then have the function call the optimal routine by it's
global function pointer.

Both of these would, IMHO, be very clean ways of doing it. Although you're
not going to gain the pennys-worth of extra optimisation by having gcc align
the loops, functions and jumps to addresses that the CPU favours (each CPU
to it's own).

-- 
rob 'nine' andrews    <e> rob@impure.org.uk <finger> nine@impure.org.uk