I try out the below:
#include <bitset>
int main ()
{
std::bitset<32> bit32 { 0xf0f0f0f0 };
bit32[4].flip();
bit32[0] = 1;
}
Using GCC 4.8.1, I couldn't get it to inline, objdump gave me more or less:
401536: c7 45 e4 f0 f0 f0 f0 movl $0xf0f0f0f0,-0x1c(%ebp)
40153d: 8d 45 e8 lea -0x18(%ebp),%eax
401540: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp)
401547: 00
401548: 8d 55 e4 lea -0x1c(%ebp),%edx
40154b: 89 14 24 mov %edx,(%esp)
40154e: 89 c1 mov %eax,%ecx
401550: e8 93 13 00 00 call 4028e8 <__ZNSt6bitsetILj32EEixEj>
401555: 83 ec 08 sub $0x8,%esp
401558: 8d 45 e8 lea -0x18(%ebp),%eax
40155b: 89 c1 mov %eax,%ecx
40155d: e8 b2 12 00 00 call 402814 <__ZNSt6bitsetILj32EE9reference4flipEv>
401562: 8d 45 e8 lea -0x18(%ebp),%eax
401565: 89 c1 mov %eax,%ecx
401567: e8 10 13 00 00 call 40287c <__ZNSt6bitsetILj32EE9referenceD1Ev>
40156c: 8d 45 f0 lea -0x10(%ebp),%eax
40156f: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
401576: 00
401577: 8d 55 e4 lea -0x1c(%ebp),%edx
40157a: 89 14 24 mov %edx,(%esp)
40157d: 89 c1 mov %eax,%ecx
40157f: e8 64 13 00 00 call 4028e8 <__ZNSt6bitsetILj32EEixEj>
401584: 83 ec 08 sub $0x8,%esp
401587: 8d 45 f0 lea -0x10(%ebp),%eax
40158a: c7 04 24 01 00 00 00 movl $0x1,(%esp)
401591: 89 c1 mov %eax,%ecx
401593: e8 f0 12 00 00 call 402888 <__ZNSt6bitsetILj32EE9referenceaSEb>
401598: 83 ec 04 sub $0x4,%esp
40159b: 8d 45 f0 lea -0x10(%ebp),%eax
40159e: 89 c1 mov %eax,%ecx
4015a0: e8 d7 12 00 00 call 40287c <__ZNSt6bitsetILj32EE9referenceD1Ev>
4015a5: b8 00 00 00 00 mov $0x0,%eax
4015aa: 8b 4d fc mov -0x4(%ebp),%ecx
-O1, -O2, -O3 doesn't help either, it sort of optimize away the code entirely. Is there anyway I can avoid calling functions?
Why use bitset if you are worried about calling functions?
How about