Useful programming links

Development directions, tasks, and features being actively implemented or pursued by the development team.
Post Reply
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Useful programming links

Post by chuck_starchaser »

snow_Cat
Confed Special Operative
Confed Special Operative
Posts: 349
Joined: Thu Jan 05, 2006 12:43 am
Location: /stray/
Contact:

Re: Useful programming links

Post by snow_Cat »

Thanks for collecting these resources.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Useful programming links

Post by chuck_starchaser »

Hey, Snow_Cat; been a while. My pleasure; I'm doing this for selfish reasons; so I don't lose the links.

Here's a brilliant piece:
Idioms for Typesafe Enums in C++ --by Martin Buchholz

I'm thinking of trying to come up with an enum macro and templates that allows you to declare
an enum=based switch statement that caches the last switch used, so that if the switch argument
would be the same it goes there directly, rather than go through the switch (computed goto). This would
speed-up the runtime in many places. For instance, VDU mode rarely changes (user changes it); but at
each iteration of VDU::draw() there's a switch statement with all modes as cases to go through.
I might use the code above and modify it to add the switch and last-used-cache-ing.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Re: Useful programming links

Post by klauss »

chuck_starchaser wrote:I'm thinking of trying to come up with an enum macro and templates that allows you to declare
an enum=based switch statement that caches the last switch used, so that if the switch argument
would be the same it goes there directly, rather than go through the switch (computed goto). This would
speed-up the runtime in many places. For instance, VDU mode rarely changes (user changes it); but at
each iteration of VDU::draw() there's a switch statement with all modes as cases to go through.
I might use the code above and modify it to add the switch and last-used-cache-ing.
That's nonsense. The CPU already tracks the last target efficiently enough (the branch target buffer).

The problem is with unpredictable (by BTB means) change patterns. Imagine the target changes every other execution or something like that.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Useful programming links

Post by chuck_starchaser »

I've never read about cpu's cacheing the targets of computed goto's, which is what switch statements often get compiled to;
but it could be there is such a thing and I never heard about it. What I know cpu's have is a branch prediction cache, which
is indexed by the address of the branch instruction. In a case statement based on enums, the compiler produces an array
of goto's preceded by an operation that adds some k*SwitchArg to the program counter. What would the cpu index its branch
prediction to, in such a case? Or does it have a separate "computed goto cache"?
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Re: Useful programming links

Post by klauss »

Well, there's a similar predictive cache that caches branch targets. It was introduced, AFAIK, in the netburst architecture and it sped up dynamic code a lot, like that of VMs (JVM, python, virtual calls in C++, indirect calls in C, etc).
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
www2
Venturer
Venturer
Posts: 537
Joined: Sat May 14, 2005 10:51 am
Location: milkyway->the sol system->earth->Europe->The Nederland->Soud Holland->Leiden
Contact:

Re: Useful programming links

Post by www2 »

I heft gift the topic the sticky status
All Your Base Are Belong To Us
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Useful programming links

Post by chuck_starchaser »

Excellent! Thanks! I'll keep adding any good links I come across.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Useful programming links

Post by chuck_starchaser »

Allocators, allocators...
A couple of years ago, Boost had a fast block allocator, and a half-baked multithreading library; and I put the two together and made a per-thread block allocator, super-fast.
I don't remember where the code would be, but it doesn't matter, as Boost has come up with a brand new multithreading library; and now that I'm looking for its fast block allocator I can't find it... But I'm finding useful links, anyways:

Fast allocations and deallocations --on Wikibooks
FSB Allocator

FOUND IT!
Boost Pool Allocator
Boost Pool Interfaces

I'll have a closer look tonight. I like the FSB allocator because it is NOT thread-safe, and therefore a lot faster. Not sure whether the boost one is, or isn't. I could re-implement the per-thread pool allocator, even if we don't have threads yet, just for scalability.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Re: Useful programming links

Post by klauss »

Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
Post Reply