Skip to content

Instantly share code, notes, and snippets.

@TABETA
Last active February 16, 2016 14:24
Show Gist options
  • Save TABETA/6701d171be9822360ea0 to your computer and use it in GitHub Desktop.
Save TABETA/6701d171be9822360ea0 to your computer and use it in GitHub Desktop.
ポインタが指し示すデータを一時変数に受けていたせいで最適化が効かなくなった例 ref: http://qiita.com/abedominal/items/f188737285c8d4e71a03
push ebp
mov ebp, esp
mov edx, DWORD PTR _b$[ebp]
mov ecx, DWORD PTR _r$[ebp]
movzx eax, WORD PTR [edx+8]
mov WORD PTR [ecx], ax
movzx eax, WORD PTR [edx+40]
mov WORD PTR [ecx+2], ax
movzx eax, WORD PTR [edx+72]
mov WORD PTR [ecx+4], ax
pop ebp
ret 8
push ebp
mov ebp, esp
push esi
mov esi, DWORD PTR _r$[ebp]
push edi
mov edi, DWORD PTR _b$[ebp]
movzx ecx, WORD PTR [edi]
movzx eax, WORD PTR [edi+8]
movzx edx, WORD PTR [edi+2]
mov WORD PTR [esi], ax
movzx eax, WORD PTR [ecx+edi+8]
mov WORD PTR [esi+2], ax
lea eax, DWORD PTR [ecx+edx]
movzx eax, WORD PTR [eax+edi+8]
pop edi
mov WORD PTR [esi+4], ax
pop esi
pop ebp
ret 8
class BufferAnalyzeDirect
{
public:
static const size_t msgOfs_ = offsetof(Header, messageByte);
static const size_t optOfs_ = offsetof(Header, optionByte);
void operator()(uint8_t* b, Result & r)
{
uint16_t msgByte = *reinterpret_cast<uint16_t*>(&b[msgOfs_]);
uint16_t optByte = *reinterpret_cast<uint16_t*>(&b[optOfs_]);
r.requestStatus = *reinterpret_cast<uint16_t*>(&b[4 + 4]);
r.optionCode = *reinterpret_cast<uint16_t*>(&b[4 + 4 + msgByte]);
r.count = *reinterpret_cast<uint16_t*>(&b[4 + 4 + msgByte + optByte]);
}
};
Before: 0.198654sec
After: 0.096776sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment