SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
64 bits for developers


       By Roman Okolovich
Introduction
   x86-64 is a superset of the x86 instruction set
    architecture. x86-64 processors can run existing 32-bit or
    16-bit x86 programs at full speed, but also support new
    programs written with a 64-bit address space and other
    additional capabilities.
   The x86-64 specification was designed by Advanced
    Micro Devices (AMD), who have since renamed it
    AMD64. This was the first time any company other than
    Intel made significant additions to the IA-32 architecture.
   x86-64 is backwards compatible with 32-bit code without
    any performance loss.
x64 architectural features
   64-bit integer capability: All general-purpose registers (GPRs) are expanded from 32 bits to 64 bits, and all arithmetic and logical operations,
    memory-to-register and register-to-memory operations, etc. can now operate directly on 64-bit integers. Pushes and pops on the stack are always in
    8-byte strides, and pointers are 8 bytes wide.
   Additional registers: In addition to increasing the size of the general-purpose registers, the number of named general-purpose registers is increased
    from eight (i.e. eax,ebx,ecx,edx,ebp,esp,esi,edi) in x86-32 to 16. It is therefore possible to keep more local variables in registers rather than on the
    stack, and to let registers hold frequently accessed constants; arguments for small and fast subroutines may also be passed in registers to a greater
    extent. However, AMD64 still has fewer registers than many common RISC processors (which typically have 32–64 registers) or VLIW-like machines
    such as the IA-64 (which has 128 registers).
   Additional XMM (SSE) registers: Similarly, the number of 128-bit XMM registers (used for Streaming SIMD instructions) is also increased from 8 to
    16.
   Larger virtual address space: Current processor models implementing the AMD64 architecture can address up to 256 TB (281,474,976,710,656
    bytes)[4] of virtual address space. This limit can be raised in future implementations to 16 EB (18,446,744,073,709,551,616 bytes). This is compared
    to just 4 GB (4,294,967,296 bytes) for 32-bit x86. This means that very large files can be operated on by mapping the entire file into the process'
    address space (which is sometimes faster than working with file read/write calls), rather than having to map regions of the file into and out of the
    address space.
   Larger physical address space: Current implementations of the AMD64 architecture can address up to 1 TB (1,099,511,627,776 bytes) of RAM; the
    architecture permits extending this to 4 PB (4,503,599,627,370,496 bytes) in the future (limited by the page table entry format). In legacy mode,
    Physical Address Extension (PAE) is included, as it is on most current 32-bit x86 processors, allowing access to a maximum of 64 GB
    (68,719,476,736 bytes).
   Instruction pointer relative data access: Instructions can now reference data relative to the instruction pointer (RIP register). This makes position
    independent code, as is often used in shared libraries and code loaded at run time, more efficient.
   SSE instructions: The original AMD64 architecture adopted Intel's SSE and SSE2 as core instructions. SSE3 instructions were added in April 2005.
    SSE2 replaces the x87 instruction set's IEEE 80-bit precision with the choice of either IEEE 32-bit or 64-bit floating-point mathematics. This provides
    floating-point operations compatible with many other modern CPUs. The SSE and SSE2 instructions have also been extended to operate on the eight
    new XMM registers. SSE and SSE2 are available in 32-bit mode in modern x86 processors; however, if they're used in 32-bit programs, those
    programs will only work on systems with processors that have the feature. This is not an issue in 64-bit programs, as all AMD64 processors have
    SSE and SSE2, so using SSE and SSE2 instructions instead of x87 instructions does not reduce the set of machines on which x64 programs can be
    run. SSE and SSE2 are generally faster than, and duplicate most of the features of, the traditional x87 instructions, MMX, and 3DNow!.
   No-Execute bit: The "NX" bit (bit 63 of the page table entry) allows the operating system to specify which pages of virtual address space can contain
    executable code and which cannot. An attempt to execute code from a page tagged "no execute" will result in a memory access violation, similar to
    an attempt to write to a read-only page. This should make it more difficult for malicious code to take control of the system via "buffer overrun" or
    "unchecked buffer" attacks. A similar feature has been available on x86 processors since the 80286 as an attribute of segment descriptors; however,
    this works only on an entire segment at a time. Segmented addressing has long been considered an obsolete mode of operation, and all current PC
    operating systems in effect bypass it, setting all segments to a base address of 0 and a size of 4 GB (4,294,967,296 bytes). AMD was the first x86-
    family vendor to implement no-execute in linear addressing mode. The feature is also available in legacy mode on AMD64 processors, and recent
    Intel x86 processors, when PAE is used.
   Removal of older features: A number of "system programming" features of the x86 architecture are not used in modern operating systems and are
    not available on AMD64 in long (64-bit and compatibility) mode. These include segmented addressing (although the FS and GS segments are
    retained in vestigial form for use as extra base pointers to operating system structures)[5], the task state switch mechanism, and Virtual 8086 mode.
    These features do of course remain fully implemented in "legacy mode," thus permitting these processors to run 32-bit and 16-bit operating systems
    without modification.
