On Wed, Apr 25, 2018 at 11:04:26AM +0200, Olaf Hering wrote: > Am Wed, 25 Apr 2018 09:59:23 +0100 > schrieb Wei Liu <wei.l...@citrix.com>: > > > Do you have the full diff of your changes? > > Not right now. But without 'val', or val being uint, the same error happens > in f(): > > #include <stdio.h> > void f(void) > { > unsigned short req_prod = 0, req_cons = 65400; > unsigned short val; > val = req_prod - req_cons; > printf("req_prod - req_cons %u\n", val); > printf("req_prod - req_cons %x\n", val); > }
What Jan said. Integer promotion makes unsigned short into unsigned int first then do the calculation. Assigning the result to val truncates it back to unsigned short. For the original code, idx is of type unsigned int. No promotion or truncation is needed so the end result is correct. Wei. > > int main(void) > { > #if 1 > unsigned nr_ents = 0x100U, req_prod_pvt = 0x14U, rsp_cons = > 0xffffffeeU, req_prod = 0xfffffffeU; > unsigned rx_target = 0x40U, qlen = 0x1aU; > #else > unsigned nr_ents = 0x100U, req_prod_pvt = 0x00U, rsp_cons = > 0xffffffeeU, req_prod = 0xfffffffeU; > unsigned rx_target = 0x40U, qlen = 0x1aU; > #endif > printf("batch_target %u, skb_queue_len %u, rx_target %u\n", rx_target > - (req_prod_pvt - rsp_cons), qlen, rx_target); > printf("nr_ents %u\n", nr_ents); > printf("req_prod_pvt - rsp_cons %u\n", req_prod_pvt - rsp_cons); > printf("req_prod_pvt - req_prod %u\n", req_prod_pvt - req_prod); > printf("%u\n", nr_ents - (req_prod_pvt - rsp_cons)); > printf("%u\n", nr_ents - (req_prod_pvt - rsp_cons)); > f(); > return 0; > } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel