And 64-Bit Windows® Operating Systems

And 64-Bit Windows® Operating Systems

DEV398 Porting Applications to Windows® for AMD64 Technology Mike Wall MTS Software Engineer, AMD Agenda AMD64 technology AMD64 Instruction Set Architecture AMD OpteronTM and AMD AthlonTM 64 Processor overview Platform features and multiprocessing 64-bit Windows® for AMD64 What to port, and how Maximize multiprocessor performance Tools and additional resources Windows® and AMD64 Technology Unifying theme: Compatibility Processor: Native hardware support for 32-bit and 64-bit x86 code OS: 64-bit Windows® runs 32-bit and 64- bit applications side by side, seamlessly Code: A single C/C++ source code tree compiles to both 32-bit and 64-bit binaries AMD64 Technology AMD64 Instruction Set Architecture AMD64 Technology AMD64 Programmer’s Model 63 31 15 7 0 In x86 Added by AMD64 RAX EAX AH AL 127 0 79 0 SS XMM0 GG EAX xx SS PP 88 EE RR 77 XMM7 EDI XMM8 R8 XMM8 EIP XMM15 R15 AMD64 Technology AMD64 Instruction Set Architecture Support for all x86 instruction extensions MMXTM, SSE, SSE2, 3DNow!TM Full performance with all code Native 32-bit x86 mode Enhanced capability in 64-bit mode 64-bit general purpose registers 64-bit addressing Twice as many general purpose registers Twice as many SSE registers Same familiar x86 instructions AMD64 Technology AMD OpteronTM and AMD AthlonTM 64 Processor Overview AMD64 Technology AMD64 CPU block diagram DDR Memory Controller L1 X86-based Instruction Cache 64-bit L2 Processor Cache Core L1 Data Cache HyperTransport™ . AMD64 Technology Integrated memory controller The word to remember: Latency 1,000’s of MHz 100’s of MHz & Always Increasing & Not Improving MemoryMemory MemoryMemory ControllerController ControllerController AMDAMD Athlon™Athlon™ 64 64 LegacyLegacy x86x86 ChipsetChipset Integrated Memory Controller runs at CPU Core Frequency As CPU frequency increases, the integrated memory controller becomes more efficient, but the Legacy x86 memory controller does not. AMD64 Technology HyperTransportTM Interface TM 16x16 8x8 AMD Athlon 64 TM Graphics HyperTransport HyperTransport I/OI/O HubHub processor @ 6.4GB/s Tunnel @ 800MB/s HyperTransportHyperTransportTM TechnologyTechnology AttributesAttributes UnidirectionalUnidirectional (a(a pairpair ofof links)links) DDRDDR--likelike performanceperformance (800MHz(800MHz == 1600MT/sec)1600MT/sec) 44 bytesbytes widewide …… 6.4GB/sec6.4GB/sec bandwidthbandwidth AMD64 Technology Platform features and multiprocessing AMD64 Technology Performance desktop PC TM AMDAMD Athlon AthlonTM6464 754 PGA 754µ µPGA 16x16 HyperTransportTM @ 1600 MT/s 266/333/400MHz 32bits @ 64-Bit Unbuffered DDR 533Mhz AMD-8151TMTM AGP8X AMD-8151 Graphics Tunnel Graphics Tunnel PCI 8x8 HyperTransport @ 400MT/s 32bits @ 33Mhz TM AMD-8111AMD-8111TM I/O Hub I/O Hub LPC FLASH USB 1.1 SIO USB 2.0 UDMA133 SMbus 1.1 SMbus 2.0 ACR MII AC’97 AC’97 CODEC Audio AMD64 Technology High performance workstation AMD Opteron AMDAMD Opteron™ Opteron™ AMD Opteron 200-333MHz 940 µPGA 16x16 cHyperTransport™ @ 940 µPGA 200-333MHz 144-Bit Reg DDR 940 µPGA 1600MT/s 940 µPGA 144-Bit Reg DDR 16x16 HyperTransport @ 16x16 HyperTransport @ 1600MT/s 1600MT/s 32bits @ 64bits @ TM 100Mhz PCI-X 533Mhz AMD-8151 TM AMD-8131TMTM AGP8X AMD-8151 AMD-8131 Graphics Tunnel PCIX Tunnel Graphics Tunnel PCIX Tunnel 1000 BaseT 8x8 HyperTransport @ 400MT/s Gbit Ethernet Legacy PCI U320 SCSI TM SCSI AMD-8111AMD-8111TM I/O Hub I/O Hub LPC FLASH SIO USB1.0,2.0 AC97 UDMA133 10/100 Ethernet 10/100 Phy 100 BaseT AMD64 Technology 4P server Possible expansion to another 4 processors 200-333MHz 16x16 cHyperTransport™ @ 144-Bit Reg DDR 1600MT/s AMD Opteron AMDAMD Opteron™ Opteron™ AMD Opteron 200-333MHz 940 µPGA Coherent 940940 µ µPGAPGA 144-Bit Reg DDR 940 µPGA HyperTransport Links 16x16 cHyperTransport @ 16x16 cHyperTransport @ 1600MT/s 1600MT/s AMD Opteron AMD Opteron 200-333MHz 200-333MHz AMD Opteron 16x16 cHyperTransport @ AMD Opteron 144-Bit Reg DDR 144-Bit Reg DDR 940940 µ µPGAPGA 1600MT/s 940940 µ µPGAPGA 16x16 HyperTransport @ 1600MT/s 8x8 HyperTransport @ 64bits @ 64bits @ 400MT/s 133Mhz TM 133Mhz AMD-8131 TM PCI-X AMD-8131 PCI-X HypTrans-PCI-X Legacy PCI HotPlug HypTrans-PCI-X HotPlug PCI VGA Graphics 8x8 HyperTransport @ TM 1600MT/s AMD-8111 TM AMD-8111 FLASH I/O Hub I/O Hub 64bits @ TM 64bits @ 1000 BaseT LPC 66Mhz AMD-8131 TM 66Mhz SIO AMD-8131 Gbit Ethernet Zircon BMC PCI-XHyperTransport PCI-X HyperTransport U320 USB1.0,2.0 PCI-X SCSI AC97 100 BaseT PCI-X UDMA100 1000 BaseT 10/100 Ethernet Management LAN Gbit Ethernet 64-bit Windows® for AMD64 Technology 64-bit Windows® for AMD64 32-bit and 64-bit on a single platform An AMD64-based Processor can run both 32- and 64-bit Windows® operating systems STARTSTART BOOTBOOT UPUP UsingUsing 3232 bitbit BIOSBIOS 32-bit LookLook 64-bit LoadLoad 3232 bitbit OSOS LoadLoad 6464 bitbit OSOS atat OSOS RunRun 3232 bitbit RunRun 3232 && 6464 ApplicationsApplications bitbit appsapps 64-bit Windows® for AMD64 Full backward compatibility with 32-bit Existing 32-bit applications run great WoW64 = Windows-on-Windows 64 32-bit applications run on the hardware no emulation anywhere with AMD64 Performance in WoW64 is not impaired slight overhead for OS calls sometimes compensated by faster OS Users can keep all their existing software 64-bit Windows® for AMD64 Technology WoW64 operation and compatibility 32-bit thread 64-bit thread 32-bit32-bit ApplicationApplication 6464-bit-bit ApplicationApplication WoW64 6464-bit-bit OperatingOperating SystemSystem 64-bit Device Drivers AMD64: What to port, and how What apps will benefit from 64 bits? Large memory! essentially unlimited virtual address space physical memory only limited by platform 8GB per CPU is expected to be common next year More registers and “big number” math Codecs, simulation, 3D, games Compression, encryption, finance Not everyone needs to port: 32-bit runs fine! AMD64: What to port, and how Some code really must be ported Drivers device drivers must “match the OS” 64-bit OS requires 64-bit drivers there are presentations focused on drivers Code libraries and .dll’s customers who port will require 64-bit versions You can’t mix 32 and 64-bit application code but OS IPC mechanisms work 32 ÅÆ 64 AMD64: What to port, and how Moving up to 64-bit mode A single source code tree Æ compile to 32-bit and 64-bit Windows® platforms! Programming for 64-bit Windows® is basically the same as 32-bit same API, a few different data types Types int and long remain 32 bits Only pointers expand to 64 bits “P64” Use size_t and new polymorphic types AMD64: What to port, and how Use portable / scalable data types Use int where only 32 bits are needed e.g. Index variable for a small array Use size_t where array may grow beyond the 32-bit limit Special polymorphic types for pointer math INT_PTR, UINT_PTR, LONG_PTR, ULONG_PTR These types scale to match the 32/64-bit mode AMD64: What to port, and how Code example #1 char *p; long Lval; Lval = p; // bad! truncated in 64-bit mode char *p; LONG_PTR Lval; // either 32 bits or 64 bits Lval = p; // works fine AMD64: What to port, and how Code example #2 for (int i = 0; i < S; i++) { A[i] += 3; } If S may exceed 32 bits, use: for (size_t i = 0; i < S; i++) { A[i] += 3; } AMD64: What to port, and how Code example #3 objectStart = (PVOID) ((ULONG)objectStart | 1); This is bad because we are casting a pointer to a long; it will get truncated when we compile for 64-bit objectStart = (PVOID) ((ULONG_PTR)objectStart | 1); Proper use of polymorphic data type AMD64: What to port, and how Assorted portability tips -1 != 0xFFFFFFFF (just use “-1”) Many Windows® apps use DWORD a DWORD is always 32 bits, make sure that is really what you want Use %p in a printf, to print a pointer Data alignment can affect performance there are alignment requirements in the ABI structure padding can affect portability AMD64: What to port, and how Explicitly sized types INT64 and UINT64 are always 64 bits INT32 and UINT32 are always 32 bits Think carefully before using these most often you really want INT_PTR etc. explicit size type are useful for shared data but you can typically just use int and long AMD64: What to port, and how Microsoft C compiler and libraries The 64-bit compiler emits SSE / SSE2 code The string and memory functions are optimized and should be used AMD provides optimized math libraries: ACML = AMD Core Math Libraries (BLAS, FFT, LAPACK, and more) AMD64: What to port, and how Microsoft C compiler and libraries (2) In-line assembly code is not supported put assembly code in a separate MASM file Compiler intrinsics are provided for effectively in-lining many SSE functions and other special functions AMD64: What to port, and how Porting x86 assembly code Assembly code is straightforward to port And worth doing for performance reasons In-line assembly no longer supported Use separate MASM file, compile .obj and link Take advantage of the new registers! GPR regs r8-r15, SSE regs xmm8-xmm15 New 64-bit stack frames, calling convention Carefully read the ABI document! ÆÆ “AMD64 Software Conventions” AMD64: What to port, and how Using the 64-bit registers 32-bit mov edx, 66 mov eax, [ecx + edx*4] mov ecx, [eax] //32-bit pointer 64-bit mov r10, 66 mov rax, [rcx + r10*8] mov rcx, [rax] //64-bit pointer AMD64: What to port, and how 64-bit regs: upper half gets cleared 32-bit code might look like this xor edx, edx // clear all bits mov dx, 66 // load 16-bit value 64-bit code looks like this mov edx, 66 // load 32-bit value // upper half is cleared AMD64: What to port, and how Function call args passed in regs 32-bit code might look like this push

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    51 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us