Xs、搬运描述字与 Cube shape¶
指令末尾的 Xs 是一个普通 64 位 X 寄存器,但消费指令会把它解释为打包配置字。以下布局已经由 dav-c220 代码生成和机器码结果逐字段核对;没有列出的专用 2D/3D、图像、压缩格式不能套用这些通用布局。
Vector repeat/stride 配置字¶
三源 Vector 常用配置字为:
| 位 | 宽度 | 字段 | 范围 | 作用 |
|---|---|---|---|---|
| 63:56 | 8 | repeat |
0..255 | repeat 次数 |
| 55:48 | 8 | 保留 | 必须为 0 | 不要承载应用数据 |
| 47:40 | 8 | src1_repeat_stride |
0..255 | 源 1 的 repeat 步长 |
| 39:32 | 8 | src0_repeat_stride |
0..255 | 源 0 的 repeat 步长 |
| 31:24 | 8 | dst_repeat_stride |
0..255 | 目标 repeat 步长 |
| 23:16 | 8 | src1_block_stride |
0..255 | 源 1 的 block 步长 |
| 15:8 | 8 | src0_block_stride |
0..255 | 源 0 的 block 步长 |
| 7:0 | 8 | dst_block_stride |
0..255 | 目标 block 步长 |
static inline unsigned long pack_vector_config(
unsigned repeat,
unsigned dst_block, unsigned src0_block, unsigned src1_block,
unsigned dst_repeat, unsigned src0_repeat, unsigned src1_repeat) {
return ((unsigned long)(repeat & 0xff) << 56) |
((unsigned long)(src1_repeat & 0xff) << 40) |
((unsigned long)(src0_repeat & 0xff) << 32) |
((unsigned long)(dst_repeat & 0xff) << 24) |
((unsigned long)(src1_block & 0xff) << 16) |
((unsigned long)(src0_block & 0xff) << 8) |
(dst_block & 0xff);
}
例如 pack_vector_config(1, 2, 3, 4, 5, 6, 7) 得到 0x0100070605040302。对应的 X 寄存器可直接作为:
步长字段的物理字节增量取决于数据类型、block 宽度和具体指令。不要把字段数值直接当成字节数,也不要把三源布局无条件用于归约、gather/scatter 或专用重排。
GM→UB 通用搬运描述字¶
通用五参数搬运描述字为:
| 位 | 宽度 | 字段 | 范围 |
|---|---|---|---|
| 63:48 | 16 | dst_stride |
0..65535 |
| 47:32 | 16 | src_stride |
0..65535 |
| 31:16 | 16 | burst_len |
0..65535 |
| 15:4 | 12 | nburst |
0..4095 |
| 3:0 | 4 | sid |
0..15 |
static inline unsigned long pack_gm_to_ub(
unsigned sid, unsigned nburst, unsigned burst_len,
unsigned src_stride, unsigned dst_stride) {
return ((unsigned long)(dst_stride & 0xffff) << 48) |
((unsigned long)(src_stride & 0xffff) << 32) |
((unsigned long)(burst_len & 0xffff) << 16) |
((unsigned long)(nburst & 0xfff) << 4) |
(sid & 0xf);
}
pack_gm_to_ub(1, 2, 3, 4, 5) 得到 0x0005000400030021。该布局对应普通 GM→UB 五参数路径;反向搬运通常复用 burst/stride 概念,但专用路由可能重解释字段。LOAD_IMAGE、压缩、Winograd、3D、transpose 和 Fixpipe 必须使用各自 builtin 生成配置,不能套用本表。
Cube shape¶
MMAD 的 shape 配置字为:
| 位 | 宽度 | 字段 | 范围 | 作用 |
|---|---|---|---|---|
| 11:0 | 12 | M |
0..4095 | M 维 |
| 23:12 | 12 | K |
0..4095 | K 维 |
| 35:24 | 12 | N |
0..4095 | N 维 |
| 61:36 | 26 | 保留 | 0 | 必须清零 |
| 62 | 1 | control0 |
0/1 | Cube 布尔控制 0 |
| 63 | 1 | control1 |
0/1 | Cube 布尔控制 1 |
static inline unsigned long pack_cube_shape(
unsigned m, unsigned k, unsigned n,
_Bool control0, _Bool control1) {
return ((unsigned long)control1 << 63) |
((unsigned long)control0 << 62) |
((unsigned long)(n & 0xfff) << 24) |
((unsigned long)(k & 0xfff) << 12) |
(m & 0xfff);
}
M=K=N=16 产生 0x0000000010010010。两个最高位在 c220 前端中确认为 _Bool,但其稳定公共名称没有暴露;手写汇编应从对应 Ascend C builtin 的 -S 输出复制,不应猜测为“累加”“清零”或其他模式。
构造规则¶
- 所有保留位清零。
- 先在 C/Ascend C 中按无符号 64 位构造,再用
-S核对生成的MOV/MOVK序列。 - 同一 X 寄存器可以先后承载不同配置字,但异步流水线尚未消费前不得覆盖其依赖状态。
- 配置字只描述迭代和地址生成;它不自动建立 MTE、Vector、Cube 之间的事件依赖。