Line data Source code
1 : /*
2 : * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
3 : * Description: ccu instruction header file
4 : * Author: sunzhepeng
5 : * Create: 2024-05-14
6 : */
7 :
8 : #ifndef CCU_MICROCODE_H
9 : #define CCU_MICROCODE_H
10 :
11 : #include <cstdint>
12 : #include <string>
13 : #include <unordered_map>
14 : namespace hcomm {
15 : namespace CcuRep {
16 :
17 : constexpr uint16_t CCU_REDUCE_SUM = 0;
18 : constexpr uint16_t CCU_REDUCE_MAX = 1;
19 : constexpr uint16_t CCU_REDUCE_MIN = 2;
20 :
21 : constexpr uint16_t CCU_REDUCE_MIN_MS = 2;
22 : constexpr uint16_t CCU_REDUCE_MAX_MS = 8;
23 :
24 : constexpr uint64_t CCU_MS_SIZE = 4096;
25 : constexpr uint64_t CCU_MS_INTERLEAVE = 8;
26 : constexpr uint64_t CCU_MS_DEFAULT_LOOP_COUNT = 128;
27 :
28 : constexpr uint16_t CCU_LOAD_TO_XN_SEC_INFO = 1;
29 :
30 : #pragma pack(push, 1)
31 : // instr common header
32 : union CcuInstrHeader {
33 : struct {
34 : uint16_t code : 11;
35 : uint16_t type : 4;
36 : uint16_t reserved : 1;
37 : };
38 :
39 : uint16_t header;
40 : };
41 : #pragma pack(pop)
42 :
43 4845 : inline CcuInstrHeader InstrHeader(uint16_t type, uint16_t code)
44 : {
45 4845 : CcuInstrHeader header = {};
46 4845 : header.type = type;
47 4845 : header.code = code;
48 4845 : return header;
49 : }
50 :
51 : namespace CcuV1 {
52 :
53 : #pragma pack(push, 1)
54 : // load instruction
55 : struct CcuInstrLoadSqeArgsToGSA {
56 : uint16_t gsaId;
57 : uint16_t sqeArgsId;
58 : uint16_t reserved[13];
59 : };
60 :
61 : struct CcuInstrLoadSqeArgsToXn {
62 : uint16_t xnId;
63 : uint16_t sqeArgsId;
64 : uint16_t reserved[13];
65 : };
66 :
67 : struct CcuInstrLoadImdToGSA {
68 : uint16_t gsaId;
69 : uint64_t immediate;
70 : uint16_t reserved[10];
71 : };
72 :
73 : struct CcuInstrLoadImdToXn {
74 : uint16_t xnId;
75 : uint64_t immediate;
76 : uint16_t secFlag;
77 : uint16_t reserved[9];
78 : };
79 :
80 : struct CcuInstrLoadGSAXn {
81 : uint16_t gsAdId;
82 : uint16_t gsAmId;
83 : uint16_t xnId;
84 : uint16_t reserved[12];
85 : };
86 :
87 : struct CcuInstrLoadGSAGSA {
88 : uint16_t gsAdId;
89 : uint16_t gsAmId;
90 : uint16_t gsAnId;
91 : uint16_t reserved[12];
92 : };
93 :
94 : struct CcuInstrLoadXX {
95 : uint16_t xdId;
96 : uint16_t xmId;
97 : uint16_t xnId;
98 : uint16_t reserved[12];
99 : };
100 :
101 : // loop control instruction
102 : struct CcuInstrLoop {
103 : uint16_t startInstrId; // 开始指令地址Id
104 : uint16_t endInstrId; // 结束指令地址Id
105 : uint16_t xnId; // LoopCtxId[52:45], Offset[44:13], IterNum[12:0]
106 : uint16_t reserved[12];
107 : };
108 :
109 : struct CcuInstrLoopGroup {
110 : uint16_t startLoopInstrId; // 开始loop地址Id
111 : uint16_t xnId; // LoopNum[61:55], RepeatNum[54:48], NoRepeatNum[47:41]
112 : uint16_t xmId; // gsaOffset[52:21], MSOffset[20:10], ckeOffset[9:0]
113 : uint16_t highPerfModeEn : 1;
114 : uint16_t reserved1 : 15;
115 : uint16_t reserved[11];
116 : };
117 :
118 : struct CcuInstrSetCKE {
119 : uint16_t clearType : 1;
120 : uint16_t reserved1 : 15;
121 : uint16_t setCKEId;
122 : uint16_t setCKEMask;
123 : uint16_t waitCKEId;
124 : uint16_t waitCKEMask;
125 : uint16_t reserved[10];
126 : };
127 :
128 : struct CcuInstrClearCKE {
129 : uint16_t clearType : 1;
130 : uint16_t reserved1 : 15;
131 : uint16_t clearCKEId;
132 : uint16_t clearMask;
133 : uint16_t waitCKEId;
134 : uint16_t waitCKEMask;
135 : uint16_t reserved[10];
136 : };
137 :
138 : struct CcuInstrJmp {
139 : uint16_t dstInstrXnId;
140 : uint16_t conditionXnId;
141 : uint64_t expectData;
142 : };
143 :
144 : // data transfer instruction
145 : struct CcuInstrTransLocMemToLocMS {
146 : uint16_t locMSId;
147 : uint16_t locGSAId;
148 : uint16_t locXnId;
149 : uint16_t lengthXnId;
150 : uint16_t channelId;
151 : uint16_t reserved1[5];
152 : uint16_t clearType : 1;
153 : uint16_t lengthEn : 1;
154 : uint16_t reserved : 14;
155 : uint16_t setCKEId;
156 : uint16_t setCKEMask;
157 : uint16_t waitCKEId;
158 : uint16_t waitCKEMask;
159 : };
160 :
161 : struct CcuInstrTransRmtMemToLocMS {
162 : uint16_t locMSId;
163 : uint16_t rmtGSAId;
164 : uint16_t rmtXnId;
165 : uint16_t lengthXnId;
166 : uint16_t channelId;
167 : uint16_t reserved1[5];
168 : uint16_t clearType : 1;
169 : uint16_t lengthEn : 1;
170 : uint16_t reserved : 14;
171 : uint16_t setCKEId;
172 : uint16_t setCKEMask;
173 : uint16_t waitCKEId;
174 : uint16_t waitCKEMask;
175 : };
176 :
177 : struct CcuInstrTransLocMSToLocMem {
178 : uint16_t locGSAId;
179 : uint16_t locXnId;
180 : uint16_t locMSId;
181 : uint16_t lengthXnId;
182 : uint16_t channelId;
183 : uint16_t reserved1[5];
184 : uint16_t clearType : 1;
185 : uint16_t lengthEn : 1;
186 : uint16_t reserved : 14;
187 : uint16_t setCKEId;
188 : uint16_t setCKEMask;
189 : uint16_t waitCKEId;
190 : uint16_t waitCKEMask;
191 : };
192 :
193 : struct CcuInstrTransLocMSToRmtMem {
194 : uint16_t rmtGSAId;
195 : uint16_t rmtXnId;
196 : uint16_t locMSId;
197 : uint16_t lengthXnId;
198 : uint16_t channelId;
199 : uint16_t reserved1[5];
200 : uint16_t clearType : 1;
201 : uint16_t lengthEn : 1;
202 : uint16_t reserved : 14;
203 : uint16_t setCKEId;
204 : uint16_t setCKEMask;
205 : uint16_t waitCKEId;
206 : uint16_t waitCKEMask;
207 : };
208 :
209 : struct CcuInstrTransRmtMSToLocMem {
210 : uint16_t locGSAId;
211 : uint16_t locXnId;
212 : uint16_t rmtMSId;
213 : uint16_t lengthXnId;
214 : uint16_t channelId;
215 : uint16_t reserved1[5];
216 : uint16_t clearType : 1;
217 : uint16_t lengthEn : 1;
218 : uint16_t reserved : 14;
219 : uint16_t setCKEId;
220 : uint16_t setCKEMask;
221 : uint16_t waitCKEId;
222 : uint16_t waitCKEMask;
223 : };
224 :
225 : struct CcuInstrTransLocMSToLocMS {
226 : uint16_t dstMSId;
227 : uint16_t srcMSId;
228 : uint16_t lengthXnId;
229 : uint16_t channelId;
230 : uint16_t reserved1[6];
231 : uint16_t clearType : 1;
232 : uint16_t lengthEn : 1;
233 : uint16_t reserved : 14;
234 : uint16_t setCKEId;
235 : uint16_t setCKEMask;
236 : uint16_t waitCKEId;
237 : uint16_t waitCKEMask;
238 : };
239 :
240 : struct CcuInstrTransRmtMSToLocMS {
241 : uint16_t locMSId;
242 : uint16_t rmtMSId;
243 : uint16_t lengthXnId;
244 : uint16_t channelId;
245 : uint16_t reserved1[6];
246 : uint16_t clearType : 1;
247 : uint16_t lengthEn : 1;
248 : uint16_t reserved : 14;
249 : uint16_t setCKEId;
250 : uint16_t setCKEMask;
251 : uint16_t waitCKEId;
252 : uint16_t waitCKEMask;
253 : };
254 :
255 : struct CcuInstrTransLocMSToRmtMS {
256 : uint16_t rmtMSId;
257 : uint16_t locMSId;
258 : uint16_t lengthXnId;
259 : uint16_t channelId;
260 : uint16_t setRmtCKEId;
261 : uint16_t setRmtCKEMask;
262 : uint16_t reserved1[4];
263 : uint16_t clearType : 1;
264 : uint16_t lengthEn : 1;
265 : uint16_t reserved : 14;
266 : uint16_t setCKEId;
267 : uint16_t setCKEMask;
268 : uint16_t waitCKEId;
269 : uint16_t waitCKEMask;
270 : };
271 :
272 : struct CcuInstrTransRmtMemToLocMem {
273 : uint16_t locGSAId;
274 : uint16_t locXnId;
275 : uint16_t rmtGSAId;
276 : uint16_t rmtXnId;
277 : uint16_t lengthXnId;
278 : uint16_t channelId;
279 : uint16_t udfType : 8;
280 : uint16_t reduceDataType : 4;
281 : uint16_t reduceOpCode : 4;
282 : uint16_t reserved[3];
283 : uint16_t clearType : 1;
284 : uint16_t lengthEn : 1;
285 : uint16_t reduceEn : 1;
286 : uint16_t reserved1 : 13;
287 : uint16_t setCKEId;
288 : uint16_t setCKEMask;
289 : uint16_t waitCKEId;
290 : uint16_t waitCKEMask;
291 : };
292 :
293 : struct CcuInstrTransLocMemToRmtMem {
294 : uint16_t rmtGSAId;
295 : uint16_t rmtXnId;
296 : uint16_t locGSAId;
297 : uint16_t locXnId;
298 : uint16_t lengthXnId;
299 : uint16_t channelId;
300 : uint16_t udfType : 8;
301 : uint16_t reduceDataType : 4;
302 : uint16_t reduceOpCode : 4;
303 : uint16_t reserved[3];
304 : uint16_t clearType : 1;
305 : uint16_t lengthEn : 1;
306 : uint16_t reduceEn : 1;
307 : uint16_t reserved1 : 13;
308 : uint16_t setCKEId;
309 : uint16_t setCKEMask;
310 : uint16_t waitCKEId;
311 : uint16_t waitCKEMask;
312 : };
313 :
314 : struct CcuInstrTransLocMemToLocMem {
315 : uint16_t dstGSAId;
316 : uint16_t dstXnId;
317 : uint16_t srcGSAId;
318 : uint16_t srcXnId;
319 : uint16_t lengthXnId;
320 : uint16_t channelId;
321 : uint16_t reserved1[4];
322 : uint16_t clearType : 1;
323 : uint16_t lengthEn : 1;
324 : uint16_t reserved : 14;
325 : uint16_t setCKEId;
326 : uint16_t setCKEMask;
327 : uint16_t waitCKEId;
328 : uint16_t waitCKEMask;
329 : };
330 :
331 : struct CcuInstrSyncCKE {
332 : uint16_t rmtCKEId;
333 : uint16_t locCKEId;
334 : uint16_t locCKEMask;
335 : uint16_t channelId;
336 : uint16_t reserved[6];
337 : uint16_t clearType : 1;
338 : uint16_t reserved1 : 15;
339 : uint16_t setCKEId;
340 : uint16_t setCKEMask;
341 : uint16_t waitCKEId;
342 : uint16_t waitCKEMask;
343 : };
344 :
345 : struct CcuInstrSyncGSA {
346 : uint16_t rmtGSAId;
347 : uint16_t locGSAId;
348 : uint16_t reserved2;
349 : uint16_t channelId;
350 : uint16_t setRmtCKEId;
351 : uint16_t setRmtCKEMask;
352 : uint16_t reserved[4];
353 : uint16_t clearType : 1;
354 : uint16_t reserved1 : 15;
355 : uint16_t setCKEId;
356 : uint16_t setCKEMask;
357 : uint16_t waitCKEId;
358 : uint16_t waitCKEMask;
359 : };
360 :
361 : struct CcuInstrSyncXn {
362 : uint16_t rmtXnId;
363 : uint16_t locXnId;
364 : uint16_t reserved2;
365 : uint16_t channelId;
366 : uint16_t setRmtCKEId;
367 : uint16_t setRmtCKEMask;
368 : uint16_t reserved[4];
369 : uint16_t clearType : 1;
370 : uint16_t reserved1 : 15;
371 : uint16_t setCKEId;
372 : uint16_t setCKEMask;
373 : uint16_t waitCKEId;
374 : uint16_t waitCKEMask;
375 : };
376 :
377 : struct CcuInstrAdd {
378 : uint16_t msId[CCU_REDUCE_MAX_MS];
379 : uint16_t XnIdLength;
380 : uint16_t reserved;
381 : uint16_t clearType : 1;
382 : uint16_t count : 3;
383 : uint16_t castEn : 2;
384 : uint16_t reserved1 : 5;
385 : uint16_t dataType : 5;
386 : uint16_t setCKEId;
387 : uint16_t setCKEMask;
388 : uint16_t waitCKEId;
389 : uint16_t waitCKEMask;
390 : };
391 :
392 : struct CcuInstrMax {
393 : uint16_t msId[CCU_REDUCE_MAX_MS];
394 : uint16_t XnIdLength;
395 : uint16_t reserved;
396 : uint16_t clearType : 1;
397 : uint16_t count : 3;
398 : uint16_t reserved1 : 7;
399 : uint16_t dataType : 5;
400 : uint16_t setCKEId;
401 : uint16_t setCKEMask;
402 : uint16_t waitCKEId;
403 : uint16_t waitCKEMask;
404 : };
405 :
406 : struct CcuInstrMin {
407 : uint16_t msId[CCU_REDUCE_MAX_MS];
408 : uint16_t XnIdLength;
409 : uint16_t reserved;
410 : uint16_t clearType : 1;
411 : uint16_t count : 3;
412 : uint16_t reserved1 : 7;
413 : uint16_t dataType : 5;
414 : uint16_t setCKEId;
415 : uint16_t setCKEMask;
416 : uint16_t waitCKEId;
417 : uint16_t waitCKEMask;
418 : };
419 : #pragma pack(pop)
420 :
421 : union CcuMicroCodeV1 {
422 : CcuV1::CcuInstrLoadSqeArgsToGSA loadSqeArgsToGSA;
423 : CcuV1::CcuInstrLoadSqeArgsToXn loadSqeArgsToXn;
424 : CcuV1::CcuInstrLoadImdToGSA loadImdToGSA;
425 : CcuV1::CcuInstrLoadImdToXn loadImdToXn;
426 : CcuV1::CcuInstrLoadGSAXn loadGSAXn;
427 : CcuV1::CcuInstrLoadGSAGSA loadGSAGSA;
428 : CcuV1::CcuInstrLoadXX loadXX;
429 :
430 : CcuV1::CcuInstrLoop loop;
431 : CcuV1::CcuInstrLoopGroup loopGroup;
432 : CcuV1::CcuInstrSetCKE setCKE;
433 : CcuV1::CcuInstrClearCKE clearCKE;
434 : CcuV1::CcuInstrJmp jmp;
435 :
436 : CcuV1::CcuInstrTransLocMemToLocMS transLocMemToLocMS;
437 : CcuV1::CcuInstrTransRmtMemToLocMS transRmtMemToLocMS;
438 : CcuV1::CcuInstrTransLocMSToLocMem transLocMSToLocMem;
439 : CcuV1::CcuInstrTransLocMSToRmtMem transLocMSToRmtMem;
440 : CcuV1::CcuInstrTransRmtMSToLocMem transRmtMSToLocMem;
441 :
442 : CcuV1::CcuInstrTransLocMSToLocMS transLocMSToLocMS;
443 : CcuV1::CcuInstrTransRmtMSToLocMS transRmtMSToLocMS;
444 : CcuV1::CcuInstrTransLocMSToRmtMS transLocMSToRmtMS;
445 :
446 : CcuV1::CcuInstrTransRmtMemToLocMem transRmtMemToLocMem;
447 : CcuV1::CcuInstrTransLocMemToRmtMem transLocMemToRmtMem;
448 : CcuV1::CcuInstrTransLocMemToLocMem transLocMemToLocMem;
449 :
450 : CcuV1::CcuInstrSyncCKE syncCKE;
451 : CcuV1::CcuInstrSyncGSA syncGSA;
452 : CcuV1::CcuInstrSyncXn syncXn;
453 :
454 : CcuV1::CcuInstrAdd add;
455 : CcuV1::CcuInstrMax max;
456 : CcuV1::CcuInstrMin min;
457 : };
458 :
459 : }; // namespace CcuV1
460 :
461 : namespace CcuV2 {
462 :
463 : struct CacheConfig {
464 : uint16_t allocHint;
465 : uint16_t victimHint;
466 : };
467 :
468 : struct TransMemNotifyInfo {
469 : uint16_t xnId;
470 : uint16_t xntId;
471 : uint32_t value;
472 : };
473 :
474 : struct TransMemReduceInfo {
475 : uint16_t udfType;
476 : uint16_t reduceDataType;
477 : uint16_t reduceOpCode;
478 : };
479 :
480 : struct TransMemConfig {
481 : uint16_t dmaOpCode;
482 : uint16_t order;
483 : uint16_t fence;
484 : uint16_t cqe;
485 : uint16_t nf;
486 : uint16_t udfEnable;
487 : uint16_t splitMode;
488 : uint16_t se;
489 : uint16_t rmtJettyType;
490 : uint16_t src_mode;
491 : uint16_t dst_mode;
492 : uint16_t msIdMode;
493 : };
494 :
495 : #pragma pack(push, 1)
496 :
497 : // load instruction
498 : struct CcuInstrLoadSqeArgsToX {
499 : uint16_t xnId;
500 : uint16_t sqeArgsId;
501 : uint16_t reserved[11];
502 : uint16_t setCKEId;
503 : uint16_t setCKEMask;
504 : };
505 :
506 : struct CcuInstrLoadImdToX {
507 : uint16_t xnId;
508 : uint64_t immediate;
509 : uint16_t reserved[8];
510 : uint16_t setCKEId;
511 : uint16_t setCKEMask;
512 : };
513 :
514 : struct CcuInstrLoadStoreX {
515 : uint16_t xdId;
516 : uint16_t xsId;
517 : uint16_t xsoId;
518 : uint16_t xdoId;
519 : uint16_t oMode : 1;
520 : uint16_t reserved : 15;
521 : uint16_t reserved1[8];
522 : uint16_t setCKEId;
523 : uint16_t setCKEMask;
524 : };
525 :
526 : struct CcuInstrClearX {
527 : uint16_t xnId : 15;
528 : uint16_t xnIdMode : 1;
529 : uint16_t xmId : 15;
530 : uint16_t xmIdMode : 1;
531 : uint16_t reserved[11];
532 : uint16_t setCKEId;
533 : uint16_t setCKEMask;
534 : };
535 :
536 : struct CcuInstrNop {
537 : uint16_t reserved[15];
538 : };
539 :
540 : struct CcuInstrLoad {
541 : uint16_t xdId;
542 : uint16_t xsId;
543 : uint16_t xstId;
544 : uint16_t xlId;
545 : uint16_t reserved[6];
546 : uint16_t dstType : 4;
547 : uint16_t allocHint : 2;
548 : uint16_t victimHint : 2;
549 : uint16_t reserved1 : 8;
550 : uint16_t reserved2[2];
551 : uint16_t setCKEId;
552 : uint16_t setCKEMask;
553 : };
554 :
555 : struct CcuInstrStore {
556 : uint16_t xdId;
557 : uint16_t xdtId;
558 : uint16_t xsId;
559 : uint16_t xlId;
560 : uint16_t xhId;
561 : uint16_t reserved[5];
562 : uint16_t srcType : 4;
563 : uint16_t allocHint : 2;
564 : uint16_t victimHint : 2;
565 : uint16_t storeType : 1;
566 : uint16_t hscbType : 1;
567 : uint16_t hscbBroadCastDstType : 6;
568 : uint16_t reserved1[2];
569 : uint16_t setCKEId;
570 : uint16_t setCKEMask;
571 : };
572 :
573 : // 运算符复用相同的结构体
574 : // 左移右移:需要指定shiftType
575 : // A = B@C类算子,需要指定xd, xn, xm
576 : // 按位非,需要指定xd, xn
577 : // popcnt,需要指定xd, xn
578 : struct CcuInstrOperator {
579 : uint16_t xdId;
580 : uint16_t xnId;
581 : uint16_t xmId;
582 : uint16_t parMode : 1;
583 : uint16_t reserved : 15;
584 : uint16_t reserved1[6];
585 : uint16_t shiftType : 1;
586 : uint16_t reserved2 : 15;
587 : uint16_t reserved3[2];
588 : uint16_t setCKEId;
589 : uint16_t setCKEMask;
590 : };
591 :
592 : // loop control instruction
593 : struct CcuInstrLoop {
594 : uint16_t startInstrId; // 开始指令地址Id
595 : uint16_t endInstrId; // 结束指令地址Id
596 : uint16_t xmId; // IterNum[12:0]
597 : uint16_t xnId; // Offset[31:0]
598 : uint16_t xpId; // LoopCtxId[8:0]
599 : uint16_t wishCKEBit;
600 : uint16_t mode : 1;
601 : uint16_t reserved : 15;
602 : uint16_t reserved1[8];
603 : };
604 :
605 : struct CcuInstrLoopGroup {
606 : uint16_t startLoopInstrId; // 开始loop地址Id
607 : uint16_t xnId; // ExtendNum[22:16], RepeatLoopIndex[15:9], LoopNum[8:0]
608 : uint16_t xmId; // gsaOffset[52:21], MSOffset[20:10], ckeOffset[9:0]
609 : uint16_t xpId; // xnOffset[31:0]
610 : uint16_t reserved[11];
611 : };
612 :
613 : struct CcuInstrSetCKE {
614 : uint16_t clearType : 1;
615 : uint16_t reserved : 15;
616 : uint16_t setCKEId;
617 : uint16_t setCKEMask;
618 : uint16_t waitCKEId;
619 : uint16_t waitCKEMask;
620 : uint64_t userData;
621 : uint16_t reserved1[6];
622 : };
623 :
624 : struct CcuInstrClearCKE {
625 : uint16_t clearType : 1;
626 : uint16_t reserved : 15;
627 : uint16_t clearCKEId;
628 : uint16_t clearMask;
629 : uint16_t waitCKEId;
630 : uint16_t waitCKEMask;
631 : uint16_t reserved1[10];
632 : };
633 :
634 : struct CcuInstrJmp {
635 : uint16_t expectedXnId;
636 : uint16_t conditionXnId;
637 : uint16_t relTarInstrXnId;
638 : uint16_t conditionType : 4;
639 : uint16_t jumpMode : 1;
640 : uint16_t reserved : 11;
641 : uint16_t reserved1[11];
642 : };
643 :
644 : struct CcuInstrWait {
645 : uint16_t conditionXnId; // Xn
646 : uint16_t expectedXnId; // Xm
647 : uint16_t conditionType : 4;
648 : uint16_t reserved : 12;
649 : uint16_t reserved1[12];
650 : };
651 :
652 : struct CcuInstrFence {
653 : uint16_t reserved[15];
654 : };
655 :
656 : // data transfer instruction
657 : struct CcuInstrTransLocMemToLocMS {
658 : uint16_t msId;
659 : uint16_t xsId;
660 : uint16_t xstId;
661 : uint16_t xlId;
662 : uint16_t xoId;
663 : uint16_t allocHint : 2;
664 : uint16_t victimHint : 2;
665 : uint16_t reserved : 12;
666 : uint16_t reserved1[7];
667 : uint16_t setCKEId;
668 : uint16_t setCKEMask;
669 : };
670 :
671 : struct CcuInstrTransLocMSToLocMem {
672 : uint16_t xdId;
673 : uint16_t xdtId;
674 : uint16_t msId;
675 : uint16_t xlId;
676 : uint16_t xoId;
677 : uint16_t allocHint : 2;
678 : uint16_t victimHint : 2;
679 : uint16_t reserved : 12;
680 : uint16_t reserved1[7];
681 : uint16_t setCKEId;
682 : uint16_t setCKEMask;
683 : };
684 :
685 : struct CcuInstrTransLocMSToLocMS {
686 : uint16_t msdId;
687 : uint16_t mssId;
688 : uint16_t xlId;
689 : uint16_t xoId;
690 : uint16_t reserved[9];
691 : uint16_t setCKEId;
692 : uint16_t setCKEMask;
693 : };
694 :
695 : struct CcuInstrTransLocMemToLocMem {
696 : uint16_t xdId;
697 : uint16_t xdtId;
698 : uint16_t xsId;
699 : uint16_t xstId;
700 : uint16_t xlId;
701 : uint16_t usedMSId;
702 : uint16_t srcAllocHint : 2;
703 : uint16_t srcVictimHint : 2;
704 : uint16_t dstAllocHint : 2;
705 : uint16_t dstVictimHint : 2;
706 : uint16_t msNum : 8;
707 : uint16_t reserved1[6];
708 : uint16_t setCKEId;
709 : uint16_t setCKEMask;
710 : };
711 :
712 : struct CcuInstrTransMem {
713 : uint16_t xdId; // 存储目的内存地址
714 : uint16_t xdtId; // 存储目的内存Token
715 : uint16_t xsId; // 存储源内存地址
716 : uint16_t xstId; // 存储源内存Token
717 : uint16_t xlId; // 存储要搬运的数据长度
718 : uint16_t xcId; // 存储使用的channelId
719 : uint16_t xnId; // 存储notify/atomic的目的地址
720 : uint16_t xntId; // 存储notify/atomic的目的Token
721 : uint32_t value; // notify value, atomic store add value, immeidata data, 视不同的opCode确定, 只支持32bit
722 : uint16_t udfType : 8;
723 : uint16_t reduceDataType : 4;
724 : uint16_t reduceOpCode : 4;
725 : uint16_t dmaOpCode : 8; // wqe中的opcode,支持0x0: send,0x1: send with immediata,0x3: Write,0x5: Write
726 : // with Notify,0x6: Read,0x70: Write with atomic store add
727 : uint16_t order : 3;
728 : uint16_t fence : 1;
729 : uint16_t cqe : 1;
730 : uint16_t nf : 1; // No Fragment, 不允许分片
731 : uint16_t udfEnable : 1;
732 : uint16_t splitMode : 1;
733 : uint16_t se : 1; // Solicited Event,Responder基于se来判断生成CQE时是否产生Completion Event
734 : uint16_t rmtJettyType : 2; // 00: JFR, 01: Jetty,10: JettyGroup,11: reserved
735 : uint16_t src_mode : 1;
736 : uint16_t dst_mode : 1;
737 : uint16_t msIdMode : 1; // 标记是否使用transmem的msId模式
738 : uint16_t reserved : 2;
739 : uint16_t targetHint : 8;
740 : uint16_t setCKEId;
741 : uint16_t setCKEMask;
742 : };
743 :
744 : // SyncWtX指令固定将一个指定Xn的信息同步,固定8B
745 : struct CcuInstrSyncWtX {
746 : uint16_t xdId; // 存储目的Xn寄存器的地址
747 : uint16_t xdtId; // 存储目的Xn寄存器Token
748 : uint16_t xsId; // 存储源Xn寄存器Id
749 : uint16_t xcId; // 存储使用的channelId
750 : uint16_t xnId; // 存储notify/atomic的目的地址
751 : uint16_t xntId; // 存储notify/atomic的目的Token
752 : uint32_t value; // notify value, 只支持32bit
753 : uint16_t notifyValid : 1;
754 : uint16_t parMode : 1;
755 : uint16_t reserved : 14;
756 : uint16_t reserved1[4];
757 : uint16_t setCKEId;
758 : uint16_t setCKEMask;
759 : };
760 :
761 : // SyncAtX指令以write with atomic store add发往对端,其中write的数据长度为0,本端Xn的值是写在atomic
762 : // value中进行发送
763 : struct CcuInstrSyncAtX {
764 : uint16_t xdId; // 存储目的Xn寄存器的地址
765 : uint16_t xdtId; // 存储目的Xn寄存器Token
766 : uint16_t xsId; // 存储源Xn寄存器Id
767 : uint16_t xcId; // 存储使用的channelId
768 : uint16_t reserved : 1;
769 : uint16_t parMode : 1;
770 : uint16_t reserved1 : 14;
771 : uint16_t reserved2[8];
772 : uint16_t setCKEId;
773 : uint16_t setCKEMask;
774 : };
775 :
776 : // reduce instruction
777 : // add: 配置castEn
778 : // max和min: castEn保持默认为0
779 : struct CcuInstrReduce {
780 : uint16_t msId[CCU_REDUCE_MAX_MS];
781 : uint16_t XnIdLength;
782 : uint16_t reserved;
783 : uint16_t reserved1 : 1;
784 : uint16_t count : 3;
785 : uint16_t castEn : 2;
786 : uint16_t reserved2 : 5;
787 : uint16_t dataType : 5;
788 : uint16_t reserved3[2];
789 : uint16_t setCKEId;
790 : uint16_t setCKEMask;
791 : };
792 :
793 : #pragma pack(pop)
794 :
795 : union CcuMicroCodeV2 {
796 : CcuV2::CcuInstrLoadSqeArgsToX loadSqeArgsToX;
797 : CcuV2::CcuInstrLoadImdToX loadImdToX;
798 : CcuV2::CcuInstrLoadStoreX loadStoreX;
799 : CcuV2::CcuInstrClearX clearX;
800 : CcuV2::CcuInstrNop nop;
801 : CcuV2::CcuInstrOperator operate;
802 : CcuV2::CcuInstrLoad load;
803 : CcuV2::CcuInstrStore store;
804 :
805 : CcuV2::CcuInstrLoop loop;
806 : CcuV2::CcuInstrLoopGroup loopGroup;
807 : CcuV2::CcuInstrSetCKE setCKE;
808 : CcuV2::CcuInstrClearCKE clearCKE;
809 : CcuV2::CcuInstrJmp jmp;
810 : CcuV2::CcuInstrWait wait;
811 : CcuV2::CcuInstrFence fence;
812 :
813 : CcuV2::CcuInstrTransLocMemToLocMS transLocMemToLocMS;
814 : CcuV2::CcuInstrTransLocMSToLocMem transLocMSToLocMem;
815 : CcuV2::CcuInstrTransLocMSToLocMS transLocMSToLocMS;
816 : CcuV2::CcuInstrTransLocMemToLocMem transLocMemToLocMem;
817 : CcuV2::CcuInstrTransMem transMem;
818 : CcuV2::CcuInstrSyncWtX syncWtX;
819 : CcuV2::CcuInstrSyncAtX syncAtX;
820 :
821 : CcuV2::CcuInstrReduce reduce;
822 : };
823 : }; // namespace CcuV2
824 :
825 : struct CcuInstr {
826 : CcuInstrHeader header;
827 : union {
828 : CcuV1::CcuMicroCodeV1 v1;
829 : CcuV2::CcuMicroCodeV2 v2;
830 : };
831 : };
832 :
833 : std::string ParseInstr(const CcuInstr* instr);
834 :
835 : void LoadSqeArgsToGSAInstr(CcuInstr* instr, uint16_t gsaId, uint16_t sqeArgsId);
836 : void LoadSqeArgsToXnInstr(CcuInstr* instr, uint16_t xnId, uint16_t sqeArgsId);
837 : void LoadImdToGSAInstr(CcuInstr* instr, uint16_t gsaId, uint64_t immediate);
838 : void LoadImdToXnInstr(CcuInstr* instr, uint16_t xnId, uint64_t immediate, uint16_t secFlag = 0);
839 : void LoadGSAXnInstr(CcuInstr* instr, uint16_t gsAdId, uint16_t gsAmId, uint16_t xnId);
840 : void LoadGSAGSAInstr(CcuInstr* instr, uint16_t gsAdId, uint16_t gsAmId, uint16_t gsAnId);
841 : void LoadXXInstr(CcuInstr* instr, uint16_t xdId, uint16_t xmId, uint16_t xnId);
842 :
843 : void LoopInstr(CcuInstr* instr, uint16_t startInstrId, uint16_t endInstrId, uint16_t xnId);
844 : void
845 : LoopGroupInstr(CcuInstr* instr, uint16_t startLoopInstrId, uint16_t xnId, uint16_t xmId, uint16_t highPerfModeEn);
846 : void JumpInstr(CcuInstr* instr, uint16_t dstInstrXnId, uint16_t conditionXnId, uint64_t expectData);
847 : void SetCKEInstr(
848 : CcuInstr* instr, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
849 : uint16_t clearType);
850 : void ClearCKEInstr(
851 : CcuInstr* instr, uint16_t clearCKEId, uint16_t clearMask, uint16_t waitCKEId, uint16_t waitCKEMask,
852 : uint16_t clearType);
853 :
854 : void TransLocMemToLocMSInstr(
855 : CcuInstr* instr, uint16_t locMSId, uint16_t locGSAId, uint16_t locXnId, uint16_t lengthXnId, uint16_t channelId,
856 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
857 : uint16_t lengthEn);
858 : void TransRmtMemToLocMSInstr(
859 : CcuInstr* instr, uint16_t locMSId, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t lengthXnId, uint16_t channelId,
860 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
861 : uint16_t lengthEn);
862 : void TransLocMSToLocMemInstr(
863 : CcuInstr* instr, uint16_t locGSAId, uint16_t locXnId, uint16_t locMSId, uint16_t lengthXnId, uint16_t channelId,
864 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
865 : uint16_t lengthEn);
866 : void TransLocMSToRmtMemInstr(
867 : CcuInstr* instr, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t locMSId, uint16_t lengthXnId, uint16_t channelId,
868 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
869 : uint16_t lengthEn);
870 : void TransRmtMSToLocMemInstr(
871 : CcuInstr* instr, uint16_t locGSAId, uint16_t locXnId, uint16_t rmtMSId, uint16_t lengthXnId, uint16_t channelId,
872 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
873 : uint16_t lengthEn);
874 :
875 : void TransLocMSToLocMSInstr(
876 : CcuInstr* instr, uint16_t dstMSId, uint16_t srcMSId, uint16_t lengthXnId, uint16_t channelId, uint16_t setCKEId,
877 : uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn);
878 : void TransRmtMSToLocMSInstr(
879 : CcuInstr* instr, uint16_t locMSId, uint16_t rmtMSId, uint16_t lengthXnId, uint16_t channelId, uint16_t setCKEId,
880 : uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn);
881 : void TransLocMSToRmtMSInstr(
882 : CcuInstr* instr, uint16_t rmtMSId, uint16_t locMSId, uint16_t lengthXnId, uint16_t channelId,
883 : uint16_t setRmtCKEId, uint16_t setRmtCKEMask, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId,
884 : uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn);
885 :
886 : void TransRmtMemToLocMemInstr(
887 : CcuInstr* instr, uint16_t locGSAId, uint16_t locXnId, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t lengthXnId,
888 : uint16_t channelId, uint16_t reduceDataType, uint16_t reduceOpCode, uint16_t setCKEId, uint16_t setCKEMask,
889 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn, uint16_t reduceEn);
890 : void TransLocMemToRmtMemInstr(
891 : CcuInstr* instr, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t locGSAId, uint16_t locXnId, uint16_t lengthXnId,
892 : uint16_t channelId, uint16_t reduceDataType, uint16_t reduceOpCode, uint16_t setCKEId, uint16_t setCKEMask,
893 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn, uint16_t reduceEn);
894 : void TransLocMemToLocMemInstr(
895 : CcuInstr* instr, uint16_t dstGSAId, uint16_t dstXnId, uint16_t srcGSAId, uint16_t srcXnId, uint16_t lengthXnId,
896 : uint16_t channelId, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
897 : uint16_t clearType, uint16_t lengthEn);
898 :
899 : void SyncCKEInstr(
900 : CcuInstr* instr, uint16_t rmtCKEId, uint16_t locCKEId, uint16_t locCKEMask, uint16_t channelId,
901 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType);
902 : void SyncGSAInstr(
903 : CcuInstr* instr, uint16_t rmtGSAId, uint16_t locGSAId, uint16_t channelId, uint16_t setRmtCKEId,
904 : uint16_t setRmtCKEMask, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
905 : uint16_t clearType);
906 : void SyncXnInstr(
907 : CcuInstr* instr, uint16_t rmtXnId, uint16_t locXnId, uint16_t channelId, uint16_t setRmtCKEId,
908 : uint16_t setRmtCKEMask, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
909 : uint16_t clearType);
910 :
911 : void AddInstr(
912 : CcuInstr* instr, uint16_t* msId, uint16_t count, uint16_t castEn, uint16_t dataType, uint16_t setCKEId,
913 : uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t XnIdLength);
914 : void MaxInstr(
915 : CcuInstr* instr, uint16_t* msId, uint16_t count, uint16_t dataType, uint16_t setCKEId, uint16_t setCKEMask,
916 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t XnIdLength);
917 : void MinInstr(
918 : CcuInstr* instr, uint16_t* msId, uint16_t count, uint16_t dataType, uint16_t setCKEId, uint16_t setCKEMask,
919 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t XnIdLength);
920 :
921 : namespace CcuV2 {
922 : void Nop(CcuInstr* instr);
923 :
924 : void LoadSqeArgsToX(
925 : CcuInstr* instr, uint16_t xnId, uint16_t sqeArgsId, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
926 : void
927 : LoadImdToXn(CcuInstr* instr, uint16_t xnId, uint64_t immediate, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
928 : void ClearX(
929 : CcuInstr* instr, uint16_t xnId, uint16_t xmId, uint16_t xnIdMode = 0, uint16_t xmIdMode = 0,
930 : uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
931 : void LoadXFromMem(
932 : CcuInstr* instr, uint16_t dst, uint16_t src, uint16_t srcToken, uint16_t len,
933 : const CacheConfig& cacheConfig, uint16_t setCKEId, uint16_t setCKEMask);
934 : void StoreXToMem(
935 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t src, uint16_t len,
936 : const CacheConfig& cacheConfig, uint16_t setCKEId, uint16_t setCKEMask);
937 : void HSCBStoreXToMem(
938 : CcuInstr* instr, uint16_t dst, uint16_t src, uint16_t len, const CacheConfig& cacheConfig,
939 : uint16_t setCKEId, uint16_t setCKEMask);
940 :
941 : void Assign(CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
942 : void
943 : AssignI(CcuInstr* instr, uint16_t result, uint64_t operand, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
944 :
945 : void
946 : Add(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
947 : uint16_t setCKEMask = 0);
948 : void AddI(
949 : CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t imm, uint16_t setCKEId = 0,
950 : uint16_t setCKEMask = 0);
951 : void
952 : Sub(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
953 : uint16_t setCKEMask = 0);
954 : void SubI(
955 : CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t imm, uint16_t setCKEId = 0,
956 : uint16_t setCKEMask = 0);
957 : void
958 : Mul(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
959 : uint16_t setCKEMask = 0);
960 : void MulI(
961 : CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t imm, uint16_t setCKEId = 0,
962 : uint16_t setCKEMask = 0);
963 :
964 : void
965 : And(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
966 : uint16_t setCKEMask = 0);
967 : void
968 : Or(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
969 : uint16_t setCKEMask = 0);
970 : void
971 : Xor(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
972 : uint16_t setCKEMask = 0);
973 : void Not(CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
974 :
975 : void
976 : SLL(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
977 : uint16_t setCKEMask = 0);
978 : void
979 : SRL(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
980 : uint16_t setCKEMask = 0);
981 : void
982 : SLA(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
983 : uint16_t setCKEMask = 0);
984 : void
985 : SRA(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
986 : uint16_t setCKEMask = 0);
987 :
988 : void Loop(
989 : CcuInstr* instr, uint16_t startInstrId, uint16_t endInstrId, uint16_t iterNum, uint16_t offset,
990 : uint16_t contextId);
991 : void LoopGroup(
992 : CcuInstr* instr, uint16_t startLoopInstrId, uint16_t loopGroupConfig, uint16_t resOffset,
993 : uint16_t xnOffset);
994 : void Jump(
995 : CcuInstr* instr, uint16_t relTarInstrXnId, uint16_t conditionXnId, uint16_t expectedXnId,
996 : uint16_t conditionType);
997 : void Wait(CcuInstr* instr, uint16_t conditionXnId, uint16_t expectedXnId, uint16_t conditionType);
998 : void Fence(CcuInstr* instr);
999 : void SetCKE(
1000 : CcuInstr* instr, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
1001 : uint16_t clearType);
1002 : void ClearCKE(
1003 : CcuInstr* instr, uint16_t clearCKEId, uint16_t clearMask, uint16_t waitCKEId, uint16_t waitCKEMask,
1004 : uint16_t clearType);
1005 :
1006 : void TransLocMemToLocMS(
1007 : CcuInstr* instr, uint16_t ms, uint16_t src, uint16_t srcToken, uint16_t len, uint16_t offset,
1008 : uint16_t setCKEId, uint16_t setCKEMask, const CacheConfig& cacheConfig);
1009 : void TransLocMSToLocMem(
1010 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t ms, uint16_t len, uint16_t offset,
1011 : uint16_t setCKEId, uint16_t setCKEMask, const CacheConfig& cacheConfig);
1012 : void TransLocMemToLocMem(
1013 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t src, uint16_t srcToken, uint16_t len,
1014 : uint16_t usedMSId, uint16_t usedMSNum, uint16_t setCKEId, uint16_t setCKEMask,
1015 : const CacheConfig& srcCacheConfig, const CacheConfig& dstcacheConfig);
1016 : void TransMem(
1017 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t src, uint16_t srcToken, uint16_t len,
1018 : uint16_t channel, const TransMemNotifyInfo& notify, const TransMemReduceInfo& reduce,
1019 : const TransMemConfig& config, uint16_t setCKEId, uint16_t setCKEMask);
1020 : void SyncWtX(
1021 : CcuInstr* instr, const TransMemNotifyInfo& notify, uint16_t channelId, uint16_t setCKEId,
1022 : uint16_t setCKEMask);
1023 : void SyncWtX(
1024 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t xn, uint16_t channelId,
1025 : const TransMemNotifyInfo& notify, uint16_t setCKEId, uint16_t setCKEMask);
1026 : void SyncAtX(
1027 : CcuInstr* instr, uint16_t dstAddr, uint16_t dstToken, uint16_t srcId, uint16_t channelId, uint16_t setCKEId,
1028 : uint16_t setCKEMask);
1029 : void ReduceAdd(
1030 : CcuInstr* instr, const uint16_t* ms, uint16_t count, uint16_t castEn, uint16_t dataType, uint16_t setCKEId,
1031 : uint16_t setCKEMask, uint16_t XnIdLength);
1032 : void ReduceMax(
1033 : CcuInstr* instr, const uint16_t* ms, uint16_t count, uint16_t dataType, uint16_t setCKEId,
1034 : uint16_t setCKEMask, uint16_t XnIdLength);
1035 : void ReduceMin(
1036 : CcuInstr* instr, const uint16_t* ms, uint16_t count, uint16_t dataType, uint16_t setCKEId,
1037 : uint16_t setCKEMask, uint16_t XnIdLength);
1038 : void RelJmp(CcuInstr* instr, uint16_t targetXnId, uint32_t jmpInstrId, uint16_t xn0, uint16_t xn1);
1039 : std::string ParseInstrV2(const CcuInstr* instr);
1040 : }; // namespace CcuV2
1041 :
1042 : }; // namespace CcuRep
1043 : }; // namespace hcomm
1044 :
1045 : #endif // CCU_MICROCODE_H
|