fastest bitwise operator

Feb 28, 2010 at 3:10pm

well there are 2 questions that i want to ask

1. is it true that the speed of the bitwise operators are Equal, or are there differences (though negligible)

2. i was wondering which of this statement would run faster (even by a fraction of a nano)

//assume the last bit of t is 0, in other words both statements should give the //same result
statement 1:
t = t | 1

statement 2:
t = t + 1
Feb 28, 2010 at 4:24pm
1. Shifts are generally slower, but I think it depends on the amount of shifting.
2. The former.
Last edited on Feb 28, 2010 at 4:25pm
Feb 28, 2010 at 5:51pm

hey thanks for the reply, as for the second question, is it because that +1 is not a bitwise operator?
Feb 28, 2010 at 9:29pm
You need to read up on processor design.

ADD instructions need to work through the bit-adders, which takes more time to traverse than a simple OR gate per bit.

Also, you can get technical information on your favorite processor's instruction set, and it will list the machine codes and execution times for everything.

Hope this helps.
Feb 28, 2010 at 10:15pm
@pacerier: Some of the questions you are asking here today on this thread and others might have made sense 10-20 years ago, but with modern CPUs and compilers, they have very little meaning.

On x86, OR and ADD generally take the same amount of time.

Read through "Intel® 64 and IA-32 Architectures Optimization Reference Manual" available at http://www.intel.com/products/processor/manuals/ . Look at the section labelled "PROCESSOR PERSPECTIVES" to get a sense of what differences exist across just Intel's latest offerings.
Mar 1, 2010 at 9:57am

heys, thanks for the link
Topic archived. No new replies allowed.