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

[bmv2] Incorrect behavior when assigning to bitvector slice #148

Closed
vikramnathan opened this issue Nov 14, 2016 · 2 comments
Closed

[bmv2] Incorrect behavior when assigning to bitvector slice #148

vikramnathan opened this issue Nov 14, 2016 · 2 comments
Assignees
Labels
fixed This topic is considered to be fixed.

Comments

@vikramnathan
Copy link

vikramnathan commented Nov 14, 2016

[Using P4-16] Assigning to a bitvector slice produces an incorrect result when run on bmv2.

To reproduce:

register<bit<8>>(1) debug;
apply {
    bit<8> n = 8w0b11111111;
    n[7:4] = 4w0;
    debug.write(0, n);
}

Send a single packet through the switch. From the thrift CLI, run

>> register_read debug 0
debug[0] = 0

Expected: 15 ( = 0b00001111).

I'm attaching the source file for reference, which is a barebones switch containing the above snippet.
basic.p4.txt

Other comments:

  • If n = 8w0 and is rewritten with n[7:4] = ~4w0, the above problem doesn't occur. debug[1] is as expected in both cases. Seems to only be a problem if the original bits are non-zero and the replaced bits are 0.
  • This bug also occurs if the LSBs are reset.
  • This works for other bit widths (I also tried 32 and 64 with the same result).
  • Strangely, I observe the correct behavior if I write n to a register before resetting its MSBs:
register<bit<8>>(32w2) debug;
apply {
    bit<8> n = ~8w0;  // All 1s
    debug.write(0, n);
    n[7:4] = 4w0;
    debug.write(1, n);
}
>> register_read debug 0
debug[0] = 255
>> register_read debug 1
debug[1] = 15

which is expected.

@ChrisDodd ChrisDodd added the fixed This topic is considered to be fixed. label Dec 13, 2016
@ChrisDodd
Copy link
Contributor

Please close if you agree it is fixed

@vikramnathan
Copy link
Author

Verified as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed This topic is considered to be fixed.
Projects
None yet
Development

No branches or pull requests

2 participants