FC - Lin Growing

FC Notes: Data Alignment and Processor Architecture

On this page

Main Line: When a line of code becomes hardware action, each step costs time, space, energy and benefits in return. It will be. The first year of the exam is a yearly one. Understanding The first is to explain it in his own words. See what I mean. I’m not going to read it.


One, alignment with padding (alineament) and the other will be matched

rules: Each field (camp) must be placed on the “multiple of its size” address (adreça múltiple de la seva mida); it is not enough to add 0 bytes (padding). Purpose A bit of memory: replacing faster access. The hardware moves the entire data in a neat way, distorting the probability of moving twice.

Three steps of struct size

  1. Starting with address 0, field in the order declared.
  2. The current address is not a multiple of the field size, but a multiple of 0 to the next one.
  3. The total size is added to the multiples of “maximum alignment requirements” (end padding).
DeclarationThe layoutSize
struct { int; char; float; }In the case of int 0 ⁇ 3, char 4, supplement 5 ⁇ 7, float 8 ⁇ 1112
struct { int; int; char; }0x3, 4x7, char 8, ending with 9x1112
struct { int; double; }Int 0 to 3, add 4 to 7, double 8 to 1516
struct { double; int; }Double 0 to 7, int 8 to 11, end to 12 to 15.16
struct { char; int; char; }Char 0, supplement 1 to 3, int 4 to 7, char 8, end of supplement 9 to 11.12
struct { int; char; char; }int 0 ⁇ 3, char 4, char 5, ending with 6 ⁇ 78
  • Double is aligned with 8 (the standard answer to the course is also calculated on 32-bit machines); char is aligned by 1.
  • Change the field order Not necessarily. Save space, all possible sequences are calculated. Generally, the large fields are saved in front.
  • The compilation machine automatically fills the padding, without manual processing by programmers; it can be requested that the compilation device not be filled, but not recommended.
  • The first is the “Padding allows the camp to float stigui in a @mem múltiple de la seva mida”.

Two, the union will be broken.

  • All members start at the same address (la stessa @ de memoria); there is only one value (un valor a la vez) at the same time; writing one member will cover all other members (els valores es sobreescriuen).
  • Size = largest member, then multiply by the maximum alignment requirement.
  • union { int; char[5]; float; } The largest member is 5 bytes, plus 4 times the result is 8.
  • union { int; char[9]; double; } The largest member is 9 bytes, plus the multiple of 8 and the result is 16.
  • The union has changed in size and order.
  • After struct is changed to union, fields overlap, writing one field changes another and the behavior of the program changes.
structunion
Membership“And”: Being at the same time“Or”: There is only one.
Starting addresses of each memberThis time, they’re out.It’s all zero.
SizeMembers and + paddingThe largest member + padding

III. Python Objects — Reading for Understanding

  • Objects are examples of classes, a combination of variables, functions and struct; classes can be seen as an evolutionary version of struct.
  • In Python, each value is an object, beginning with a header (capçaleres) metadades, which depends on the type of object.
  • The principle of C instead of Python is that the object adds a lot of “noise” and turns memory size and execution into black boxes.
import sys
print(sys.getsizeof(125))   # 64 位 CPython 上一般是 28,远大于 C 的 int(4 字节)

Four, from cloud to device, you can see the cloud.

  • Computing system (sistema informático) = hardware + system software, used to execute a program. The device can be completely different but the concept is the same.
  • Layer: cloud, thousands of them) → fog, millions of them, geographically closer to the server of the user) → terminal devices, billions of them: watches, cameras, robots, phones).
  • The concept of fog was developed by Cisco and later evolved into edge.

Five, John Neumann vs. Harvard - How to understand a mother

  • The following is a list of articles related to the book. (Arquitectura Von Neumann, most commonly used): The CPU receives instructions and data from the input device or memory and processes them to send the results to the output device or memory; instructions and data Sharing a memory.
  • The Harvard (Arquitectura Harvard): instructions and data use Separated storage The term “memória separada per instrucciones i per datos” is used in the context of DSP.
The following is a list of articles related to the book.The Harvard
The benefitsCheap, flexible allocation of spaceInstructions and data accessible simultaneously
CostThe instructions and data clutter together to form a bottleneck.The lines are more expensive and the capacity is difficult to allocate.
  • Modern CPUs are mixed: only one main cache, but L1 caches are divided into i-cache (instructions) and d-cache data.

Six: The components of the CPU understand the components

