This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PowerPC G5, 64-bit long long, bit counting and inline assembler...


Hi, 

I am trying to speed up some C code and find that I need to know details
about compilation and assembler that I cannot seem to find either via
FAQs or Google.

I have a program that represents sets using the bit pattern in a 64-bit
word, and I repeatedly have to answer the question "Does this word have
exactly 2 bits set".

At the moment, I am using a bit manipulation trick as follows:

#define IF2BITS(x) x &= x-1; if (x && !(x&(x-1)))

(this relies on the fact that x&(x-1) strips off the least significant
bit that is set)

In order to use 64-bit words, I am using the type "long long".


Now I recently gained access to a Mac G5, with the 64-bit PowerPC G5
chip, and so I naively expected a substantial increase in performance
over my existing testing machine (in case it is relevant the chips are
2.667GHz Xeon vs 2GHz G5) because presumably gcc must "simulate" the
64-bit behaviour of "long long" on a 32-bit machine while it can do it
natively on a G5. 

But in practice, I only gained about 20% - even when I did a test
program that *only* did a few billion operations like &, |, ^ and the
IF2BITS macro above.... 

Is there something important that I am missing, or is this to be
expected? Can I check that it *is* actually using the G5 in native
64-bit mode? 

In addition, is there a faster way to check if a word has exactly 2-bits
set? Would there be any gain from trying to inline assembler to do just
this operation? 

Thanks in advance..

Gordon


-- 
Dr. Gordon Royle, http://www.csse.uwa.edu.au, gordon(AT)csse.uwa.edu.au
--



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]