3 ms·
Every C++ compiler released in the last 30 years will trivially inline oneliner getter functions, member or not.
by Sharlin 5y ago
Every C++ compiler released in the last 30 years will trivially inline oneliner getter functions, member or not.
- nomel 5y agoTrue, but this is making the assumption that whatever pointer offsets, shifting, and masking that you have in your method, to extract the 9th bit in the 5th word of a 512 bit struct, will result in the same operations as the simple struct access. It very well could be so (certainly for some architectures, most likely not for others), but I don't think all this complication is justified when a struct is available, especially if you're someone writing code for hardware, where these concepts are more known/less scary.
- ncmncm 5y agoCompilers do generate instructions specified in functions correctly, inlined or no.
- nomel 5y ago> Compilers do generate instructions specified in functions correctly, inlined or no. Well, clearly that's not always the case, as shown in the article, and which is what started this comment chain. But, I'm not sure how you reached that interpretation. I'm saying that the code that you put into the function will result in some operations, whatever they may be, inline or not. The struct access will result in some operations. The those two sets of operations may be different. Some architectures have specialized instructions for bitfield access. There's a good chance that the complier won't convert the shenanigans in your method to those specialized instructions. Maybe! It requires an understanding of your particular situation. But some people's work exist in a context where this is a reasonable choice, for them.
- ncmncm 5y agoIf you make bitfield members, and access those in an inline function, and code generation for bitfields tickles a bug, the access being in an inline function won't help. If you code a shift-and-mask in an inline function, instead, your odds are better, same as if you made a macro for it.