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
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
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
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
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
494 495 496 497 498 499 500 501 502 503 504 |
|
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 bitwidth of the floating-point type. |
6
|
vlen |
int
|
The number of floating-point numbers packed in the encoding,
|
1
|
Source code in util/trace/gen_trace.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
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
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
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
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
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
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
=======
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
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
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
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
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
494 495 496 497 498 499 500 501 502 503 504 |
|
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 bitwidth of the floating-point type. |
6
|
vlen |
int
|
The number of floating-point numbers packed in the encoding,
|
1
|
Source code in util/trace/gen_trace.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
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
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
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
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
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
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
c744477... trace: Refactor and prepare for DMA trace generation