跳转至

CS#

Calling conventions

ABI - Calling convention

In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines or functions receive parameters from their caller and how they return a result.

CPU Architectures

有5种指令集最为常见,它们构成了处理器领域的5朵金花。

  1. x86——硕大的大象
  2. ARM——稳扎稳打的蚁群
  3. MIPS——优雅的孔雀
  4. Power——昔日的贵族
  5. C6000——偏安一隅的独立王国

This article is about the collection of datasheet/textbooks/references on the three major mainstream CPUs.

计算机中有符号数的表示

对于无符号整数,一般来说,所有的数位都被用来表示数值。
对于带符号整数,数位被划分为符号位(只能占一位)与数值位(剩余的其它位)。

符号位的权值有不同的解释:

  1. 权值是零(符号位是“1”则表示数值为负),称为“符号-绝对值”模式(Sign and magnitude)。
  2. 权值是 –(2N-1-1),“1的补码”方式(Ones’ complement)。
  3. 权值是 –2N-1,“2的补码”方式(Two’s complement)。

Struct Alignment Specify

在上一篇《Struct Alignment Rule》中,我们梳理了结构体存储布局的“地址边界对齐限制”规则。
本篇介绍通过编译器 gcc/msvc 提供的扩展特性及 C/C++ 提供的一些语言特性来修改默认的对齐参数,并测试分析其作用效果。

  1. The packed attribute specifies that a structure member should have the smallest possible alignment.
  2. The aligned attribute specifies a minimum alignment for the variable or structure field, measured in bytes.
  3. -fpack-struct[=n]/#pragma pack(n) specifies the maximum alignment, structure members can potentially be unaligned.

Struct Alignment Rule

An object doesn't just need enough storage to hold its representation. In addition, on some machine architectures, the bytes used to hold it must have proper alignment for the hardware to access it efficiently.

Where alignment most often becomes visible is in object layouts: sometimes structs contain "holes" to improve alignment.

C/C++ Memory Alignment

One of the low-level features of C/C++ is the ability to specify the precise alignment of objects in memory to take maximum advantage of a specific hardware architecture. By default, the compiler aligns class and struct members on their size value.

Memory Address Alignment

One of the low-level features of C/C++ is the ability to specify the precise alignment of objects in memory to take maximum advantage of a specific hardware architecture. By default, the compiler aligns class and struct members on their size value.

x86's ill-timed WORD

The word size is the computer's preferred size for moving units of information around; technically it's the width of your processor's registers. It reflects the amount of data that can be transmitted between memory and the processor in one chunk. Likewise, it may reflect the size of data that can be manipulated by the CPU's ALU in one cycle.

Whereas, in the universe of x86, word continues to designate a 16-bit quantity. Microsoft's Windows API maintains the programming language definition of WORD as 16 bits, despite the fact that the API may be used on a 32- or 64-bit x86 processor.

Machine Word

In computing, a word is the natural unit of data used by a particular processor design. The term word refers to the standard number of bits that are manipulated as a unit by any particular CPU.

The word size is the computer's preferred size for moving units of information around; technically it's the width of your processor's registers. It reflects the amount of data that can be transmitted between memory and the processor in one chunk. Likewise, it may reflect the size of data that can be manipulated by the CPU's ALU in one cycle.

Data Models

In 32-bit programs, pointers and data types such as integers generally have the same length. This is not necessarily true on 64-bit machines. Mixing data types in programming languages such as C and its descendants such as C++ and Objective-C may thus work on 32-bit implementations but not on 64-bit implementations.