The following is a list of the official languages of the United States:The role
The following is a list of the commands for the Control Unit (Unitat de Control d’Instrucciones)Implementation of the management instructions
The Bank of Registres (Banc de Registres) is a bank holding company.Access the nearest storage distance in word
The first is the memory cache.Reducing the gap between CPU and memory
The first is the Interficie del Bus.The circuit responsible for memory reading and writing
ALUSimple calculations
Other units (Altres Unitats)Complex computing units, accelerators
The first is the “Memòria Principal”.Connected via I/O Bridge outside the CPU

The five stages of executing an order (etapes) will be followed by the execution of a sentence.

StageWhat to do?Responsible for the components
FetchThe following instructions are taken from the address on the PCDirections for control units
DecodeThe operation is decoded in ISA microoperacions and read operand from the register stack.Directions for control units
ExecuteThe functional units are given as units functionals: ALU, FPU, Load/Store…)Execution units
MemoryOnly load/store instruction is actually accessing memoryExecution units
Write BackWrite back the results in a procedural orderRetirement Unit
  • The first is that the decode is directly affected by ISA. The more complex the CISC, the more complicated the decode. Fetch is only intercepted: CISC instructions are not fixed in length and make it more difficult to point out.
  • Directions to the Control Unit Fetch and Decode (Question asked)
  • Why write back separately: There may be many instructions executed at the same time, and the results must be written back in program order, so it’s called “retirement”.
  • C = A + B The actual instructions are four: load A → load B → add → store C―A, B, C all in memory, and you have to calculate the address before you can access it.
  • RegA = RegA + RegB The components used are: the command to take control units from i-cache → decode → read RegA, RegB → ALU from register stack → add back RegA → Retirement Unit so that the command is retired.
  • The real processor breaks down these five steps into 15×20.

The water is flowing through the pipeline.

The Principle The first step is to create a new car, like Ford’s car stream: one job finishes and the next gets half of it, and then you start making the next.

  • No flow lines: total time = n × k × t
  • The total time for the flow line is = (k + n − 1) × t_max
  • Example: k = 5 phases, n = 3 instructions for each 1 s, without flowing waterline 15 s, with flowing water line 7 s.

Two restrictions

  1. The distribution is uneven (particionat no-uniforme): The performance is limited to the slowest stage. The solution is to break down the slowest phase, so that modern processors have more than 15 stages.
  2. Additional own costs (cost inherent addicional): between phases, the results are transmitted by pipeline registers that account for chip area and also consume electricity.

The flow of water does not speed up the single line instruction, which is the throughput (the number of instructions completed in unit time).

I’m not sure. The main circuit diagram is similar to RISC-V, PC and +4 corresponding Fetch, Register File and Control Unit corresponding Decode, ALU corresponding Execute, D-Mem corresponding Memory; the green long bar in the diagram is a flow line register.


IX. Instruction Set Architecture (ISA) — Essential Knowledge

ISAs define the format and type of instructions, the code for operations (codification de les opérations), how to access memory, which registers are available, and similar mechanisms such as SIMD.

  • For one ISA compilation program, on another ISA processor It’s not decoding, it doesn’t run. It’s not a “running slow” issue, like x86 vs. Arm: Apple M Series and Intel Mac.)
  • Forat semàntic: ISA design should alternate between “closer to advanced language” and “closest to hardware control signals”, which affects the complexity of compilation machines and microarchitectures.
RISCCISC
DirectionsLess and simplerMultiple and complex (one instruction to complete the visit + calculation)
The advantagesReducing the complexity of processorsReducing the complexity of compilation
ExamplesARM, MIPS, RISC-VThe early x86, the Motorola 68K
  • The x86 is the later. Mixed CISC-RISC The chip is designed to be a simple micro-instruction and then executed internally.
  • Less instructions ≠ faster.

