Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from1.0: fix signed register type #3117

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontends/p4/fromv1.0/programStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ ProgramStructure::convert(const IR::Register* reg, cstring newName,
regElementType = new IR::Type_Name(new IR::Path(str->name));
// use provided type
} else if (reg->width > 0) {
regElementType = IR::Type_Bits::get(reg->width);
regElementType = IR::Type_Bits::get(reg->width, reg->signed_);
} else if (reg->layout) {
cstring newName = ::get(registerLayoutType, reg->layout);
if (newName.isNullOrEmpty())
Expand Down
72 changes: 72 additions & 0 deletions testdata/p4_14_samples/register_signed.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
header_type ethernet_t {
fields {
dstAddr : 48;
srcAddr : 48;
etherType : 16;
}
}

header_type intrinsic_metadata_t {
fields {
mcast_grp : 4;
egress_rid : 4;
}
}

header_type meta_t {
fields {
register_tmp : 32 (signed);
}
}

metadata meta_t meta;

parser start {
return parse_ethernet;
}

header ethernet_t ethernet;
metadata intrinsic_metadata_t intrinsic_metadata;

parser parse_ethernet {
extract(ethernet);
return ingress;
}

action _drop() {
drop();
}

action _nop() {
}

register my_register {
width: 32;
static: m_table;
instance_count: 16384;
attributes: signed;
}

action m_action(register_idx) {
// modify_field_rng_uniform(meta.register_tmp, 100, 200);
// register_write(my_register, register_idx, meta.register_tmp);
register_read(meta.register_tmp, my_register, register_idx);
// TODO
}

table m_table {
reads {
ethernet.srcAddr : exact;
}
actions {
m_action; _nop;
}
size : 16384;
}

control ingress {
apply(m_table);
}

control egress {
}
87 changes: 87 additions & 0 deletions testdata/p4_14_samples_outputs/register_signed-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <core.p4>
#define V1MODEL_VERSION 20200408
#include <v1model.p4>

struct intrinsic_metadata_t {
bit<4> mcast_grp;
bit<4> egress_rid;
}

struct meta_t {
int<32> register_tmp;
}

header ethernet_t {
bit<48> dstAddr;
bit<48> srcAddr;
bit<16> etherType;
}

struct metadata {
@name(".meta")
meta_t meta;
}

struct headers {
@name(".ethernet")
ethernet_t ethernet;
}

parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name(".parse_ethernet") state parse_ethernet {
packet.extract<ethernet_t>(hdr.ethernet);
transition accept;
}
@name(".start") state start {
transition parse_ethernet;
}
}

control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
apply {
}
}

@name(".my_register") register<int<32>, bit<14>>(32w16384) my_register;

control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name(".m_action") action m_action(bit<14> register_idx) {
my_register.read(meta.meta.register_tmp, register_idx);
}
@name("._nop") action _nop() {
}
@name(".m_table") table m_table {
actions = {
m_action();
_nop();
@defaultonly NoAction();
}
key = {
hdr.ethernet.srcAddr: exact @name("ethernet.srcAddr") ;
}
size = 16384;
default_action = NoAction();
}
apply {
m_table.apply();
}
}

control DeparserImpl(packet_out packet, in headers hdr) {
apply {
packet.emit<ethernet_t>(hdr.ethernet);
}
}

control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

control computeChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

V1Switch<headers, metadata>(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;

89 changes: 89 additions & 0 deletions testdata/p4_14_samples_outputs/register_signed-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include <core.p4>
#define V1MODEL_VERSION 20200408
#include <v1model.p4>

struct intrinsic_metadata_t {
bit<4> mcast_grp;
bit<4> egress_rid;
}

struct meta_t {
int<32> register_tmp;
}

header ethernet_t {
bit<48> dstAddr;
bit<48> srcAddr;
bit<16> etherType;
}

struct metadata {
@name(".meta")
meta_t meta;
}

struct headers {
@name(".ethernet")
ethernet_t ethernet;
}

parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name(".parse_ethernet") state parse_ethernet {
packet.extract<ethernet_t>(hdr.ethernet);
transition accept;
}
@name(".start") state start {
transition parse_ethernet;
}
}

control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
apply {
}
}

@name(".my_register") register<int<32>, bit<14>>(32w16384) my_register;

control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name(".m_action") action m_action(@name("register_idx") bit<14> register_idx) {
my_register.read(meta.meta.register_tmp, register_idx);
}
@name("._nop") action _nop() {
}
@name(".m_table") table m_table_0 {
actions = {
m_action();
_nop();
@defaultonly NoAction_1();
}
key = {
hdr.ethernet.srcAddr: exact @name("ethernet.srcAddr") ;
}
size = 16384;
default_action = NoAction_1();
}
apply {
m_table_0.apply();
}
}

control DeparserImpl(packet_out packet, in headers hdr) {
apply {
packet.emit<ethernet_t>(hdr.ethernet);
}
}

control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

control computeChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

V1Switch<headers, metadata>(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;

88 changes: 88 additions & 0 deletions testdata/p4_14_samples_outputs/register_signed-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <core.p4>
#define V1MODEL_VERSION 20200408
#include <v1model.p4>

struct intrinsic_metadata_t {
bit<4> mcast_grp;
bit<4> egress_rid;
}

struct meta_t {
int<32> register_tmp;
}

header ethernet_t {
bit<48> dstAddr;
bit<48> srcAddr;
bit<16> etherType;
}

struct metadata {
int<32> _meta_register_tmp0;
}

struct headers {
@name(".ethernet")
ethernet_t ethernet;
}

parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name(".parse_ethernet") state parse_ethernet {
packet.extract<ethernet_t>(hdr.ethernet);
transition accept;
}
@name(".start") state start {
transition parse_ethernet;
}
}

control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
apply {
}
}

@name(".my_register") register<int<32>, bit<14>>(32w16384) my_register;

control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name(".m_action") action m_action(@name("register_idx") bit<14> register_idx) {
my_register.read(meta._meta_register_tmp0, register_idx);
}
@name("._nop") action _nop() {
}
@name(".m_table") table m_table_0 {
actions = {
m_action();
_nop();
@defaultonly NoAction_1();
}
key = {
hdr.ethernet.srcAddr: exact @name("ethernet.srcAddr") ;
}
size = 16384;
default_action = NoAction_1();
}
apply {
m_table_0.apply();
}
}

control DeparserImpl(packet_out packet, in headers hdr) {
apply {
packet.emit<ethernet_t>(hdr.ethernet);
}
}

control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

control computeChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

V1Switch<headers, metadata>(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;

Loading