Computer architecture

Computer architecture

[Who are the Computer Architects?]
The Mathematical Theory of Communication
Given a symbol level, the architecture is the description of the system in whatever system-description scheme exists next below the symbol level. - Newell, 1990, p. 81
Digital Design and Computer Architecture 2nd Edition
Computer Organization and Design 5th Edition
Structured Computer Organization 6th Edition
Write Great Code: Volume 1: Understanding the Machine


Architectural state
Microarchitectural state, such as information stored in TLBs and caches


A Symbolic Analysis of Relay and Switching Circuits


How a CPU Works


ISA: memory model, registers, data types, instructions, word size(?).
Memory model: unit of address resolution, word, aligment, address space, addressing mode, memory barrier/memory order primitive’s semantics.

Data struct alignment

struct foo { char c; int i;};
A bug story: data alignment on x86
The Lost Art of C Structure Packing
Typical alignment of C structs on x86

Reasons for not alignment

  1. Casting variables to types of different lengths, e.g. char * to int *
  2. Pointer arithmetic followed by access to at least 2 bytes of data , 不太理解.

    Programming skills

    Reorder members of struct;
    get/put_unaligned to avoid analigned access.
    attribute aligned

    Calculate the sizeof of aligned c struct

    Data alignment means putting the data at a memory address equal to some multiple of the word size, which increases the system’s performance due to the way the CPU handles memory.

  3. find the widest scalar member and attribute( aligned(x)) to determin alignment.

  4. fill the member to alignement without wrap

  5. Pading to alignment

Endianess and bitfield

The order of allocation of bit-fields within a unit
It’s Determined by ABI not Gcc. Check comments on Bitfield endianness in gcc

How Endianness Effects Bitfield Packing

__u8 ihl:4,
version:4; # MSB, check wikipeida ipv4 header

GCC bug on bitfield

Betrayed by a bitfield


Check books COD, COA and ULK 3rd