This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: make sure struct real_value's bitfields are packed


+#define REAL_EXP(REAL) \
+  ((int)((REAL)->uexp ^ (unsigned int)(1 << (EXP_BITS - 1))) \
+   - (1 << (EXP_BITS - 1)))

I hadn't come across this "(x ^ signbit) - signbit" idiom for
implementing sign-extension before.  Nice.

Yeah, I found it great as well when I learned about it in the binutils list :-)

I don't really like the idiom. It's obfuscated and requires a large constant, which is costly on some targets. Plain old (x << EXP_BITS) >> EXP_BITS is much more readable and already gets recognized by gcc as sign extension.

But it doesn't mean the same thing! To use your idiom, you need to know the size in bits of int. Messy.


Segher



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]