Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [lttng-dev] [PATCH barectf 1/1] Fix: bitfield: shift undefined/implementation defined behaviors
Date: Wed, 15 May 2019 17:53:19 -0400 (EDT)	[thread overview]
Message-ID: <1142915113.1625.1557957199369.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20190514204215.27528-1-mathieu.desnoyers@efficios.com>

----- On May 14, 2019, at 4:42 PM, Mathieu Desnoyers mathieu.desnoyers at efficios.com wrote:

[...]
> 
> #define _$prefix$bt_bitfield_write_be(_ptr, type, _start, _length, _vtype, _v)
> \\
> do {									\\
> -	_vtype __v = (_v);					\\
> +	_vtype __v = (_v);						\\
> 	type *__ptr = CAST_PTR(type *, _ptr);				\\
> 	unsigned long __start = (_start), __length = (_length);		\\
> 	type mask, cmask;						\\
> @@ -740,15 +859,15 @@ do {									\\
> 									\\
> 	/* Trim v high bits */						\\
> 	if (__length < sizeof(__v) * CHAR_BIT)				\\
> -		__v &= ~((~(_vtype) 0) << __length);			\\
> +		__v &= _$prefix$bt_make_mask(_vtype, __length);		\\
> 									\\
> 	/* We can now append v with a simple "or", shift it piece-wise */ \\
> 	this_unit = end_unit - 1;					\\
> 	if (start_unit == end_unit - 1) {				\\
> -		mask = ~((~(type) 0) << ((ts - (end % ts)) % ts));	\\
> +		mask = _$prefix$bt_make_mask(type, (ts - (end % ts)) % ts); \\
> 		if (__start % ts)					\\
> -			mask |= (~((type) 0)) << (ts - (__start % ts));	\\
> -		cmask = (type) __v << ((ts - (end % ts)) % ts);		\\
> +			mask |= _$prefix$bt_make_mask_complement(type, ts - (__start % ts)); \\
> +		cmask = _$prefix$bt_lshift(type, (type) (__v), (ts - (end % ts)) % ts); \\
> 		cmask &= ~mask;						\\
> 		__ptr[this_unit] &= mask;				\\
> 		__ptr[this_unit] |= cmask;				\\
> @@ -756,8 +875,8 @@ do {									\\
> 	}								\\
> 	if (end % ts) {							\\
> 		cshift = end % ts;					\\
> -		mask = ~((~(type) 0) << (ts - cshift));			\\
> -		cmask = (type) __v << (ts - cshift);			\\
> +		mask = _$prefix$bt_make_mask(type, ts - cshift);	\\
> +		cmask = _$prefix$bt_lshift(type, (type) (__v), ts - cshift); \\
> 		cmask &= ~mask;						\\
> 		__ptr[this_unit] &= mask;				\\
> 		__ptr[this_unit] |= cmask;				\\
> @@ -771,7 +890,7 @@ do {									\\
> 		end -= ts;						\\
> 	}								\\
> 	if (__start % ts) {						\\
> -		mask = (~(type) 0) << (ts - (__start % ts));		\\
> +		mask = _$prefix$bt_make_mask(type, ts - (__start % ts)); \\

Should be:

+               mask = _$prefix$bt_make_mask_complement(type, ts - (__start % ts)); \\

Will send an updated patch.

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


      reply	other threads:[~2019-05-15 21:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-14 20:42 Mathieu Desnoyers
2019-05-15 21:53 ` Mathieu Desnoyers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1142915113.1625.1557957199369.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox