gen_trace.py
<<<<<<< HEAD
Script to generate human-readable instruction traces for Snitch.
This script takes a trace generated by a Snitch hart
(see snitch_cc.sv) and transforms the additional decode stage info
into meaningful annotation.
It also counts and computes various performance metrics for every
execution region. An execution region is a sequence of instructions.
Every mcycle CSR read instruction in your trace implicitly defines
two execution regions, comprising respectively:
- all instructions executed before the read, up to the previous read or the first executed instruction
- all instructions executed after the read, up to the next read or the last executed instruction
Performance metrics are appended at the end of the generated trace and can optionally be dumped to a separate JSON file.
It also computes various performance metrics for every DMA transfer, provided that the Snitch core is equipped with a tightly-coupled DMA engine, and the DMA trace logged during simulation is fed to the tool. DMA performance metrics are dumped to a separate JSON file.
disasm_inst(hex_inst, mc_exec='llvm-mc', mc_flags='-disassemble -mcpu=snitch')
cached
Disassemble a single RISC-V instruction using llvm-mc.
Source code in util/trace/gen_trace.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
flt_decode(val, fmt)
Interprets the binary encoding of an integer as a FP value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
int
|
The integer encoding of the FP variable to decode. |
required |
fmt
|
int
|
The floating point number format, as an index into the
|
required |
Returns: The floating point value represented by the input integer.
Source code in util/trace/gen_trace.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
flt_fmt(flt, width=6)
Formats a floating-point number rounding to a certain decimal precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flt
|
float
|
The floating-point number to format. |
required |
width
|
int
|
The number of significant decimal digits to round to. |
6
|
Returns: The formatted floating-point number as a string.
Source code in util/trace/gen_trace.py
503 504 505 506 507 508 509 510 511 512 513 | |
flt_lit(num, fmt, width=6, vlen=1)
Formats an integer encoding into a floating-point literal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The integer encoding of the floating-point number(s). |
required |
fmt
|
int
|
The floating point number format, as an index into the
|
required |
width
|
int
|
The number of significant decimal digits to round to. |
6
|
vlen
|
int
|
The number of floating-point numbers packed in the encoding,
|
1
|
Source code in util/trace/gen_trace.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
flt_op_fmt(extras, port)
Extracts the floating-point format of an instruction operand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extras
|
dict
|
The dictionary containing the instruction's extra information. |
required |
port
|
int
|
The index of the floating-point operand. |
required |
Source code in util/trace/gen_trace.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
flt_op_vlen(insn, op_type)
Get the vector length of a floating-point instruction operand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
insn
|
str
|
Instruction as extracted from the trace line. |
required |
op_type
|
str
|
One of the operand types defined in |
required |
Returns: The vector length of the operand, greater than one if SIMD.
Source code in util/trace/gen_trace.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
flt_oper(insn, extras, port)
Extracts details on the floating-point operand of an instruction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
insn
|
str
|
The current instruction mnemonic. |
required |
extras
|
dict
|
The dictionary containing the instruction's extra information. |
required |
port
|
int
|
The index of the floating-point operand. |
required |
Returns: A tuple containing the operand's register name and a string literal representing the floating-point value.
Source code in util/trace/gen_trace.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
fpu_operand_lit(num, fmt, is_vector, is_int)
Formats an FPU operand's data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
The integer encoding of the floating-point number(s). |
required | |
fmt
|
The floating point number format, as an index into the
|
required | |
width
|
The bitwidth of the floating-point type. |
required | |
vlen
|
The number of floating-point numbers packed in the encoding,
|
required |
Source code in util/trace/gen_trace.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
int_lit(num, size=2, vlen=1, as_hex=None)
Formats integer data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The integer data to format. |
required |
size
|
int
|
log2 of the size in bytes of each number (in the vector). |
2
|
vlen
|
int
|
The number of numbers packed in the encoding,
|
1
|
as_hex
|
Optional[bool]
|
If True, always format as hex. |
None
|
Source code in util/trace/gen_trace.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
=======
Script to generate human-readable instruction traces for Snitch.
This script takes a trace generated by a Snitch hart
(see snitch_cc.sv) and transforms the additional decode stage info
into meaningful annotation.
It also counts and computes various performance metrics for every
execution region. An execution region is a sequence of instructions.
Every mcycle CSR read instruction in your trace implicitly defines
two execution regions, comprising respectively:
- all instructions executed before the read, up to the previous read or the first executed instruction
- all instructions executed after the read, up to the next read or the last executed instruction
Performance metrics are appended at the end of the generated trace and can optionally be dumped to a separate JSON file.
It also computes various performance metrics for every DMA transfer, provided that the Snitch core is equipped with a tightly-coupled DMA engine, and the DMA trace logged during simulation is fed to the tool. DMA performance metrics are dumped to a separate JSON file.
disasm_inst(hex_inst, mc_exec='llvm-mc', mc_flags='-disassemble -mcpu=snitch')
cached
Disassemble a single RISC-V instruction using llvm-mc.
Source code in util/trace/gen_trace.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
flt_decode(val, fmt)
Interprets the binary encoding of an integer as a FP value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
int
|
The integer encoding of the FP variable to decode. |
required |
fmt
|
int
|
The floating point number format, as an index into the
|
required |
Returns: The floating point value represented by the input integer.
Source code in util/trace/gen_trace.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
flt_fmt(flt, width=6)
Formats a floating-point number rounding to a certain decimal precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flt
|
float
|
The floating-point number to format. |
required |
width
|
int
|
The number of significant decimal digits to round to. |
6
|
Returns: The formatted floating-point number as a string.
Source code in util/trace/gen_trace.py
503 504 505 506 507 508 509 510 511 512 513 | |
flt_lit(num, fmt, width=6, vlen=1)
Formats an integer encoding into a floating-point literal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The integer encoding of the floating-point number(s). |
required |
fmt
|
int
|
The floating point number format, as an index into the
|
required |
width
|
int
|
The number of significant decimal digits to round to. |
6
|
vlen
|
int
|
The number of floating-point numbers packed in the encoding,
|
1
|
Source code in util/trace/gen_trace.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
flt_op_fmt(extras, port)
Extracts the floating-point format of an instruction operand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extras
|
dict
|
The dictionary containing the instruction's extra information. |
required |
port
|
int
|
The index of the floating-point operand. |
required |
Source code in util/trace/gen_trace.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
flt_op_vlen(insn, op_type)
Get the vector length of a floating-point instruction operand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
insn
|
str
|
Instruction as extracted from the trace line. |
required |
op_type
|
str
|
One of the operand types defined in |
required |
Returns: The vector length of the operand, greater than one if SIMD.
Source code in util/trace/gen_trace.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
flt_oper(insn, extras, port)
Extracts details on the floating-point operand of an instruction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
insn
|
str
|
The current instruction mnemonic. |
required |
extras
|
dict
|
The dictionary containing the instruction's extra information. |
required |
port
|
int
|
The index of the floating-point operand. |
required |
Returns: A tuple containing the operand's register name and a string literal representing the floating-point value.
Source code in util/trace/gen_trace.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
fpu_operand_lit(num, fmt, is_vector, is_int)
Formats an FPU operand's data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
The integer encoding of the floating-point number(s). |
required | |
fmt
|
The floating point number format, as an index into the
|
required | |
width
|
The bitwidth of the floating-point type. |
required | |
vlen
|
The number of floating-point numbers packed in the encoding,
|
required |
Source code in util/trace/gen_trace.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
int_lit(num, size=2, vlen=1, as_hex=None)
Formats integer data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The integer data to format. |
required |
size
|
int
|
log2 of the size in bytes of each number (in the vector). |
2
|
vlen
|
int
|
The number of numbers packed in the encoding,
|
1
|
as_hex
|
Optional[bool]
|
If True, always format as hex. |
None
|
Source code in util/trace/gen_trace.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
c744477... trace: Refactor and prepare for DMA trace generation