This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

std::tuple assembly code

Hello

I try to add some generalization into the C++ project thus I use std::tuple to hold fields.

I'm investigating the difference in assembly code between std::get<1>(myClass.myTuple).read() and myClass.myField.read().

myField.read() is compiled as:
9A02                ldr        r2, [r13, #8]
E71F                b          #0x16a0
which is obvious and expected.

While std::get<1>(myTuple).read() is compiled as:
9B82                ldr        r3, [r13, #0x208]
695B                ldr        r3, [r3, #0x14]
42AB                cmp        r3, r5
D11B                bne        #0x1a3c

F8BD0210            ldrh.w     r0, [r13, #0x210]
E761                b          #0x1792

In theory std::get has to be evaluated in compile-time and the result should be similar in both cases.

For what reason do we get this additional comparison?
9B82                ldr        r3, [r13, #0x208]
695B                ldr        r3, [r3, #0x14]
42AB                cmp        r3, r5
D11B                bne        #0x1a3c
I cannot find any situation when the code follows this branch.

What can I do to simplify this code?
Can I change something in my C++ code to get a result equivalent to direct field access (myField.read())?
How can I force the compiler not to generate this additional piece of code?

Any help is appreciated.

/Adam