Sign in to follow this  
tonymontana

How Much speed the usage of Bitwise operations bring ?

Recommended Posts

As we know with Bitwise operators we can make some opearations as a) multiplyin 2 or dividing by 2 b) swipping two variable values without a need of a third one c) changin some part of a Variable that hold many knowledges (for ex: taking the RED bytes from a COLORREF) all i am curious is How much Speed does Usage or bitwise operations bring?is it significant or unimportant?

Share this post


Link to post
Share on other sites
Quote:
Original post by tonymontana
As we know with Bitwise operators we can make some opearations as
a) multiplyin 2 or dividing by 2
b) swipping two variable values without a need of a third one
c) changin some part of a Variable that hold many knowledges
(for ex: taking the RED bytes from a COLORREF)

all i am curious is How much Speed does Usage or bitwise operations bring?is it significant or unimportant?


  • Very little. Your compiler will generally optimize such situations better than you can. Performance gains will be better made by profiling first, then adjusting your algorithms, and finally focusing on more specific optimizations, like such tiny things as bitwise operations.

  • Change your signature.

Share this post


Link to post
Share on other sites
I suppose it depends on what you substitute with bitwise operators. Working on a software renderer I found a huge performance increase when switching from floating point to fixed point, using left and right shift to multiply, devide and otherwise manipulate decimal numbers and store them as integers.

On the subject of your sig, change it please. This isnt an attack on the content of your sig, rather the size of it.

Share this post


Link to post
Share on other sites
Definetly agree with Washu.
Quote:
a) multiplyin 2 or dividing by 2

If you look at the actual code that your compiler produces, you'll notice that (if its a decent compiler) almost all int*2 or int/2 will be substituted with a bit-shift because the compiler is trying to optimize your code. Also, trying to bitshift a floating point types will produce unwanted results, so if you need to be accurate to some decimal places, then you'll need to multiply/divide anyways.
Quote:
b) swipping two variable values without a need of a third one

Unless you really need to save any extra memory you can, this isn't going to make any noticeable difference.
Being in the "for Beginners" section, I assume you've heard that bitwise operators are faster from books, which also mention the interger math is much faster than floating point. However, I believe that Pentium 4 and considerable level processors perform floating point math as fast or faster than interger math, so many of these optimizations are really not gaining you any time at all. Like Washu mentioned, the best idea is to profile your code and target the slowest sections. Optimizing a single algorithm can give you a huge performance boost if you were just coding it to make it work at first.
----------------------------------------------------------
I won't comment on the signature because I think enough has been said

Share this post


Link to post
Share on other sites
Quote:
Original post by tonymontana
no
because i am a free-man i will not change it
and because you are a moderator.ý have to say that iwill not post it much but i liked it.
any disagreement?
I can simply flip a bit in your profile and make it impossible for you to use a signature at all. If you don't change your signature volutarily, I'll do exactly that.

Share this post


Link to post
Share on other sites
well do your best...
You can't insist what you want because you are from gamedev...
you change it and i take another account and write a story to my
signature...
In my country,we chose to solve controversys with kindly behaviours.Not with insistence.
Your behaviour was more crap than my signature.Do your best ok??
you are stuff.You are king.you can change the world comeee onnnn....:))

Share this post


Link to post
Share on other sites
General advise: Nano-optimisation is evil. Unless you need the extra bit of performance (e.g. because you are targeting embedded hardware) you shouldn't care.

As for point c) - profile first. casting a COLORREF to a struct may be sufficient and more readable.

struct ArgbColor {
unsigned Blue : 8;
unsigned Green : 8;
unsigned Red : 8;
unsigned Alpha : 8;
};

COLORREF c1;

ArgbColor &c2 = reinterpret_cast<ArgbColor>(c1);
c2.Red = 128;


Share this post


Link to post
Share on other sites
Quote:
Original post by tonymontana
well do your best...
You can't insist what you want because you are from gamedev...
you change it and i take another account and write a story to my
signature...
In my country,we chose to solve controversys with kindly behaviours.Not with insistence.
Your behaviour was more crap than my signature.Do your best ok??
you are stuff.You are king.you can change the world comeee onnnn....:))


This argument doesn't even sound good when it comes from someone who speaks the language (English in this case) natively.

In case you haven't noticed, this is not a country we are talking about here, it is a message board. You do not necessarily have freedom of speech, and what would normally be social customs are basically elevated to the status of law.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by tonymontana
Your behaviour was more crap than my signature.Do your best ok??
you are stuff.You are king.you can change the world comeee onnnn....:))


Er. No. Your signature takes up a full page in quite a high resolution. For that, "Change your signature" in nothing more than bold font was pretty kind. There are unwritten rules on the internet (at least those parts where sp34k1n9 1ik3 7h1s is not considered cool) and you violated them. There was a time when people spent some time learning those rules but, alas, nowadays the best you can hope for is they learn them mistake by mistake, hopefully without much of a fuss.
So, stop this mess and pick a proper signature (and stop trying to make an issue out of it. Your supposed right for any signature you like contradicts the right of every serious user for readable threads). Otherwise, just leave and find a board where they like annoying signatures. Good luck with that though.

