关于 Apple M1 软件工程师所需要知道的细节

827 阅读3分钟

更多精彩技术文章,请关注作者的微信公众号:码工笔记

Apple M1 是苹果新推出的基于 ARM 指令集的新一代 SoC(System on Chip,除 CPU 以外还集成了 GPU、神经网络计算引擎、I/O控制器等),是个人电脑上第一个采用 5 nm 工艺制造的 CPU,,特点和参数总结如下:

一、8 核 CPU

4 个高性能 CPU 核(代号“FireStorm”)

  • L1 instruction cache: 192KB
    • 分别是 Arm 和 Intel 竞品的 3 倍和 6 倍
  • L1 data cache: 128 KB
    • load 只需 3 个时钟周期
    • AMD 32 KB,需要 4 个时钟周期;Intel 最新的 Sunny Cove 为 48 KB,5 个时钟周期
  • L2 shared cache: 12 MB
  • "P cluster" 主频 0.6-3.204GHz, 功率 <=13.8W

以下微架构数据由软件评测得到[2][3],可能与实际有出入

指令译码器宽度为 8

  • 业界最宽的
  • AMD Zen1~3,Intel x86 宽度都是 4
  • ARM 系列中,Samsung M3 以后都是 6,Arm 的 Cortex 系列目前是 4,Cortex-X1 会加到 5

指令执行部件(Port)

  • 整数部件(Integer units):
    • 1: alu + flags + branch + adr + msr/mrs nzcv + mrs
    • 2: alu + flags + branch + adr + msr/mrs nzcv + ptrauth
    • 3: alu + flags + mov-from-simd/fp?
    • 4: alu + mov-from-simd/fp?
    • 5: alu + mul + div
    • 6: alu + mul + madd + crc + bfm/extr
  • 内存读写部件(Load and store units,up to 128-bit loads and stores, including address generation with shifts up to LSL #3):
    • 7: store + amx
    • 8: load/store + amx
    • 9: load
    • 10: load
  • 浮点数、SIMD 部件(FP/SIMD units):
    • 11: fp/simd
    • 12: fp/simd
    • 13: fp/simd + fcsel + to-gpr
    • 14: fp/simd + fcsel + to-gpr + fcmp/e + fdiv + frecpe + frsqrte + fjcvtzs + ursqrte + urecpe + sha

指令融合

  • adds/subs/ands/cmp/tst + b.cc (complete fusion when fused instructions read no more than 4 registers per 6 instructions)
  • aese + aesmc (always fused if operands match pattern "A, B ; A, A")
  • aesd + aesimc (always fused if operands match pattern "A, B ; A, A")
  • pmull + eor (usually fused if operands match pattern "A, B, C ; A, A, D" or "A, B, C ; A, D, A")
  • amx + amx (excluding loads and stores - probably fuses to something like a STP)

指令消除:删除不需要的指令

  • mov x0, 0 (handled by renaming)
  • mov x0, x1 (usually handled by renaming)
  • movi v0.16b, #0 (handled by renaming)
  • mov v0.16b, v1.16b (usually handled by renaming)
  • mov imm/movz/movn (handled by renamer at a max of 2 per 8 instructions, includes all tested "mov")
  • nop (never issues)

其他参数

  • Retires per cycle: 8
  • ROB(in-flight renames):~623
    • 目前 Intel Sunny Cove & Willow Cove cores 居第二:352
    • AMD 最新的 Zen3 为 256
    • Arm 最新的 Cortex-X1 为 224
  • Integer physical register file size: ~380
  • FP/SIMD physical register file size: ~434
  • Fetch window tracking slots (in-flight I-cache lines or branches): ~144
  • Load buffers: ~129
  • Store buffers: ~108

注:Physical register file 用于存放乱序执行流水线中 uop 的操作数,流水线中的 uop 通过指针指向 physical register file 来得到操作数

4 个节能核

  • L1 instruction cache: 128 KB
  • L1 data cache: 64 KB
  • L2 cache: 4MB
  • "E cluster" 主频 0.6-2.064GHz, 功率 <=1.3W

二、其他部件

8 核 GPU(苹果自研)

  • 每个 GPU 核包含 8 个执行部件(EU)
  • 每个执行部件包含 8 个 ALU
  • 一共 128 个 EU,1024 个 ALU
  • 可同时执行 25000 个线程
  • 浮点运算:2.6 TFLOPS

image.png

16 核神经网络计算引擎

  • 11 万亿次计算/秒

RAM

  • Unified Memory Architecutre (UMA)
    • CPU、GPU 等各个部件可以存取同一个物理内存
    • 省去了各部件之间进行内存拷贝,提高了效率
  • 8G 或 16G 4266 MT/s LPDDR4X SDRAM

三、兼容为 Intel 编译的程序

Rosetta 2 dynamic binary translation

  • 此技术可以让 M1 的设备运行为 Intel x86 CPU 编译的软件
  • 性能方面,与 Native 相比,在计算密集型的程序上表现差一些,基本在 70%+,详细数据见评测数据[4]。

四、参考资料