Jump to content

Recommended Posts

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.




Link to post
Share on other sites




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
Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji 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.

  • Create New...