Virtual address space details
   Although virtual addresses are 64 bits wide in 64-bit mode, current implementations (and
    any chips known to be in the planning stages) do not allow the entire virtual address space
    of 16 EB (18,446,744,073,709,551,616 bytes) to be used. Most operating systems and
    applications will not need such a large address space for the foreseeable future (for
    example, Windows implementations for AMD64 are only populating 16 TB
    (17,592,186,044,416 bytes), or 44 bits' worth).
   AMD therefore decided that, in the first implementations of the architecture, only the least
    significant 48 bits of a virtual address would actually be used in address translation (page
    table lookup).




                     Current 48-bit implementation   56-bit implementation   64-bit implementation
Advantages of using x64
   Compiling of a 64-bit code increases performance
       the expected performance growth caused by an ordinary
        compilation is 5-15%
           Adobe Company claims that new 64-bit "Photoshop CS4" is 12%
            faster than its 32-bit version
   Some programs dealing with large data arrays may
    increase their performance when expanding address
    space
   Using ptrdiff_t, size_t and derivative types allows to
    optimize program code up to 30%.
Support x64 in Visual Studio (1 of 2)
   /wp64 - Detects 64-bit portability problems on types that are also marked with the
    __w64 keyword.
   The /Wp64 compiler option and __w64 keyword are deprecated and will be
    removed in a future version of the compiler.
   Instead of using this option and keyword to detect 64-bit portability issues, use a
    Visual C++ compiler that targets a 64-bit platform. For more information, see 64-Bit
    Programming with Visual C++.
Support x64 in Visual Studio (2 of 2)
   How to: Configure Visual C++ Projects
    to Target 64-Bit Platforms
       Click Configuration Manager to open the
        Configuration Manager Dialog Box.
       Click the Active Solution Platform list,
        and then select the <New…> option to
        open the New Solution Platform Dialog
        Box.
       Click the Type or select the new
        platform drop-down arrow, and then
        select a 64-bit platform.
       Click OK. The platform you selected in the
        preceding step will appear under Active
        Solution Platform in the Configuration
        Manager dialog box.
       Click Close in the Configuration
        Manager dialog box, and then click OK in
        the <Projectname> Property Pages
        dialog box.
Data model
    • ISO/IEC 9899:1990, Programming                          Data Type   LP32   ILP32   ILP64   LLP64   LP64

      Languages - C (ISO C) left the definition of    char                 8       8       8       8      8

      the short int, the int, the long int, and the   short                16     16      16      16      16
                                                      int32                               32
      pointer to avoid constraining hardware
                                                      int                  16     32      64      32      32
      architectures that might benefit from
                                                      long                 32     32      64      32      64
      defining these data types independently         long long (int64)                                   64
      from one another.                               pointer              32     32      64      64      64
    • The relationship between the
      fundamental data types can be
      expressed as:
                         sizeof(char) <= sizeof(short) <= sizeof(int)
                                     <= sizeof(long) = sizeof(size_t)
    • Notation: int (I), long (L), and pointer (P)

    • ILP32 is used in Win32
    • LLP64 is used in Win64
    • LP64 is used in UNIX


8
General issues relating to x64 (1 of 4)
   An int and a long are 32-bit values on 64-bit Windows
    operating systems.
       You should not to assign pointers to 32-bit variables. Pointers
        are 64-bit on 64-bit platforms, and you will truncate the pointer
        value if you assign it to a 32-bit variable.
    sizeof(int) = sizeof(long) = sizeof(pointer)



                                     Common assumptions about the relationships
                                     between the fundamental data types may no
                                        longer be valid in a 64-bit data model
General issues relating to x64 (2 of 4)
   size_t, time_t, and ptrdiff_t (STL) are 64-bit values on 64-bit
    Windows operating systems.
                     Fine if bigValue <= UINT_MAX


                                                                                           Don’t mix up size_t and
                                                                                          fundamental data types.
     size_t n = bigValue;                                                                unsigned int <= UINT_MAX

     for(unsigned i = 0; i != n; ++i)
     { ... }
                                                    size_t n = bigValue;
                Result value will be                unsigned index = 0;
                    truncated
                                                    for(size_t i = 0; i != n; ++i)
size_t a;                                           {
int b = (int)a;                                       array[index++] = 10;
int b = (int)(a);                                   }
int b = int(a);                                       Use only size_t because an array
                                                          can contains more when
int b = static_cast<int>(a);                                 UINT_MAX items
General issues relating to x64 (3 of 4)
   The %x (hex int format) printf modifier will not work as
    expected on a 64-bit Windows operating system. It will
    only operate on the first 32 bits of the value that is
    passed to it.
       Use %I32x to display an integer on a Windows 32-bit
        operating system.
       Use %I64x to display an integer on a Windows 64-bit
        operating system.
       The %p (hex format for a pointer) will work as expected on a
        64-bit Windows operating system.
General issues relating to x64 (4 of 4)
   data alignment
       The MyStruct2 structure size equals to 12 bytes in a 32-bit program, and in a 64-bit
        program, it is only 16 bytes. Therewith, from the point of view of data access efficiency,
        the MyStruct1 and MyStruct2 structures are equivalent.
   common recommendation is the following: the objects should be distributed in
    descending order of their size.
References
   x86-64 (wikipedia)
   64-bit Programming (How Do I in Visual C++)
   64-Bit Programming with Visual C++
   FAQ for Development on 64-bit Windows
   Common Visual C++ 64-bit Migration Issues
   Viva64, a tool for porting your applications to 64-bit
    platforms
   Optimization of 64-bit programs

Contenu connexe

Tendances

Pentium (80586) Microprocessor By Er. Swapnil Kaware
Pentium (80586) Microprocessor By Er. Swapnil KawarePentium (80586) Microprocessor By Er. Swapnil Kaware
Pentium (80586) Microprocessor By Er. Swapnil KawareProf. Swapnil V. Kaware
 
The reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memoryThe reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memoryPVS-Studio
 
Efficient Fpe Algorithm For Encrypting Credit Card Numbers
Efficient Fpe Algorithm For Encrypting Credit Card NumbersEfficient Fpe Algorithm For Encrypting Credit Card Numbers
Efficient Fpe Algorithm For Encrypting Credit Card NumbersIOSR Journals
 
Addressing mode of 80286 microprocessor
Addressing mode of 80286 microprocessorAddressing mode of 80286 microprocessor
Addressing mode of 80286 microprocessorpal bhumit
 
Addressing modes of 80386
Addressing modes of 80386Addressing modes of 80386
Addressing modes of 80386PDFSHARE
 
Address translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAddress translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAniket Bhute
 
Unit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idtUnit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idtKanchanPatil34
 
DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...
DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...
DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...Journal For Research
 
Memory segmentation-of-8086
Memory segmentation-of-8086Memory segmentation-of-8086
Memory segmentation-of-8086mudulin
 

Tendances (18)

Js2517181724
Js2517181724Js2517181724
Js2517181724
 
Pentium (80586) Microprocessor By Er. Swapnil Kaware
Pentium (80586) Microprocessor By Er. Swapnil KawarePentium (80586) Microprocessor By Er. Swapnil Kaware
Pentium (80586) Microprocessor By Er. Swapnil Kaware
 
X86 operation types
X86 operation typesX86 operation types
X86 operation types
 
Memory mgmt 80386
Memory mgmt 80386Memory mgmt 80386
Memory mgmt 80386
 
The reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memoryThe reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memory
 
Micropro
MicroproMicropro
Micropro
 
Intel 80486 Microprocessor
Intel 80486 MicroprocessorIntel 80486 Microprocessor
Intel 80486 Microprocessor
 
Efficient Fpe Algorithm For Encrypting Credit Card Numbers
Efficient Fpe Algorithm For Encrypting Credit Card NumbersEfficient Fpe Algorithm For Encrypting Credit Card Numbers
Efficient Fpe Algorithm For Encrypting Credit Card Numbers
 
64bitsprocessor
64bitsprocessor64bitsprocessor
64bitsprocessor
 
Addressing mode of 80286 microprocessor
Addressing mode of 80286 microprocessorAddressing mode of 80286 microprocessor
Addressing mode of 80286 microprocessor
 
Addressing modes of 80386
Addressing modes of 80386Addressing modes of 80386
Addressing modes of 80386
 
Address translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAddress translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhute
 
Unit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idtUnit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idt
 
Aes
AesAes
Aes
 
DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...
DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...
DESIGN AND VHDL IMPLEMENTATION OF 64-POINT FFT USING TWO STRUCTURE 8-POINT FF...
 
Microprocessor lecture 2
Microprocessor lecture   2Microprocessor lecture   2
Microprocessor lecture 2
 
Mpmc
MpmcMpmc
Mpmc
 
Memory segmentation-of-8086
Memory segmentation-of-8086Memory segmentation-of-8086
Memory segmentation-of-8086
 

En vedette

Intel core presentation mnk
Intel core presentation mnkIntel core presentation mnk
Intel core presentation mnkkondalarao7
 
Intel 64bit Architecture
Intel 64bit ArchitectureIntel 64bit Architecture
Intel 64bit ArchitectureMotaz Saad
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly languageAhmed M. Abed
 
The 7 Habits of Breakthrough Innovators
The 7 Habits of Breakthrough InnovatorsThe 7 Habits of Breakthrough Innovators
The 7 Habits of Breakthrough InnovatorsAmy Jo Kim
 

En vedette (7)

Intel core presentation mnk
Intel core presentation mnkIntel core presentation mnk
Intel core presentation mnk
 
x86
x86x86
x86
 
Intel 64bit Architecture
Intel 64bit ArchitectureIntel 64bit Architecture
Intel 64bit Architecture
 
X86 Architecture
X86 Architecture X86 Architecture
X86 Architecture
 
Multi core processor
Multi core processorMulti core processor
Multi core processor
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
 
The 7 Habits of Breakthrough Innovators
The 7 Habits of Breakthrough InnovatorsThe 7 Habits of Breakthrough Innovators
The 7 Habits of Breakthrough Innovators
 

Similaire à 64 bits for developers

Lesson 1. What 64-bit systems are
Lesson 1. What 64-bit systems areLesson 1. What 64-bit systems are
Lesson 1. What 64-bit systems arePVS-Studio
 
Cpu 64x architecture
Cpu 64x architectureCpu 64x architecture
Cpu 64x architectureAmmAr mobark
 
64bit_Linux-Myths_and_Facts_for AMD_Processors.pdf
64bit_Linux-Myths_and_Facts_for AMD_Processors.pdf64bit_Linux-Myths_and_Facts_for AMD_Processors.pdf
64bit_Linux-Myths_and_Facts_for AMD_Processors.pdfrangerdan275
 
Lesson 19. Pattern 11. Serialization and data interchange
Lesson 19. Pattern 11. Serialization and data interchangeLesson 19. Pattern 11. Serialization and data interchange
Lesson 19. Pattern 11. Serialization and data interchangePVS-Studio
 
CO&AL-lecture-04 about the procedures in c language (1).pptx
CO&AL-lecture-04 about the procedures in c language (1).pptxCO&AL-lecture-04 about the procedures in c language (1).pptx
CO&AL-lecture-04 about the procedures in c language (1).pptxgagarwazir7
 
Mac osx 64_rop_chains
Mac osx 64_rop_chainsMac osx 64_rop_chains
Mac osx 64_rop_chainsRahul Sasi
 
22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE
22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE
22cs201 COMPUTER ORGANIZATION AND ARCHITECTUREKathirvel Ayyaswamy
 
x86 architecture
x86 architecturex86 architecture
x86 architecturei i
 
Session01_Intro.pdf
Session01_Intro.pdfSession01_Intro.pdf
Session01_Intro.pdfRahnerJames
 
Arm v8 instruction overview android 64 bit briefing
Arm v8 instruction overview android 64 bit briefingArm v8 instruction overview android 64 bit briefing
Arm v8 instruction overview android 64 bit briefingMerck Hung
 
Intel 8086 microprocessor
Intel 8086 microprocessorIntel 8086 microprocessor
Intel 8086 microprocessorRavi Yasas
 
Intel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptIntel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptjeronimored
 
Advanced High-Performance Computing Features of the OpenPOWER ISA
 Advanced High-Performance Computing Features of the OpenPOWER ISA Advanced High-Performance Computing Features of the OpenPOWER ISA
Advanced High-Performance Computing Features of the OpenPOWER ISAGanesan Narayanasamy
 
Comparison of analyzers' diagnostic possibilities at checking 64-bit code
Comparison of analyzers' diagnostic possibilities at checking 64-bit codeComparison of analyzers' diagnostic possibilities at checking 64-bit code
Comparison of analyzers' diagnostic possibilities at checking 64-bit codePVS-Studio
 

Similaire à 64 bits for developers (20)

Lesson 1. What 64-bit systems are
Lesson 1. What 64-bit systems areLesson 1. What 64-bit systems are
Lesson 1. What 64-bit systems are
 
Cpu 64x architecture
Cpu 64x architectureCpu 64x architecture
Cpu 64x architecture
 
64bit_Linux-Myths_and_Facts_for AMD_Processors.pdf
64bit_Linux-Myths_and_Facts_for AMD_Processors.pdf64bit_Linux-Myths_and_Facts_for AMD_Processors.pdf
64bit_Linux-Myths_and_Facts_for AMD_Processors.pdf
 
64 bits
64 bits64 bits
64 bits
 
What is-32-bit-and-64-bit
What is-32-bit-and-64-bitWhat is-32-bit-and-64-bit
What is-32-bit-and-64-bit
 
Advanced microprocessor
Advanced microprocessorAdvanced microprocessor
Advanced microprocessor
 
Lesson 19. Pattern 11. Serialization and data interchange
Lesson 19. Pattern 11. Serialization and data interchangeLesson 19. Pattern 11. Serialization and data interchange
Lesson 19. Pattern 11. Serialization and data interchange
 
Uint3 vtu format
Uint3 vtu formatUint3 vtu format
Uint3 vtu format
 
CO&AL-lecture-04 about the procedures in c language (1).pptx
CO&AL-lecture-04 about the procedures in c language (1).pptxCO&AL-lecture-04 about the procedures in c language (1).pptx
CO&AL-lecture-04 about the procedures in c language (1).pptx
 
Operating system
Operating systemOperating system
Operating system
 
Mac osx 64_rop_chains
Mac osx 64_rop_chainsMac osx 64_rop_chains
Mac osx 64_rop_chains
 
22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE
22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE
22cs201 COMPUTER ORGANIZATION AND ARCHITECTURE
 
x86 architecture
x86 architecturex86 architecture
x86 architecture
 
Session01_Intro.pdf
Session01_Intro.pdfSession01_Intro.pdf
Session01_Intro.pdf
 
Arm v8 instruction overview android 64 bit briefing
Arm v8 instruction overview android 64 bit briefingArm v8 instruction overview android 64 bit briefing
Arm v8 instruction overview android 64 bit briefing
 
Intel 8086 microprocessor
Intel 8086 microprocessorIntel 8086 microprocessor
Intel 8086 microprocessor
 
Intel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.pptIntel microprocessor history lec12_x86arch.ppt
Intel microprocessor history lec12_x86arch.ppt
 
Advanced High-Performance Computing Features of the OpenPOWER ISA
 Advanced High-Performance Computing Features of the OpenPOWER ISA Advanced High-Performance Computing Features of the OpenPOWER ISA
Advanced High-Performance Computing Features of the OpenPOWER ISA
 
Cao 2012
Cao 2012Cao 2012
Cao 2012
 
Comparison of analyzers' diagnostic possibilities at checking 64-bit code
Comparison of analyzers' diagnostic possibilities at checking 64-bit codeComparison of analyzers' diagnostic possibilities at checking 64-bit code
Comparison of analyzers' diagnostic possibilities at checking 64-bit code
 

Plus de Roman Okolovich

Plus de Roman Okolovich (11)

Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
C# XML documentation
C# XML documentationC# XML documentation
C# XML documentation
 
code analysis for c++
code analysis for c++code analysis for c++
code analysis for c++
 
Using QString effectively
Using QString effectivelyUsing QString effectively
Using QString effectively
 
Ram Disk
Ram DiskRam Disk
Ram Disk
 
Virtual Functions
Virtual FunctionsVirtual Functions
Virtual Functions
 
Visual Studio 2008 Overview
Visual Studio 2008 OverviewVisual Studio 2008 Overview
Visual Studio 2008 Overview
 
State Machine Framework
State Machine FrameworkState Machine Framework
State Machine Framework
 
The Big Three
The Big ThreeThe Big Three
The Big Three
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Smart Pointers
Smart PointersSmart Pointers
Smart Pointers
 

Dernier

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Dernier (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

64 bits for developers

  • 1. 64 bits for developers By Roman Okolovich
  • 2. Introduction  x86-64 is a superset of the x86 instruction set architecture. x86-64 processors can run existing 32-bit or 16-bit x86 programs at full speed, but also support new programs written with a 64-bit address space and other additional capabilities.  The x86-64 specification was designed by Advanced Micro Devices (AMD), who have since renamed it AMD64. This was the first time any company other than Intel made significant additions to the IA-32 architecture.  x86-64 is backwards compatible with 32-bit code without any performance loss.
  • 3. x64 architectural features  64-bit integer capability: All general-purpose registers (GPRs) are expanded from 32 bits to 64 bits, and all arithmetic and logical operations, memory-to-register and register-to-memory operations, etc. can now operate directly on 64-bit integers. Pushes and pops on the stack are always in 8-byte strides, and pointers are 8 bytes wide.  Additional registers: In addition to increasing the size of the general-purpose registers, the number of named general-purpose registers is increased from eight (i.e. eax,ebx,ecx,edx,ebp,esp,esi,edi) in x86-32 to 16. It is therefore possible to keep more local variables in registers rather than on the stack, and to let registers hold frequently accessed constants; arguments for small and fast subroutines may also be passed in registers to a greater extent. However, AMD64 still has fewer registers than many common RISC processors (which typically have 32–64 registers) or VLIW-like machines such as the IA-64 (which has 128 registers).  Additional XMM (SSE) registers: Similarly, the number of 128-bit XMM registers (used for Streaming SIMD instructions) is also increased from 8 to 16.  Larger virtual address space: Current processor models implementing the AMD64 architecture can address up to 256 TB (281,474,976,710,656 bytes)[4] of virtual address space. This limit can be raised in future implementations to 16 EB (18,446,744,073,709,551,616 bytes). This is compared to just 4 GB (4,294,967,296 bytes) for 32-bit x86. This means that very large files can be operated on by mapping the entire file into the process' address space (which is sometimes faster than working with file read/write calls), rather than having to map regions of the file into and out of the address space.  Larger physical address space: Current implementations of the AMD64 architecture can address up to 1 TB (1,099,511,627,776 bytes) of RAM; the architecture permits extending this to 4 PB (4,503,599,627,370,496 bytes) in the future (limited by the page table entry format). In legacy mode, Physical Address Extension (PAE) is included, as it is on most current 32-bit x86 processors, allowing access to a maximum of 64 GB (68,719,476,736 bytes).  Instruction pointer relative data access: Instructions can now reference data relative to the instruction pointer (RIP register). This makes position independent code, as is often used in shared libraries and code loaded at run time, more efficient.  SSE instructions: The original AMD64 architecture adopted Intel's SSE and SSE2 as core instructions. SSE3 instructions were added in April 2005. SSE2 replaces the x87 instruction set's IEEE 80-bit precision with the choice of either IEEE 32-bit or 64-bit floating-point mathematics. This provides floating-point operations compatible with many other modern CPUs. The SSE and SSE2 instructions have also been extended to operate on the eight new XMM registers. SSE and SSE2 are available in 32-bit mode in modern x86 processors; however, if they're used in 32-bit programs, those programs will only work on systems with processors that have the feature. This is not an issue in 64-bit programs, as all AMD64 processors have SSE and SSE2, so using SSE and SSE2 instructions instead of x87 instructions does not reduce the set of machines on which x64 programs can be run. SSE and SSE2 are generally faster than, and duplicate most of the features of, the traditional x87 instructions, MMX, and 3DNow!.  No-Execute bit: The "NX" bit (bit 63 of the page table entry) allows the operating system to specify which pages of virtual address space can contain executable code and which cannot. An attempt to execute code from a page tagged "no execute" will result in a memory access violation, similar to an attempt to write to a read-only page. This should make it more difficult for malicious code to take control of the system via "buffer overrun" or "unchecked buffer" attacks. A similar feature has been available on x86 processors since the 80286 as an attribute of segment descriptors; however, this works only on an entire segment at a time. Segmented addressing has long been considered an obsolete mode of operation, and all current PC operating systems in effect bypass it, setting all segments to a base address of 0 and a size of 4 GB (4,294,967,296 bytes). AMD was the first x86- family vendor to implement no-execute in linear addressing mode. The feature is also available in legacy mode on AMD64 processors, and recent Intel x86 processors, when PAE is used.  Removal of older features: A number of "system programming" features of the x86 architecture are not used in modern operating systems and are not available on AMD64 in long (64-bit and compatibility) mode. These include segmented addressing (although the FS and GS segments are retained in vestigial form for use as extra base pointers to operating system structures)[5], the task state switch mechanism, and Virtual 8086 mode. These features do of course remain fully implemented in "legacy mode," thus permitting these processors to run 32-bit and 16-bit operating systems without modification.
  • 4. Virtual address space details  Although virtual addresses are 64 bits wide in 64-bit mode, current implementations (and any chips known to be in the planning stages) do not allow the entire virtual address space of 16 EB (18,446,744,073,709,551,616 bytes) to be used. Most operating systems and applications will not need such a large address space for the foreseeable future (for example, Windows implementations for AMD64 are only populating 16 TB (17,592,186,044,416 bytes), or 44 bits' worth).  AMD therefore decided that, in the first implementations of the architecture, only the least significant 48 bits of a virtual address would actually be used in address translation (page table lookup). Current 48-bit implementation 56-bit implementation 64-bit implementation
  • 5. Advantages of using x64  Compiling of a 64-bit code increases performance  the expected performance growth caused by an ordinary compilation is 5-15%  Adobe Company claims that new 64-bit "Photoshop CS4" is 12% faster than its 32-bit version  Some programs dealing with large data arrays may increase their performance when expanding address space  Using ptrdiff_t, size_t and derivative types allows to optimize program code up to 30%.
  • 6. Support x64 in Visual Studio (1 of 2)  /wp64 - Detects 64-bit portability problems on types that are also marked with the __w64 keyword.  The /Wp64 compiler option and __w64 keyword are deprecated and will be removed in a future version of the compiler.  Instead of using this option and keyword to detect 64-bit portability issues, use a Visual C++ compiler that targets a 64-bit platform. For more information, see 64-Bit Programming with Visual C++.
  • 7. Support x64 in Visual Studio (2 of 2)  How to: Configure Visual C++ Projects to Target 64-Bit Platforms  Click Configuration Manager to open the Configuration Manager Dialog Box.  Click the Active Solution Platform list, and then select the <New…> option to open the New Solution Platform Dialog Box.  Click the Type or select the new platform drop-down arrow, and then select a 64-bit platform.  Click OK. The platform you selected in the preceding step will appear under Active Solution Platform in the Configuration Manager dialog box.  Click Close in the Configuration Manager dialog box, and then click OK in the <Projectname> Property Pages dialog box.
  • 8. Data model • ISO/IEC 9899:1990, Programming Data Type LP32 ILP32 ILP64 LLP64 LP64 Languages - C (ISO C) left the definition of char 8 8 8 8 8 the short int, the int, the long int, and the short 16 16 16 16 16 int32 32 pointer to avoid constraining hardware int 16 32 64 32 32 architectures that might benefit from long 32 32 64 32 64 defining these data types independently long long (int64) 64 from one another. pointer 32 32 64 64 64 • The relationship between the fundamental data types can be expressed as: sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) = sizeof(size_t) • Notation: int (I), long (L), and pointer (P) • ILP32 is used in Win32 • LLP64 is used in Win64 • LP64 is used in UNIX 8
  • 9. General issues relating to x64 (1 of 4)  An int and a long are 32-bit values on 64-bit Windows operating systems.  You should not to assign pointers to 32-bit variables. Pointers are 64-bit on 64-bit platforms, and you will truncate the pointer value if you assign it to a 32-bit variable. sizeof(int) = sizeof(long) = sizeof(pointer) Common assumptions about the relationships between the fundamental data types may no longer be valid in a 64-bit data model
  • 10. General issues relating to x64 (2 of 4)  size_t, time_t, and ptrdiff_t (STL) are 64-bit values on 64-bit Windows operating systems. Fine if bigValue <= UINT_MAX Don’t mix up size_t and fundamental data types. size_t n = bigValue; unsigned int <= UINT_MAX for(unsigned i = 0; i != n; ++i) { ... } size_t n = bigValue; Result value will be unsigned index = 0; truncated for(size_t i = 0; i != n; ++i) size_t a; { int b = (int)a; array[index++] = 10; int b = (int)(a); } int b = int(a); Use only size_t because an array can contains more when int b = static_cast<int>(a); UINT_MAX items
  • 11. General issues relating to x64 (3 of 4)  The %x (hex int format) printf modifier will not work as expected on a 64-bit Windows operating system. It will only operate on the first 32 bits of the value that is passed to it.  Use %I32x to display an integer on a Windows 32-bit operating system.  Use %I64x to display an integer on a Windows 64-bit operating system.  The %p (hex format for a pointer) will work as expected on a 64-bit Windows operating system.
  • 12. General issues relating to x64 (4 of 4)  data alignment  The MyStruct2 structure size equals to 12 bytes in a 32-bit program, and in a 64-bit program, it is only 16 bytes. Therewith, from the point of view of data access efficiency, the MyStruct1 and MyStruct2 structures are equivalent.  common recommendation is the following: the objects should be distributed in descending order of their size.
  • 13. References  x86-64 (wikipedia)  64-bit Programming (How Do I in Visual C++)  64-Bit Programming with Visual C++  FAQ for Development on 64-bit Windows  Common Visual C++ 64-bit Migration Issues  Viva64, a tool for porting your applications to 64-bit platforms  Optimization of 64-bit programs