Fwd: Help to understand instructions
Kalle Olavi Niemitalo
kon@iki.fi
Wed Nov 7 19:24:00 GMT 2012
Sergey Ivanov <icegood1980@gmail.com> writes:
> else if (r < -halfL[i])
> 41f088: f2 0f 10 15 90 55 02 movsd xmm2,QWORD PTR
> [rip+0x25590] # 444620 <typeinfo name for
> SpeciesDependedMove<GeneralPolymerChain>+0x80> <<<<<<<<<<<<<<<question
> is here
[...]
> What implicit addressation via rip means? Is it kind of protection or
> is it bug of objdump?
It just loads some constant from memory. I suppose the compiler
did not emit a name for the constant in the debug information, so
objdump displays the nearest preceding symbol, which happens to be
typeinfo name for SpeciesDependedMove<GeneralPolymerChain>.
Somewhat reproduced like this:
#include <typeinfo>
struct Box
{
double L[4];
double halfL[4];
void MinCoordDistance(double &r, const int i) const;
};
const std::type_info &dummy = typeid(Box);
void Box::MinCoordDistance(double &r, const int i) const
{
if (r >= halfL[i])
r -= L[i];
else if (r < -halfL[i])
r += L[i];
}
Compiling this with g++ (Debian 4.7.1-7) 4.7.1, options -m64 -O3 -g -S:
.file "xmm.c"
.text
.Ltext0:
.align 2
.p2align 4,,15
.globl _ZNK3Box16MinCoordDistanceERdi
.type _ZNK3Box16MinCoordDistanceERdi, @function
_ZNK3Box16MinCoordDistanceERdi:
.LFB19:
.file 1 "xmm.c"
.loc 1 13 0
.cfi_startproc
.LVL0:
.loc 1 14 0
movslq %edx, %rdx
movsd (%rsi), %xmm0
movsd 32(%rdi,%rdx,8), %xmm1
ucomisd %xmm1, %xmm0
jae .L10
.loc 1 16 0
movsd .LC0(%rip), %xmm2 <<<<<<<<<<<<<<<question is here
xorpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe .L1
.loc 1 17 0
addsd (%rdi,%rdx,8), %xmm0
movsd %xmm0, (%rsi)
.L1:
rep
ret
.p2align 4,,10
.p2align 3
.L10:
.loc 1 15 0
subsd (%rdi,%rdx,8), %xmm0
movsd %xmm0, (%rsi)
ret
.cfi_endproc
.LFE19:
.size _ZNK3Box16MinCoordDistanceERdi, .-_ZNK3Box16MinCoordDistanceERdi
.globl dummy
.section .rodata
.align 8
.type dummy, @object
.size dummy, 8
dummy:
.quad _ZTI3Box
.weak _ZTI3Box
.section .rodata._ZTI3Box,"aG",@progbits,_ZTI3Box,comdat
.align 16
.type _ZTI3Box, @object
.size _ZTI3Box, 16
_ZTI3Box:
.quad _ZTVN10__cxxabiv117__class_type_infoE+16
.quad _ZTS3Box
.weak _ZTS3Box
.section .rodata._ZTS3Box,"aG",@progbits,_ZTS3Box,comdat
.type _ZTS3Box, @object
.size _ZTS3Box, 5
_ZTS3Box:
.string "3Box"
.section .rodata.cst16,"aM",@progbits,16
.align 16
.LC0:
.long 0
.long -2147483648
.long 0
.long 0
.text
... the rest omitted for brevity.
The "movsd .LC0(%rip), %xmm2" instruction loads a value from
.LC0, which is in the rodata.cst16 section and is thus a constant.
It looks like this constant is double[2] { -0.0, 0.0 } and the
function computes -halfL[i] by toggling the sign bit with xor.
The debug information in the assembly file does not refer to .LC0.
More information about the Gcc-help
mailing list