Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ZackCQB

Rotate-byte instructions

This topic is 5321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any Rotate-bit instructions in C/C++? I mean the C/C++ equivalents of Assembly''s ROL and ROR instructions. Or am I stuck using embedded ASM?

Share this post


Link to post
Share on other sites
Advertisement
There isn''t.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites
it wouldn''t be hard to whip something up, but if you know how the ASM will be better anyway.

Share this post


Link to post
Share on other sites
Some compilers supply functions to do it. For example, MSVC uses the _rotl() and _rotr() functions. And because of the magic of compiler intrisics they turn into ROL and ROR assembly instructions when compiled in release mode.

Share this post


Link to post
Share on other sites
The good news is that MinGW, because it uses the Microsoft C runtime, has the _rotl() and _rotr() functions. So you can use them without resorting to inline assembly.

The bad news is that, even with optimization, MinGW doesn''t recognize _rotl() or _rotr() as intrinsics so they''ll show up in the machine code as function calls. (At least of MinGW 3.2 20020817-1, I haven''t upgraded my non-cygwin gcc builds on my system in a while.)

Share this post


Link to post
Share on other sites
I''m not going to speed here. This could take three hours for all I care, I just want to get it done.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!