P4C
The P4 Compiler
Loading...
Searching...
No Matches
parde_spec.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_PARDE_PARDE_SPEC_H_
20#define BACKENDS_TOFINO_BF_P4C_PARDE_PARDE_SPEC_H_
21
22#include <map>
23#include <vector>
24
25#include "bf-p4c/bf-p4c-options.h"
26#include "bf-p4c/ir/bitrange.h"
27#include "bf-p4c/parde/match_register.h"
28
29using namespace P4::literals;
30
379 public:
382 size_t byteIngressIntrinsicMetadataSize() const { return 8; }
383
387 virtual size_t bytePhase0Size() const = 0;
388 size_t bitPhase0Size() const { return bytePhase0Size() * 8; }
389
391 size_t bitResubmitTagSize() const { return 8; }
392 size_t byteResubmitTagSize() const { return 1; }
393
395 size_t bitResubmitSize() const { return bitPhase0Size(); }
396 size_t byteResubmitSize() const { return bytePhase0Size(); }
397
400 virtual size_t byteIngressPrePacketPaddingSize() const = 0;
401 size_t bitIngressPrePacketPaddingSize() const { return byteIngressPrePacketPaddingSize() * 8; }
402
408
410 int byteInputBufferSize() const { return 32; }
411
415
419 virtual const std::map<unsigned, unsigned> &extractorSpec() const = 0;
420
422 virtual const std::vector<MatchRegister> matchRegisters() const = 0;
423
425 virtual const std::vector<MatchRegister> scratchRegisters() const = 0;
426
427 // Region in the input buffer where the specified scratch register is located.
428 virtual const nw_bitrange bitScratchRegisterRange(const MatchRegister &reg) const = 0;
429
430 // Verifies if the provided range is a valid scratch register location.
431 virtual bool byteScratchRegisterRangeValid(nw_byterange range) const = 0;
432
434 virtual int numParsers() const = 0;
435
437 virtual int numTcamRows() const = 0;
438
440 virtual unsigned maxClotsPerState() const = 0;
441
443 virtual unsigned byteMaxClotSize() const = 0;
444
446 virtual unsigned numClotsPerGress() const = 0;
447
449 virtual unsigned maxClotsLivePerGress() const = 0;
450
452 virtual unsigned byteInterClotGap() const = 0;
453
455 virtual unsigned bitMinClotPos(gress_t) const = 0;
456
458 virtual unsigned bitMaxClotPos() const = 0;
459
461 virtual size_t minParseDepth(gress_t) const { return 0; }
462
464 virtual size_t maxParseDepth(gress_t) const { return SIZE_MAX; }
465
467 virtual bool parserAllExtractorsSupportSingleByte() const = 0;
468
469 // Number of deparser consant bytes available
470 virtual unsigned numDeparserConstantBytes() const = 0;
471
472 // Number deparser checksum units each gress can support
473 virtual unsigned numDeparserChecksumUnits() const = 0;
474
475 // Number of deparser checksum units that can invert its output
476 virtual unsigned numDeparserInvertChecksumUnits() const = 0;
477
478 // Deparser chunk size in bytes
479 virtual unsigned deparserChunkSize() const = 0;
480
481 // Deparser group size in chunks
482 virtual unsigned deparserChunkGroupSize() const = 0;
483
484 // Number of chunk groups in deparser
485 virtual unsigned numDeparserChunkGroups() const = 0;
486
487 // Number of clots in a single chunk group in deparser
488 virtual unsigned numClotsPerDeparserGroup() const = 0;
489
491 virtual double clkFreq() const = 0;
492
494 virtual unsigned lineRate() const = 0;
495
497 virtual const std::vector<std::string> &mdpValidVecFields() const = 0;
498
500 virtual const std::unordered_set<std::string> &mdpValidVecFieldsSet() const = 0;
501};
502
504 public:
505 size_t bytePhase0Size() const override { return 8; }
506 size_t byteIngressPrePacketPaddingSize() const override { return 0; }
507
508 const std::map<unsigned, unsigned> &extractorSpec() const override {
509 static const std::map<unsigned, unsigned> extractorSpec = {{8, 4}, {16, 4}, {32, 4}};
510 return extractorSpec;
511 }
512
513 const std::vector<MatchRegister> matchRegisters() const override {
514 static std::vector<MatchRegister> spec;
515
516 if (spec.empty()) {
517 spec = {MatchRegister("half"_cs), MatchRegister("byte0"_cs), MatchRegister("byte1"_cs)};
518 }
519
520 return spec;
521 }
522
523 const std::vector<MatchRegister> scratchRegisters() const override { return {}; }
524
525 const nw_bitrange bitScratchRegisterRange(const MatchRegister &reg) const override {
526 // Bug check while silencing unused variable warning.
527 BUG("Scratch registers not available in Tofino. Register: %1%", reg.name);
528 return nw_bitrange();
529 }
530
531 bool byteScratchRegisterRangeValid(nw_byterange) const override { return false; }
532
533 int numParsers() const override { return 18; }
534 int numTcamRows() const override { return 256; }
535
536 unsigned maxClotsPerState() const override { BUG("No CLOTs in Tofino"); }
537 unsigned byteMaxClotSize() const override { BUG("No CLOTs in Tofino"); }
538 unsigned numClotsPerGress() const override { return 0; }
539
540 unsigned maxClotsLivePerGress() const override { BUG("No CLOTs in Tofino"); }
541
542 unsigned byteInterClotGap() const override { BUG("No CLOTs in Tofino"); }
543
544 unsigned bitMinClotPos(gress_t) const override { BUG("No CLOTs in Tofino"); }
545 unsigned bitMaxClotPos() const override { BUG("No CLOTs in Tofino"); }
546
547 size_t minParseDepth(gress_t gress) const override { return gress == EGRESS ? 65 : 0; }
548
549 size_t maxParseDepth(gress_t gress) const override { return gress == EGRESS ? 160 : SIZE_MAX; }
550
551 bool parserAllExtractorsSupportSingleByte() const override { return false; }
552
553 unsigned numDeparserConstantBytes() const override { return 0; }
554 unsigned numDeparserChecksumUnits() const override { return 6; }
555 unsigned numDeparserInvertChecksumUnits() const override { return 0; }
556 unsigned deparserChunkSize() const { return 0; }
557 unsigned deparserChunkGroupSize() const { return 0; }
558 unsigned numDeparserChunkGroups() const { return 0; }
559 unsigned numClotsPerDeparserGroup() const { return 0; }
560
561 double clkFreq() const override { return 1.22; }
562 unsigned lineRate() const override { return 100; }
563
564 const std::vector<std::string> &mdpValidVecFields() const override {
565 static std::vector<std::string> vldVecFields;
566 return vldVecFields;
567 }
568
569 const std::unordered_set<std::string> &mdpValidVecFieldsSet() const override {
570 static std::unordered_set<std::string> vldVecSet;
571 return vldVecSet;
572 }
573};
574
575class JBayPardeSpec : public PardeSpec {
576 public:
577 size_t bytePhase0Size() const override { return 16; }
578 size_t byteIngressPrePacketPaddingSize() const override { return 8; }
579
580 const std::map<unsigned, unsigned> &extractorSpec() const override {
581 static const std::map<unsigned, unsigned> extractorSpec = {{16, 20}};
582 return extractorSpec;
583 }
584
585 const std::vector<MatchRegister> matchRegisters() const override {
586 static std::vector<MatchRegister> spec;
587
588 if (spec.empty()) {
589 spec = {MatchRegister("byte0"_cs), MatchRegister("byte1"_cs), MatchRegister("byte2"_cs),
590 MatchRegister("byte3"_cs)};
591 }
592
593 return spec;
594 }
595
596 const std::vector<MatchRegister> scratchRegisters() const override {
597 static std::vector<MatchRegister> spec;
598
599 if (spec.empty()) {
600 matchRegisters(); // make sure the match registers are created first
601
602 spec = {MatchRegister("save_byte0"_cs), MatchRegister("save_byte1"_cs),
603 MatchRegister("save_byte2"_cs), MatchRegister("save_byte3"_cs)};
604 }
605
606 return spec;
607 }
608
609 const nw_bitrange bitScratchRegisterRange(const MatchRegister &reg) const override {
610 if (reg.name == "save_byte0")
611 return nw_bitrange(504, 511);
612 else if (reg.name == "save_byte1")
613 return nw_bitrange(496, 503);
614 else if (reg.name == "save_byte2")
615 return nw_bitrange(488, 495);
616 else if (reg.name == "save_byte3")
617 return nw_bitrange(480, 487);
618 else
619 BUG("Invalid scratch register %1%", reg.name);
620 return nw_bitrange();
621 }
622
623 bool byteScratchRegisterRangeValid(nw_byterange range) const override {
624 return (range.lo >= 60) && (range.hi <= 63);
625 }
626
627 // TBD
628 int numParsers() const override { return 36; }
629 int numTcamRows() const override { return 256; }
630
631 unsigned maxClotsPerState() const override { return 2; }
632
633 // Cap max size to 56 as a workaround of TF2LAB-44
634 unsigned byteMaxClotSize() const override {
635 return BackendOptions().tof2lab44_workaround ? 56 : 64;
636 }
637
638 unsigned numClotsPerGress() const override { return 64; }
639 unsigned maxClotsLivePerGress() const override { return 16; }
640 unsigned byteInterClotGap() const override { return 3; }
641 unsigned bitMinClotPos(gress_t gress) const override {
642 return gress == EGRESS ? 28 * 8 : byteTotalIngressMetadataSize() * 8;
643 }
644 unsigned bitMaxClotPos() const override { return 384 * 8; /* 384 bytes */ }
645 bool parserAllExtractorsSupportSingleByte() const override { return true; }
646
647 unsigned numDeparserConstantBytes() const override { return 8; }
648 unsigned numDeparserChecksumUnits() const override { return 8; }
649 unsigned numDeparserInvertChecksumUnits() const override { return 4; }
650 unsigned deparserChunkSize() const { return 8; }
651 unsigned deparserChunkGroupSize() const { return 8; }
652 unsigned numDeparserChunkGroups() const { return 16; }
653 unsigned numClotsPerDeparserGroup() const { return 4; }
654
655 // FIXME: adjust to true clock rate
656 double clkFreq() const override { return 1.35; }
657 unsigned lineRate() const override { return 400; }
658
659 const std::vector<std::string> &mdpValidVecFields() const override {
660 static std::vector<std::string> vldVecFields;
661 return vldVecFields;
662 }
663
664 const std::unordered_set<std::string> &mdpValidVecFieldsSet() const override {
665 static std::unordered_set<std::string> vldVecSet;
666 return vldVecSet;
667 }
668};
669
671 public:
672 unsigned numDeparserInvertChecksumUnits() const override { return 0; }
673};
674
675#endif /* BACKENDS_TOFINO_BF_P4C_PARDE_PARDE_SPEC_H_ */
Definition parde_spec.h:670
Definition parde_spec.h:575
unsigned lineRate() const override
Max line rate per-port (Gbps)
Definition parde_spec.h:657
unsigned byteInterClotGap() const override
The minimum number of bytes required between consecutive CLOTs.
Definition parde_spec.h:640
const std::map< unsigned, unsigned > & extractorSpec() const override
Definition parde_spec.h:580
int numParsers() const override
Total parsers supported ingress/egress.
Definition parde_spec.h:628
unsigned maxClotsPerState() const override
The maximum number of CLOTs that can be generated in each parser state.
Definition parde_spec.h:631
const std::vector< MatchRegister > scratchRegisters() const override
Specifies the available scracth registers.
Definition parde_spec.h:596
const std::vector< MatchRegister > matchRegisters() const override
Specifies the available match registers.
Definition parde_spec.h:585
unsigned maxClotsLivePerGress() const override
The maximum number of CLOTs that can be live for each packet in each gress.
Definition parde_spec.h:639
const std::unordered_set< std::string > & mdpValidVecFieldsSet() const override
Unused.
Definition parde_spec.h:664
double clkFreq() const override
Clock frequency.
Definition parde_spec.h:656
unsigned bitMinClotPos(gress_t gress) const override
The minimum offset a CLOT can have, in bits.
Definition parde_spec.h:641
unsigned bitMaxClotPos() const override
The maximum offset+length a CLOT can have, in bits.
Definition parde_spec.h:644
int numTcamRows() const override
Total TCAM Rows supported ingress/egress.
Definition parde_spec.h:629
size_t byteIngressPrePacketPaddingSize() const override
Definition parde_spec.h:578
unsigned numClotsPerGress() const override
The number of CLOTs available for allocation in each gress.
Definition parde_spec.h:638
unsigned byteMaxClotSize() const override
The maximum number of bytes a CLOT can hold.
Definition parde_spec.h:634
const std::vector< std::string > & mdpValidVecFields() const override
Unused.
Definition parde_spec.h:659
size_t bytePhase0Size() const override
Definition parde_spec.h:577
bool parserAllExtractorsSupportSingleByte() const override
Do all extractors support single-byte extracts?
Definition parde_spec.h:645
Definition match_register.h:31
Definition parde_spec.h:378
virtual unsigned byteInterClotGap() const =0
The minimum number of bytes required between consecutive CLOTs.
virtual unsigned bitMaxClotPos() const =0
The maximum offset+length a CLOT can have, in bits.
virtual int numParsers() const =0
Total parsers supported ingress/egress.
virtual int numTcamRows() const =0
Total TCAM Rows supported ingress/egress.
virtual unsigned maxClotsLivePerGress() const =0
The maximum number of CLOTs that can be live for each packet in each gress.
virtual unsigned lineRate() const =0
Max line rate per-port (Gbps)
size_t byteIngressIntrinsicMetadataSize() const
Definition parde_spec.h:382
size_t bitResubmitTagSize() const
Definition parde_spec.h:391
virtual size_t maxParseDepth(gress_t) const
The maximum parse depth for the given gress.
Definition parde_spec.h:464
virtual const std::unordered_set< std::string > & mdpValidVecFieldsSet() const =0
Unused.
virtual size_t minParseDepth(gress_t) const
The minimum parse depth for the given gress.
Definition parde_spec.h:461
virtual unsigned numClotsPerGress() const =0
The number of CLOTs available for allocation in each gress.
virtual const std::vector< MatchRegister > scratchRegisters() const =0
Specifies the available scracth registers.
virtual const std::vector< std::string > & mdpValidVecFields() const =0
Unused.
int byteInputBufferSize() const
The size of input buffer, in bytes.
Definition parde_spec.h:410
virtual unsigned maxClotsPerState() const =0
The maximum number of CLOTs that can be generated in each parser state.
virtual unsigned bitMinClotPos(gress_t) const =0
The minimum offset a CLOT can have, in bits.
size_t bitResubmitSize() const
Definition parde_spec.h:395
virtual unsigned byteMaxClotSize() const =0
The maximum number of bytes a CLOT can hold.
virtual const std::vector< MatchRegister > matchRegisters() const =0
Specifies the available match registers.
virtual const std::map< unsigned, unsigned > & extractorSpec() const =0
virtual size_t bytePhase0Size() const =0
virtual size_t byteIngressPrePacketPaddingSize() const =0
nw_byterange byteInputBufferMetadataRange() const
Definition parde_spec.h:414
virtual double clkFreq() const =0
Clock frequency.
virtual bool parserAllExtractorsSupportSingleByte() const =0
Do all extractors support single-byte extracts?
size_t byteTotalIngressMetadataSize() const
Definition parde_spec.h:404
Definition parde_spec.h:503
const std::vector< MatchRegister > matchRegisters() const override
Specifies the available match registers.
Definition parde_spec.h:513
bool parserAllExtractorsSupportSingleByte() const override
Do all extractors support single-byte extracts?
Definition parde_spec.h:551
unsigned lineRate() const override
Max line rate per-port (Gbps)
Definition parde_spec.h:562
unsigned maxClotsLivePerGress() const override
The maximum number of CLOTs that can be live for each packet in each gress.
Definition parde_spec.h:540
unsigned maxClotsPerState() const override
The maximum number of CLOTs that can be generated in each parser state.
Definition parde_spec.h:536
const std::vector< std::string > & mdpValidVecFields() const override
Unused.
Definition parde_spec.h:564
size_t bytePhase0Size() const override
Definition parde_spec.h:505
unsigned byteMaxClotSize() const override
The maximum number of bytes a CLOT can hold.
Definition parde_spec.h:537
unsigned numClotsPerGress() const override
The number of CLOTs available for allocation in each gress.
Definition parde_spec.h:538
unsigned byteInterClotGap() const override
The minimum number of bytes required between consecutive CLOTs.
Definition parde_spec.h:542
size_t byteIngressPrePacketPaddingSize() const override
Definition parde_spec.h:506
const std::map< unsigned, unsigned > & extractorSpec() const override
Definition parde_spec.h:508
size_t minParseDepth(gress_t gress) const override
The minimum parse depth for the given gress.
Definition parde_spec.h:547
double clkFreq() const override
Clock frequency.
Definition parde_spec.h:561
size_t maxParseDepth(gress_t gress) const override
The maximum parse depth for the given gress.
Definition parde_spec.h:549
const std::vector< MatchRegister > scratchRegisters() const override
Specifies the available scracth registers.
Definition parde_spec.h:523
const std::unordered_set< std::string > & mdpValidVecFieldsSet() const override
Unused.
Definition parde_spec.h:569
unsigned bitMinClotPos(gress_t) const override
The minimum offset a CLOT can have, in bits.
Definition parde_spec.h:544
unsigned bitMaxClotPos() const override
The maximum offset+length a CLOT can have, in bits.
Definition parde_spec.h:545
int numParsers() const override
Total parsers supported ingress/egress.
Definition parde_spec.h:533
int numTcamRows() const override
Total TCAM Rows supported ingress/egress.
Definition parde_spec.h:534
Definition cstring.h:80
Definition lib/bitrange.h:158
Definition lib/bitrange.h:513
int lo
Definition lib/bitrange.h:694
int hi
Definition lib/bitrange.h:700