Modern X86 Assembly Language Programming: Covers x86 64-Bit, AVX, AVX2, and AVX-512 2nd Edition Daniel Kusswurm 2024 Scribd Download
Modern X86 Assembly Language Programming: Covers x86 64-Bit, AVX, AVX2, and AVX-512 2nd Edition Daniel Kusswurm 2024 Scribd Download
com
https://ebookmeta.com/product/modern-x86-assembly-
language-programming-covers-x86-64-bit-avx-
avx2-and-avx-512-2nd-edition-daniel-kusswurm/
https://ebookmeta.com/product/modern-x86-assembly-language-
programming-covers-x86-64-bit-avx-avx2-and-avx-512-3rd-edition-
daniel-kusswurm/
https://ebookmeta.com/product/x86-64-assembly-language-
programming-with-ubuntu-ed-jorgensen/
https://ebookmeta.com/product/modern-parallel-programming-with-c-
and-assembly-language-daniel-kusswurm/
https://ebookmeta.com/product/assembly-language-
for-x86-processors-6th-edition-kip-irvine/
Cambridge IGCSE and O Level History Workbook 2C - Depth
Study: the United States, 1919-41 2nd Edition Benjamin
Harrison
https://ebookmeta.com/product/cambridge-igcse-and-o-level-
history-workbook-2c-depth-study-the-united-states-1919-41-2nd-
edition-benjamin-harrison/
https://ebookmeta.com/product/introduction-to-computer-
organisation-an-under-the-hood-look-at-hardware-
and-x86-64-assembly-1st-edition-robert-g-plantz/
https://ebookmeta.com/product/low-level-programming-c-assembly-
and-program-execution-on-intel-64-architecture-zhirkov/
https://ebookmeta.com/product/raspberry-pi-assembly-language-
programming-1st-edition-stephen-smith/
Daniel Kusswurm
Standard Apress
Trademarked names, logos, and images may appear in this book. Rather
than use a trademark symbol with every occurrence of a trademarked
name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark. The use in this publication
of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of
opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true
and accurate at the date of publication, neither the authors nor the
editors nor the publisher can accept any legal responsibility for any
errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained
herein.
Distributed to the book trade worldwide by Springer Science+Business
Media New York, 233 Spring Street, 6th Floor, New York, NY 10013.
Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-
[email protected], or visit www.springeronline.com. Apress Media,
LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM
Finance Inc is a Delaware corporation.
This book is dedicated to those individuals who suffer the ravages of
Alzheimer’s disease and their unsung compassionate caregivers.
Introduction
Since the invention of the personal computer, software developers have
used x86 assembly language to create innovative solutions for a wide
variety of algorithmic challenges. During the early days of the PC era, it
was common practice to code large portions of a program or complete
applications using x86 assembly language. Given the 21st Century
prevalence of high-level languages such as C++, C#, Java, and Python, it
may be surprising to learn that many software developers still employ
assembly language to code performance-critical sections of their
programs. And while compilers have improved remarkably over the
years in terms of generating machine code that is both spatially and
temporally efficient, situations still exist where it makes sense for a
software developer to exploit the benefits of assembly language
programming.
The single-instruction multiple-data (SIMD) architectures of
modern x86 processors provide another explanation for the continued
interest in assembly language programming. A SIMD-capable processor
contains computational resources that facilitate simultaneous
calculations using multiple data values, which can significantly improve
the performance of applications that must deliver real-time
responsiveness. SIMD architectures are also well-suited for
computationally-intense problem domains, such as image processing,
audio and video encoding, computer-aided design, computer graphics,
and data mining. Unfortunately, many high-level languages and
development tools are still unable to fully or even partially exploit the
SIMD capabilities of a modern x86 processor. Assembly language, on
the other hand, enables the software developer to take full advantage of
a processor’s SIMD resources.
Target Audience
The target audience for this book is software developers, including:
Software developers who are creating application programs for
Windows-based platforms and want to learn how to write
performance-enhancing algorithms and functions using x86-64
assembly language
Software developers who are creating application programs for non-
Windows environments and want to learn x86-64 assembly language
programming
Software developers who want to learn how to create SIMD
calculating functions using the AVX, AVX2, and AVX-512 instruction
sets
Software developers and computer science students who want or
need to gain a better understanding of the x86-64 platform and its
SIMD architecture
The principal audience for Modern X86 Assembly Language
Programming, Second Edition is Windows software developers, since
the source code examples were developed using Visual Studio C++ and
MASM. Software developers who are targeting non-Windows platforms
can also benefit from this book since most of the informative content is
organized and communicated independent of any specific operating
system. It is assumed that readers of this book will have previous high-
level language programming experience and a basic understanding of
C++. Familiarity with Visual Studio or Windows programming is not
necessary.
Content Overview
The primary objective of this book is to help you learn x86 64-bit
assembly language programming along with AVX, AVX2, and AVX-512.
The book’s chapters and content are structured to achieve this goal.
Here’s a brief overview of what you can expect to learn.
Chapter 1 covers the core architecture of the x86-64 platform. It
includes a discussion of the platform’s fundamental data types, internal
architecture, register sets, instruction operands, and memory
addressing modes. This chapter also describes the core x86-64
instruction set. Chapters 2 and 3 explain the fundamentals of x86-64
assembly language programming using the core instruction set and
common programming constructs, including arrays and structures. The
source code examples presented in these (and subsequent) chapters
are packaged as working programs, which means that you can run,
modify, or otherwise experiment with the code to enhance your
learning experience.
Chapter 4 focuses on the architectural resources of AVX including its
register sets, data types, and instruction set. Chapter 5 explains how to
use the AVX instruction set to perform scalar floating-point arithmetic
using both single-precision and double-precision values. Chapters 6
and 7 illustrate AVX SIMD programming using packed floating-point
and packed integer operands.
Chapter 8 introduces AVX2 and explores its enhanced capabilities
including data broadcasts, gathers, and permutes. It also explains
fused-multiply-add (FMA) operations. Chapters 9 and 10 contain
source code examples that exemplify a variety of computational
algorithms using AVX2 with packed floating-point and packed integer
operands. Chapter 11 includes source code examples that demonstrate
FMA programming. This chapter also covers examples that explicate
recent x86 platform extensions using the general-purpose registers.
Chapter 12 delves into the architectural details of AVX-512. This
chapter describes AVX-512’s register sets and data types. It also
elucidates pivotal AVX-512 enhancements including conditional
execution and merging, embedded broadcast operations, and
instruction-level rounding. Chapters 13 and 14 contain numerous
source code examples that demonstrate how to exploit these advanced
features.
Chapter 15 presents an overview of a modern x86 multi-core
processor and its underlying microarchitecture. This chapter also
outlines specific coding strategies and techniques that can be used to
boost the performance of x86 assembly language code. Chapter 16
reviews several source code examples that illustrate advanced x86
assembly language programming techniques including processor
feature detection, accelerated memory accesses, and multithreaded
computations.
Appendix A describes how to execute the source code examples
using Visual Studio and MASM. It also includes a list of references and
resources that you can consult for more information about x86
assembly language programming.
Source Code
Source code download information for this book is available on the
Apress website at
https://www.apress.com/us/book/9781484240625 . For
each chapter, there is a ZIP file that contains the C++ and assembly
language source code files along with the Visual Studio project files.
There is no setup or install program to run. You can simply extract the
contents of a chapter ZIP file into a folder of your own choosing.
Caution The sole purpose of the source code is to elucidate
programming examples that are directly related to the topics
discussed in this book. Minimal attention is given to essential
software engineering concerns such as robust error handling,
security risks, numerical stability, rounding errors, or ill-conditioned
functions. You are responsible for addressing these issues should
you decide to use any of the source code in your own programs.
Additional Resources
An extensive set of x86-related programming documentation is
available from both AMD and Intel. Appendix A lists several important
resources that both aspiring and experienced x86 assembly language
programmers will find useful. Of all the resources listed Appendix A,
the most valuable reference is Volume 2 of Intel 64 and IA-32
Architectures Software Developer’s Manual - Combined Volumes: 1, 2A,
2B, 2C, 2D, 3A, 3B, 3C, 3D, and 4 (
https://www.intel.com/content/www/us/en/processors
/architectures-software-developer-manuals.html ). This
tome contains comprehensive programming information for every x86
processor instruction including detailed operational descriptions, lists
of valid operands, affected status flags, and potential exceptions. You
are strongly encouraged to consult this indispensable resource when
developing your own x86 assembly language code to verify correct
instruction usage.
Acknowledgments
The production of a motion picture and the publication of a book are
somewhat analogous. Movie trailers extol the performances of the lead
actors. The front cover of a book trumpets the authors’ names. Actors
and authors ultimately receive public acclamation for their efforts. It is,
however, impossible to produce a movie or publish a book without the
dedication, expertise, and creativity of a professional behind-the-scenes
team. This book is no exception.
I would like to thank the talented editorial team at Apress for their
efforts especially Steve Anglin, Mark Powers, and Matthew Moodie. Paul
Cohen deserves kudos for his meticulous technical review and practical
suggestions. Proofreader Ed Kusswurm merits applause and
recognition for his hard work and constructive feedback. I accept full
responsibility for any remaining imperfections.
I would also like to thank Nirmal Selvaraj, Dulcy Nirmala, Kezia
Endsley, Dhaneesh Kumar and the entire production staff at Apress for
their contributions, and my professional colleagues for their support
and encouragement. Finally, I would like to recognize parental nodes
Armin (RIP) and Mary along with sibling nodes Mary, Tom, Ed, and John
for their inspiration during the writing of this book.
Contents
Chapter 1:X86-64 Core Architecture
Historical Overview
Data Types
Fundamental Data Types
Numerical Data Types
SIMD Data Types
Miscellaneous Data Types
Internal Architecture
General-Purpose Registers
RFLAGS Register
Instruction Pointer
Instruction Operands
Memory Addressing
Differences Between x86-64 and x86-32 Programming
Invalid Instructions
Deprecated Instructions
Instruction Set Overview
Summary
Chapter 2:X86-64 Core Programming – Part 1
Simple Integer Arithmetic
Addition and Subtraction
Logical Operations
Shift Operations
Advanced Integer Arithmetic
Multiplication and Division
Calculations Using Mixed Types
Memory Addressing and Condition Codes
Memory Addressing Modes
Condition Codes
Summary
Chapter 3:X86-64 Core Programming – Part 2
Arrays
One-Dimensional Arrays
Two-Dimensional Arrays
Structures
Strings
Counting Characters
String Concatenation
Comparing Arrays
Array Reversal
Summary
Chapter 4:Advanced Vector Extensions
AVX Overview
SIMD Programming Concepts
Wraparound vs.Saturated Arithmetic
AVX Execution Environment
Register Set
Data Types
Instruction Syntax
AVX Scalar Floating-Point
Floating-Point Programming Concepts
Scalar Floating-Point Register Set
Control-Status Register
Instruction Set Overview
AVX Packed Floating-Point
Instruction Set Overview
AVX Packed Integer
Instruction Set Overview
Differences Between x86-AVX and x86-SSE
Summary
Chapter 5:AVX Programming – Scalar Floating-Point
Scalar Floating-Point Arithmetic
Single-Precision Floating-Point
Double-Precision Floating-Point
Scalar Floating-Point Compares and Conversions
Floating-Point Compares
Floating-Point Conversions
Scalar Floating-Point Arrays and Matrices
Floating-Point Arrays
Floating-Point Matrices
Calling Convention
Basic Stack Frames
Using Non-Volatile General-Purpose Registers
Using Non-Volatile XMM Registers
Macros for Prologs and Epilogs
Summary
Another random document with
no related content on Scribd:
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.