From: Mathieu Desnoyers Date: Tue, 5 Oct 2010 15:32:15 +0000 (-0400) Subject: bitfield header macros cleanup (style) X-Git-Tag: v0.1~220 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=6a7b33456f65d964463e4bab4eff318da7f0a4c1 bitfield header macros cleanup (style) Signed-off-by: Mathieu Desnoyers --- diff --git a/include/babeltrace/bitfield.h b/include/babeltrace/bitfield.h index 74d8228c..449923c2 100644 --- a/include/babeltrace/bitfield.h +++ b/include/babeltrace/bitfield.h @@ -241,52 +241,52 @@ do { \ end = start + length; \ start_unit = start / ts; \ end_unit = (end + (ts - 1)) / ts; \ - \ - this_unit = end_unit - 1; \ - if (_bt_is_signed_type(typeof(v)) \ + \ + this_unit = end_unit - 1; \ + if (_bt_is_signed_type(typeof(v)) \ && ((ptr)[this_unit] & ((typeof(*(ptr))) 1 << ((end % ts ? : ts) - 1)))) \ - v = ~(typeof(v)) 0; \ - else \ - v = 0; \ - if (start_unit == end_unit - 1) { \ - cmask = (ptr)[this_unit]; \ - cmask >>= (start % ts); \ - if ((end - start) % ts) { \ + v = ~(typeof(v)) 0; \ + else \ + v = 0; \ + if (start_unit == end_unit - 1) { \ + cmask = (ptr)[this_unit]; \ + cmask >>= (start % ts); \ + if ((end - start) % ts) { \ mask = ~((~(typeof(*(ptr))) 0) << (end - start)); \ - cmask &= mask; \ - } \ - v = _bt_piecewise_lshift(v, end - start); \ - v |= _bt_unsigned_cast(typeof(v), cmask); \ - *(vptr) = v; \ - break; \ - } \ - if (end % ts) { \ - cshift = end % ts; \ - mask = ~((~(typeof(*(ptr))) 0) << cshift); \ - cmask = (ptr)[this_unit]; \ - cmask &= mask; \ - v = _bt_piecewise_lshift(v, cshift); \ - v |= _bt_unsigned_cast(typeof(v), cmask); \ - end -= cshift; \ - this_unit--; \ - } \ + cmask &= mask; \ + } \ + v = _bt_piecewise_lshift(v, end - start); \ + v |= _bt_unsigned_cast(typeof(v), cmask); \ + *(vptr) = v; \ + break; \ + } \ + if (end % ts) { \ + cshift = end % ts; \ + mask = ~((~(typeof(*(ptr))) 0) << cshift); \ + cmask = (ptr)[this_unit]; \ + cmask &= mask; \ + v = _bt_piecewise_lshift(v, cshift); \ + v |= _bt_unsigned_cast(typeof(v), cmask); \ + end -= cshift; \ + this_unit--; \ + } \ for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \ - v = _bt_piecewise_lshift(v, ts); \ - v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ - end -= ts; \ - } \ - if (start % ts) { \ - mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \ - cmask = (ptr)[this_unit]; \ - cmask >>= (start % ts); \ - cmask &= mask; \ - v = _bt_piecewise_lshift(v, ts - (start % ts)); \ - v |= _bt_unsigned_cast(typeof(v), cmask); \ - } else { \ - v = _bt_piecewise_lshift(v, ts); \ - v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ - } \ - *(vptr) = v; \ + v = _bt_piecewise_lshift(v, ts); \ + v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ + end -= ts; \ + } \ + if (start % ts) { \ + mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \ + cmask = (ptr)[this_unit]; \ + cmask >>= (start % ts); \ + cmask &= mask; \ + v = _bt_piecewise_lshift(v, ts - (start % ts)); \ + v |= _bt_unsigned_cast(typeof(v), cmask); \ + } else { \ + v = _bt_piecewise_lshift(v, ts); \ + v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ + } \ + *(vptr) = v; \ } while (0) #define _bt_bitfield_read_be(ptr, _start, _length, vptr) \ @@ -306,51 +306,51 @@ do { \ end = start + length; \ start_unit = start / ts; \ end_unit = (end + (ts - 1)) / ts; \ - \ + \ this_unit = start_unit; \ if (_bt_is_signed_type(typeof(v)) \ && ((ptr)[this_unit] & ((typeof(*(ptr))) 1 << (ts - (start % ts) - 1)))) \ - v = ~(typeof(v)) 0; \ - else \ - v = 0; \ - if (start_unit == end_unit - 1) { \ - cmask = (ptr)[this_unit]; \ - cmask >>= (ts - (end % ts)) % ts; \ - if ((end - start) % ts) {\ + v = ~(typeof(v)) 0; \ + else \ + v = 0; \ + if (start_unit == end_unit - 1) { \ + cmask = (ptr)[this_unit]; \ + cmask >>= (ts - (end % ts)) % ts; \ + if ((end - start) % ts) { \ mask = ~((~(typeof(*(ptr))) 0) << (end - start)); \ - cmask &= mask; \ - } \ - v = _bt_piecewise_lshift(v, end - start); \ - v |= _bt_unsigned_cast(typeof(v), cmask); \ - *(vptr) = v; \ - break; \ - } \ - if (start % ts) { \ - mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \ - cmask = (ptr)[this_unit]; \ - cmask &= mask; \ - v = _bt_piecewise_lshift(v, ts - (start % ts)); \ - v |= _bt_unsigned_cast(typeof(v), cmask); \ - start += ts - (start % ts); \ - this_unit++; \ - } \ - for (; this_unit < end_unit - 1; this_unit++) { \ - v = _bt_piecewise_lshift(v, ts); \ - v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ - start += ts; \ - } \ - if (end % ts) { \ - mask = ~((~(typeof(*(ptr))) 0) << (end % ts)); \ - cmask = (ptr)[this_unit]; \ - cmask >>= ts - (end % ts); \ - cmask &= mask; \ - v = _bt_piecewise_lshift(v, end % ts); \ - v |= _bt_unsigned_cast(typeof(v), cmask); \ - } else { \ - v = _bt_piecewise_lshift(v, ts); \ - v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ - } \ - *(vptr) = v; \ + cmask &= mask; \ + } \ + v = _bt_piecewise_lshift(v, end - start); \ + v |= _bt_unsigned_cast(typeof(v), cmask); \ + *(vptr) = v; \ + break; \ + } \ + if (start % ts) { \ + mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \ + cmask = (ptr)[this_unit]; \ + cmask &= mask; \ + v = _bt_piecewise_lshift(v, ts - (start % ts)); \ + v |= _bt_unsigned_cast(typeof(v), cmask); \ + start += ts - (start % ts); \ + this_unit++; \ + } \ + for (; this_unit < end_unit - 1; this_unit++) { \ + v = _bt_piecewise_lshift(v, ts); \ + v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ + start += ts; \ + } \ + if (end % ts) { \ + mask = ~((~(typeof(*(ptr))) 0) << (end % ts)); \ + cmask = (ptr)[this_unit]; \ + cmask >>= ts - (end % ts); \ + cmask &= mask; \ + v = _bt_piecewise_lshift(v, end % ts); \ + v |= _bt_unsigned_cast(typeof(v), cmask); \ + } else { \ + v = _bt_piecewise_lshift(v, ts); \ + v |= _bt_unsigned_cast(typeof(v), (ptr)[this_unit]); \ + } \ + *(vptr) = v; \ } while (0) /*