Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Jose on May 10, 2005, 06:38:22 PM

Title: Help optimizing this...
Post by: Jose on May 10, 2005, 06:38:22 PM
I have a linked list of structures wich, among other things, contain apointer to a function (a certain action). I also have an array of LONGs, each having flags that inicate actions that have been done. I’ll compare that with another array wich is similar but whose flags correspond to actions that must have been done before proceding. To make the comparison I’ll use an XOR. I never used C’s standard library but there must be some function that the compiler converts to the processor ‘s native XOR operation, or a way to do that. The result of the operation will of course be flags that correspond to actions that must still be done before proceding.
Is there a fast way to check the result of the XOR and procced to execute the corresponding functions, without having to check each bit at a time wich will be more time consuming?
My current idea, hopefully someone will come up with something faster, or more strightforward and efficient:

Make a table with 256 entries (all possible conbinations within a byte). Each entry in the table is a pointer to a NULL terminated array of numbers wich, when added to the number of the byte being checked (offset from the beginning of the array of LONGs) give the number of the linked list element whose function is to be executed (the linked list is organized in the as the corresponding flags in the LONG arrays).
All in all, checked bytes would be 8 times faster, but, discounting jumps to the table and  then to the array of numbers the table points to, then adding the byte nr. to each etc, should make it slower, say, 3 or times faster than individually checking bytes at best (just a bet).

I haven’t coded this yet, I’m still in the conceptual part trying to find the best algorithm before throwing time out coding something that will be scrapped later...

What do you think?
Maybe given that some functions have much more code compared to this, it's just not worth the hassle?
Title: Re: Help optimizing this...
Post by: SamuraiCrow on May 11, 2005, 02:12:54 AM
If you XOR all of the bits from one array to the other a one bit in the "actions performed" column that isn't specified in the "actions required" column you'll get a bit that is set in the destination which will indicate that the actions performed aren't sufficient to meet the needs of the actions required.  Have you excluded that possibility somewhere else in your code?
Title: Re: Help optimizing this...
Post by: Jose on May 12, 2005, 07:16:09 PM
@samurai

well spotted thanks  :-o  I coded a sketch of this 2 days ago and I think I've made an AND (&) with the "actions required" after the XOR and before checking for TRUE flags but I'm not sure...