0
뭔가 : 컴파일러는 일반적으로 여러 연속 메모리 복사본을 하나의 작업으로 압축 할 수 있습니까? 다음과 같은
struct Vec2
{
int x, y;
};
struct Bounds
{
int left, top, right, bottom;
};
int main()
{
Vec2 topLeft = {5, 5};
Vec2 bottomRight = { 10, 10 };
Bounds bounds;
//___Here is copy operation
//___Note they're not in contiguous order, harder for the compiler?
bounds.left = topLeft.x;
bounds.bottom = bottomRight.y;
bounds.top = topLeft.y;
bounds.right = bottomRight.x;
}
그 네 가지 과제
은과 같이 할 수있다 :- 는 컴파일러에서 최적화 일반적으로 수 있습니까 :
memcpy(&bounds, &topLeft, sizeof(Vec2)); memcpy(&bounds.right, &bottomRight, sizeof(Vec2));
나는 두 가지를 궁금하네요 이 방법?
- 복사 메모리가 O (n)이므로 4 개의 정수가 2 개의 정수 쌍으로 복사됩니까?
내가 네 사본에 대해 다음 분해 결과를 얻었다 :
bounds.left = topLeft.x;
00007FF642291034 mov dword ptr [bounds],5
bounds.bottom = bottomRight.y;
00007FF64229103C mov dword ptr [rsp+2Ch],0Ah
bounds.top = topLeft.y;
00007FF642291044 mov dword ptr [rsp+24h],5
bounds.right = bottomRight.x;
00007FF64229104C mov dword ptr [rsp+28h],0Ah
그리고 혼동, 두 memcpys은 첫 번째와 두 번째에 대해 서로 다른 지침이를, 나는이 이해가 안 :
memcpy(&bounds, &topLeft, sizeof(Vec2));
00007FF64229105E mov rbx,qword ptr [topLeft] // This is only one instruction
memcpy(&bounds.right, &bottomRight, sizeof(Vec2));
00007FF642291063 mov rdi,qword ptr [bottomRight] // Compared to 6?
00007FF642291068 mov qword ptr [bounds],rbx
00007FF64229106D mov qword ptr [rsp+28h],rdi
00007FF642291072 jmp main+7Eh (07FF64229107Eh)
00007FF642291074 mov rdi,qword ptr [rsp+28h]
00007FF642291079 mov rbx,qword ptr [bounds]
"compiler"는 단일 항목이 아닙니다. 여러 플랫폼에 여러 버전이 포함 된 여러 컴파일러가 있습니다. 어떤 권위자라도 지나치게 광범위한 질문에 답할 수있는 사람은 없을 것 같습니다. 해결하고자하는 실제 정량화 가능한 문제를 설명하는 구체적인 답을 할 수있는 엔터티로서 질문을 다시 말해야합니다. – xaxxon