++code move for function

This commit is contained in:
Nico Schottelius 2019-07-17 15:48:16 +02:00
parent 512fca1349
commit ed6c4daec9
2 changed files with 15 additions and 10 deletions

View file

@ -1,17 +1,9 @@
#ifndef NICO_DELTA_CHECKSUM #ifndef NICO_DELTA_CHECKSUM
#define NICO_DELTA_CHECKSUM #define NICO_DELTA_CHECKSUM
/* copied from
https://p4.org/p4-spec/docs/PSA-v1.1.0.html#appendix-internetchecksum-implementation
*/
bit<16> ones_complement_sum(in bit<16> x, in bit<16> y) {
bit<17> ret = (bit<17>) x + (bit<17>) y; #include "headers.p4"
if (ret[16:16] == 1) {
ret = ret + 1;
}
return ret[15:0];
}
action v4sum() { action v4sum() {
bit<16> tmp = 0; bit<16> tmp = 0;

View file

@ -239,4 +239,17 @@ struct metadata {
table_t table_id; table_t table_id;
} }
/* copied from
https://p4.org/p4-spec/docs/PSA-v1.1.0.html#appendix-internetchecksum-implementation
*/
bit<16> ones_complement_sum(in bit<16> x, in bit<16> y) {
bit<17> ret = (bit<17>) x + (bit<17>) y;
if (ret[16:16] == 1) {
ret = ret + 1;
}
return ret[15:0];
}
#endif #endif