#review Lessons on development of 64-bit C/C++ applications

2 minute read

글 주소는 http://www.viva64.com/en/l/

64비트 포팅 – 32비트 포인터들이여 안녕에서 소개한 20 issues of porting C++ code on the 64-bit platform보다 더 자세하게 설명한다.

설명도 자세하고 좋아 도움을 많이 받았다. 똑바로 일하라 (Rework)에서 다른 사람을 가르치는 걸 좋은 마케팅 방법으로 소개한다. 정말 그런 것 같다. 보고 있자니 PVS-Studio가 좋아져.

Lesson 01. What 64-bit systems are.

64bit 마이크로프로세서 아키텍처로는 IA64Intel 64가 유명. 당연히 서로 호환은 안 되고 담쌓고 지냄.

x86-64, AA-64, Hammer Architecture, AMD64, Yamhill Technology, EM64T, IA-32e, Intel 64, x64. 이거 다 같은 의미. 뭐 조금씩 다르거나 이렇게 된 역사나 이유가 있겠지만, 관심 없다. 귀찮아.

x86-64 아키텍처 주요 장점. x86 하위 호환성도 갖췄어요~

  • the 64-bit address space;
  • an extended register set;
  • a command set familiar to developers;
  • the capability to launch obsolete 32-bit applications in a 64-bit operating system;
  • the capability to use 32-bit operating systems.

오예~ Win64에서는 호출규약(calling convention)이 하나밖에 없다. Win32에서는 많았지. __stdcall, __cdecl, __fastcal, … 하지만 이거 때문에 32bit, 64bit 코드를 못 섞어 쓴다.

Lesson 2. Support of 32-bit applications in the 64-bit Windows environment

Win64에서 32bit 애플리케이션은 WoW64 x86 emulator를 사용해 실행한다. 평균 2% 성능 패널티.

Lesson 3. Porting code to 64-bit systems. The pros and cons

64bit로 포팅하면 5~15% 성능 향상을 기대할 수 있다. 5~10%는 64bit 시스템 약발. 1~5%는 WoW64 레이어를 사용 안 해서 얻을 수 있는 성능 향상. Photoshop CS4 64bit 버전이 32bit 버전보다 12% 더 빠르다고 adobe 아저씨들이 얘기함.

Lesson 4. Creating the 64-bit configuration

stack reserve size 기본값은 1MB. 자동으로 안 바꿔주니 2~3MB로 설정한다. 64bit에서는 스택 소모량이 32bit에 비해 많이 늘어나기 때문.

Lesson 5. Building a 64-bit application

바로 64bit 포팅 관련 경고를 고치지 마라. 64bit 에러 패턴에 대해 배우고 난 후에 고쳐라. 어설프게 잘못 고쳤다간 나중에 찾기 어려운 결함을 만들 수 있다.

size_t, ptrdiff_t와 같은 memsize-type이 64bit로 변경.

Lesson 6. Errors in 64-bit code

에러 카테고리

  • code based on wrong assumptions about type sizes (for example, an assumption that the pointer size is always 4 bytes);
  • code processing large arrays whose size is more than 2 Gbytes on 64-bit systems;
  • code responsible for data writing and reading;
  • code containing bit operations;
  • code with complex address arithmetic;
  • obsolete code;

Lesson 9. Pattern 1. Magic numbers

4, 32, 0x7fffffff, 0x80000000, 0xffffffff

Lesson 10. Pattern 2. Functions with variable number of arguments

ptrdiff_t, size_t 용 prefix로 I가 있다. Size Specification - MSDN

Lesson 26. Optimization of 64-bit programs

메모리 사용량 증가.

  • larger memory amounts to store some objects, for example pointers;
  • changes of the rules of data alignment in structures;
  • growth of stack memory consumption.

중간마다 나오는 PVS-Studio 소개는 애교. 이 정도는 봐줄 만하지. 아티클을 다 보고 나니 한번 써보고 싶어졌다. Trial version도 있잖아.

안 써도 상관없다. 글만 봐도 도움이 많이 된다.