Recent

Author Topic: inlining a generic lookup-table  (Read 3029 times)

yogo1212

  • New Member
  • *
  • Posts: 22
inlining a generic lookup-table
« on: May 12, 2014, 01:08:02 pm »
Hi,

im trying to do this weird thing to optimise my code.
Having to do a lookup-table everywhere you want you want one can be really annoying...
That's why i am trying to insert a level of abstraction; which is potentially slower, but still better than losing hundreds of cycles with a pipeline flush.

My current idea is:
Code: [Select]
// ok... trying to make sure the inlined code is being optimised...
// not sure how inlining is implemented
{$OPTIMIZATION ON}
// inline for less stack-frames.
procedure genericLookup(second: Boolean; a,b: TObjProc); inline;
procedure genericLookup(really: Boolean; a: TObjProc); inline; overload;
{$OPTIMIZATION DEFAULT}

implementation

{$OPTIMIZATION ON}
// Is this crap?
procedure genericLookup(second: Boolean; a, b: TObjProc);
// cant make this a global variable because not thread-safe. :-(
// where does it land anyway? register? that makes the lookup really weird.
// Hope it's not on the stack...
var genericBinaryLookupTable: Array[Boolean] of TObjProc;
begin
  genericBinaryLookupTable[False] := a;
  genericBinaryLookupTable[True] := b;
  genericBinaryLookupTable[second]();
end;

procedure genericLookup(really: Boolean; a: TObjProc);
var genericSingularLookupTable: Array[Boolean] of TObjProc;
begin
  PPointer(@genericSingularLookupTable[False])^ := Pointer(@DoNothing);
  genericSingularLookupTable[True] := a;
  genericSingularLookupTable[really]();
end;
{$OPTIMIZATION DEFAULT}

Is this bogus? If so, why?
Any ideas how to improve?

kind regards

EDIT: Is there a guide about writing code that helps make use of optimisation?
« Last Edit: May 12, 2014, 01:21:07 pm by yogo1212 »

 

TinyPortal © 2005-2018