I’m not sure.

  • The first computer for electronic storage was the Manchester Baby in 1948, with only three-bit identification instructions (maximum eight, seven items on the curriculum table).
  • The assembly language (llenguatge ensamblador) is written in the machine code assistant (mnemotècnics) codi màquina: mov moves data, add I’m not sure. sub The decrease jl It’s “Jump less than jump”.
  • Machine code examples in the course ((Y86-64) for teaching: 20 10 = rrmovq %rcx,%rax, 60 20 = addq %rdx,%rax, 72 84 00 00 … = jl 0x84. You can see that the command length is not fixed (2 byte or 9 byte) and that the jump address is stored in little-endian (little-endian).

X. Register Files and Hardware Threads — Essential Knowledge

  • The registers (Banc de Registres): the smallest, fastest layer of the storage level in the CPU; small because it must be fast.
  • x86-64 is 16 64-bit universal registers The GPR, the registres de propòsit general (GPR), has 52 other sub-registers.
  • The following types of registers are available: general register, FPU register, special register, program counter, status register, vector register, registers and vector registers.
  • PC (program counter): record the address of an instruction to be executed. When a loop, condition judgment, function call is encountered, it jumps elsewhere.
  • When the register is not enough, it is the compilation that determines which variables are stored and which are temporarily stored.
  • The registers I can’t. Instead of caching, it provides the operand directly to instructions and also takes on specific uses such as PC, sign space.
  • Processor I can. No cache: it can still work, but every time you access memory, it will be much slower.
  • Hardware threads (Hardware Thread): The hardware is provided by the execution context, and the core of the hardware is a register stack. In Windows, it is called a logical processor, or processing unit.

I’m not sure.: sub-registers RAX(64 bits)→ EAX(low 32 bits)→ AX(low 16 bits)→ AH(8th row 15th row)/AL ((0th row 7th row)), which are all different parts of the same physical register.

Next week, the yearly exam will be held: software threads and hardware threads, core threads, multi-core vs. multiple threads. When only one register stacks, two hardware threads cannot run simultaneously.

XI. Execution Units — Conceptual Understanding

UnitThe first is the “Class of the Year”.
ALUnombres enters i lògica binària (full numbers and binary logic)
FPUCommon (floating-point)
AGUCalculation of the address of the address (Callcul de l’adreça per accedir a memoria)
The vector units are units of vectorialsApply the same operation to a set of data (for example, a set of numbers)

ALU enters two operands and a 4-bit opcode ((0000 plus 0001 minus 1000 AND…), output the result, and sets four character bits:

  • C#, carry on The result is beyond the scope.
  • V (overflow, overflow) The symbols are only relevant for numbers such as char type 127 + 1 = 10000000, where C = 0 , V = 1.
  • I’m not sure what to do. The result was negative.
  • Z: Zero, zero The result is 0.

The latency of different operations (latència) is different: floating-point operations are usually slower than integers.

The second is that the two sides of the border are not going to be able to get a clearer picture.

The four questions

  1. What is it? The following is a list of commands for multiple data processing:
  2. Where to use the code The following is a list of the most common types of cycles:
  3. What hardware is needed ISAs have vector instructions (instructions vectorials) and processors have vector registers (registres vectorial).
  4. The effect: The number of cycles and the number of instructions executed changes; if there is no vectorization in the code, the number of instructions may be the same as before.
ExpandedRegisteredThe width of the bitHow many floats can be loaded?
SSEXMM128 bits4 (or 2 double)
AVX / AVX2YMM256 bits8
AVX-512—512 bits16
for (int i = 0; i < 1024; i++)
    c[i] = a[i] + b[i];   // 各次迭代互不依赖,编译器可以自动向量化
  • Programmers generally do not write vector instructions by hand: adding an instruction to the compilation machine, the compiler will automatically vectorise.
  • The power saving: 4 times the addition of a finger, decoding once.
  • I’m not sure. Flynn: Classified by “Instruction Flow × Data Flow” for each single/multiple, divided into SISD, SIMD, MISD, MIMD.

Glossary: Chinese and Catalan

ChineseCatalan
Coordinated / Filledalignment / padding
Fields / Addresses / Sizefield / address (@) / size
Objects / Class / Head / Elementsobject / class / headers / metadata
Computer architecturecomputer architecture
The registersregister file
Main storage / cachingmain memory / cache memory
Stage / Slowest stagestage / slowest stage
Waterline recorderpipeline registers
Inequality of distribution / Additional intrinsic costsnonuniform partitioning / inherent additional cost
Micro operation / functional unitmicro-operations / functional units
The following is a list of the most commonly used names in the United States:instruction set (ISA) / semantic gap
Assembly language / machine codeassembly language / machine code
General registersgeneral-purpose registers
Run context / hardware threadsexecution context / hardware thread
Execute the unit/vector unitexecution units / vector units
The whole number / floating-pointintegers / floating point
The first is the “Fireflow” (Figure 1).performance / energy consumption / bottleneck
Delayedlatency

Frequently Asked Questions

CatalanChinese
Briefly justify all answersAll answers should be brief and justifiable.
How many bytes in total do they occupy…?How many bytes is that?
Briefly explain how the byte count is obtainedA brief description of how the bytes came to be
Can changing the order of the fields result in a different number of bytes?Does the change in field order change bytes?
How does it differ…?What difference does it make?
Does the ISA directly affect it?Is it directly affected by ISA?
És possible…? En cas afirmatiu… / En cas negatiu…If it is possible to explain… if it is impossible to explain…
Can we execute … simultaneously?Can you do it simultaneously?
Identify and briefly describe…The following is a list of the most common types of cancer:

Machine-assisted translation · Read Chinese original