I was looking through the bhyve code and noticed an obvious
easy (if trivial) code improvement.
Tested "standalone" rather than inside bhyve (with both gcc and
clang, on FreeBSD 9.0).
Not sure where/how diffs should go, so I figured I would send this
here as a test. :-)
--- pci_virtio_block.c (revision 247510)
+++ pci_virtio_block.c (working copy)
@@ -164,14 +164,19 @@
hq_num_avail(struct vring_hqueue *hq)
- int ndesc;
+ uint16_t ndesc;
- if (*hq->hq_avail_idx >= hq->hq_cur_aidx)
- ndesc = *hq->hq_avail_idx - hq->hq_cur_aidx;
- ndesc = UINT16_MAX - hq->hq_cur_aidx + *hq->hq_avail_idx + 1;
+ * We're just computing (a-b) in GF(2^16).
+ * The only glitch here is that in standard C,
+ * uint16_t promotes to (signed) int when int has
+ * more than 16 bits (pretty much always now), so
+ * we have to force it back to unsigned.
+ ndesc = (unsigned)*hq->hq_avail_idx - (unsigned)hq->hq_cur_aidx;
- assert(ndesc >= 0 && ndesc <= hq->hq_size);
+ assert(ndesc <= hq->hq_size);
email@example.com mailing list
To unsubscribe, send any mail to