Share this post


Link to post
Share on other sites
tonymontana,

GameDev.net is a privately owned company, in which Dave is the "boss". GameDev has to adhere certain laws in the US to prevent from being fined, and because of that they made rules.

One of these rules(although not forced by law, but by communist GameDev) is that you follow any directions(Or orders) from the administrators and moderators. Not following these rules, might result in being suspended, banned or your entire IP range blackholed.

GameDev isn't a democracy, it's communist. And besides, the overall community hates the kind of behaviour you are displaying in this thread.

Toolmaker

Share this post


Link to post
Share on other sites
I run at the second highest standard resolution (1280 by 1024, with 1600 by 1200 being the highest standard resolution). Your signature took a page of my screen. Being a shit about it and not just changing your signature when it's that long is immature and stupid. I do hope Dave gets on that bit toggling soon.

Share this post


Link to post
Share on other sites
Quote:
Original post by tonymontana
well do your best...
You can't insist what you want because you are from gamedev...
you change it and i take another account and write a story to my
signature...

Yeah, because GameDev isn't able to block by IP address...
If you create a new account, and its verified that you did it just to sidestep Dave, you're just asking to get your IP range blocked, making it impossible for you to even view the forums.

Quote:
Original post by tonymontana
In my country,we chose to solve controversys with kindly behaviours.Not with insistence.
Your behaviour was more crap than my signature.Do your best ok??
you are stuff.You are king.you can change the world comeee onnnn....:))

If you have that attitude in Real Life, you're in for a hard time...

Back to the actual question:
Quote:
Original post by tonymontana
a) multiplyin 2 or dividing by 2
b) swipping two variable values without a need of a third one
c) changin some part of a Variable that hold many knowledges
(for ex: taking the RED bytes from a COLORREF)

a) The compiler will do that for you, don't worry about it. All it does is make your code harder to understand.
b) Using the XOR technique is SLOW. Its totally breaks the CPUs pipeline. Don't do it. Just use a tempoary unless you have an exceptionally good reason.
c) Bitwise operators are the only way to do things here.

Generally, don't worry about tiny optimizations like this, profile your code, and see if its a problem. If it is (which 99.99% of the time it won't be) then you an go ahead and try to optimize it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
... There are unwritten rules on the internet ...


Well, it seems they have been written some days ago (or was it years ?) : the netiquette guidelines, RFC 1855.

This is still not really on-topic :)

Regarding the question of tonymontana : shift operations are faster than multiply or divide by their equivalent (power of two). But they are also mush less readable than their counterparts. Not to mention that any good compiler will optimize a "* 32" by itself (so their is no point of using a >> N or << N where N is a constant which is known at compile time). My advice: this is at least micro-optimization. It may be useful in a software renderer inner loop. May be. Not sure...

Regards,

Share this post


Link to post
Share on other sites
First of all it is a debt to thank all of the poster that wrote about actual issue(Bitwise operations).
i think i would just use them when passing arguments to functions
as ShowCreatureImage(ANIM_LOOP|ANIM_CONTINUE ) vb...as dword flags..
And i want to say something to the poster who cared about my signature.Ý changed it (Kýçýnýza kýna yakýn...:)) but i didn't changed by the insistence of you.I have a private message that wass kindly and reasonable.I think you can never get somewhere with that style(in game programming or somewhere else )..what was that
You left all the things on earth and started to attack me..)
Anyway the post about immaturity and stupidity was really a annoying thing.)i am 22 and believe me i am intellegent enough..(chess champion,civil engineer,got degrees on exams...that all requires it.).and comparing to your replys i am more mature .You should admit that to yourself.Ýf i saw a signature that is long (and the owner says he will not post it because he is already aware of it's length)i wouldn't say anything..

ok that is the end of it i didn't blame or attack anyone.And i want to stop it noone will write anything on that post about my signature...if you want post me in private .
Thanks for your reading..(by the time i spend to defend of myself to your unneccessary blames i could learn something new)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Toolmaker
...not forced by law, but by communist GameDev) is that...

GameDev isn't a democracy, it's communist. And besides...


Well, this was news. I would have expected GDNet to be anything but that. *LOL*

Share this post


Link to post
Share on other sites
Where was the attack? I simply informed you that if you chose to defy a moderator's instruction to change your signature, you'd lose the privilege of using a signature. I could have simply banned you instead. Neither my nor Washu's post was rude. They weren't overly polite, either, but common sense and netiquette - as well as the length of time you've been here - should have told you that a signature that size was inappropriate in the first place.

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
GameDev isn't a democracy, it's communist.


Say what?!
If it were communist they'd be rationing out threads and everyone's icon would be a picture of our glorious leader.

GameDev is private property where the property owner makes the rules. Plus people pay a fee to become GDNet+ members and get extra services. That is capitalism baby!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this