Jump to content

Recommended Posts

jartim    0

Hello -


When the compiler generates code for "test_bit(x,y)" it very nicely generates a 'btfss' instruction.

However, when it generates code for "!test_bit(x,y)" it generates much more complex code because the ! is a logical operation not a bit-wise operation.


It would be nice if the compiler could spot that "!test_bit(x,y)" is really a 'btfsc' instruction instead.




Share this post

Link to post
Share on other sites
JorgeF    0




Any special reason to not use the bitwise not operator (~) or does it generate the same code^?

Using a logical operator induces the compiler to do a type cast on the result of "test_bit" to a logical type (char or int) before checking its value.

In strict 'C' the "!test_bit(...)" expression translates to something like "!(char)test_bit()" or "!(int)test_bit(...)"



How about droping the old "test-bit()" and similar macros and using direct bit indexing,

If I'm not worng its available since the first release of BoostC 7.xx

AFAIK the "test_bit", "set_bit" and "clear_bit" macros have been deprecated several years ago.





"semantics do matter!"


Best reards


Edited by JorgeF

Share this post

Link to post
Share on other sites

Your content will need to be approved by a moderator

You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.