public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: Re: [B.A.T.M.A.N.] [PATCH] batman-adv: move smallest_signed_int(), seq_before() and  seq_after() into main.h
Date: Thu, 19 May 2011 21:41:11 +0200	[thread overview]
Message-ID: <201105192141.18647.sven@narfation.org> (raw)
In-Reply-To: <1305703250-23111-1-git-send-email-ordex@autistici.org>

[-- Attachment #1: Type: Text/Plain, Size: 3234 bytes --]

Antonio Quartulli wrote:
> smallest_signed_int(), seq_before() and seq_after() are very useful
> functions that help to handle comparisons between sequence numbers.
> However they were only defined in vis.c. With this patch every
> batman-adv function will be able to use them.
> 
> Signed-off-by: Antonio Quartulli <ordex@autistici.org>


Acked-by: Sven Eckelmann <sven@narfation.org>

David S. Miller doesn't want to have the seq_before/seq_after in a global 
header: http://lkml.org/lkml/2011/5/19/88

I would still like to propose the type check on top of that patch

Kind regards,
	Sven

> ---
>  main.h |   16 ++++++++++++++++
>  vis.c  |   16 ----------------
>  2 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/main.h b/main.h
> index 3ca3941..90db244 100644
> --- a/main.h
> +++ b/main.h
> @@ -181,4 +181,20 @@ static inline int compare_eth(void *data1, void
> *data2)
> 
>  #define atomic_dec_not_zero(v)	atomic_add_unless((v), -1, 0)
> 
> +/* Returns the smallest signed integer in two's complement with the sizeof
> x */ +#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
> +
> +/* Checks if a sequence number x is a predecessor/successor of y.
> + * they handle overflows/underflows and can correctly check for a
> + * predecessor/successor unless the variable sequence number has grown by
> + * more then 2**(bitwidth(x)-1)-1.
> + * This means that for a uint8_t with the maximum value 255, it would
> think: + *  - when adding nothing - it is neither a predecessor nor a
> successor + *  - before adding more than 127 to the starting value - it is
> a predecessor, + *  - when adding 128 - it is neither a predecessor nor a
> successor, + *  - after adding more than 127 to the starting value - it is
> a successor */ +#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
> +			_dummy > smallest_signed_int(_dummy); })
> +#define seq_after(x, y) seq_before(y, x)
> +
>  #endif /* _NET_BATMAN_ADV_MAIN_H_ */
> diff --git a/vis.c b/vis.c
> index c39f20c..e1ed552 100644
> --- a/vis.c
> +++ b/vis.c
> @@ -30,22 +30,6 @@
> 
>  #define MAX_VIS_PACKET_SIZE 1000
> 
> -/* Returns the smallest signed integer in two's complement with the sizeof
> x */ -#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
> -
> -/* Checks if a sequence number x is a predecessor/successor of y.
> - * they handle overflows/underflows and can correctly check for a
> - * predecessor/successor unless the variable sequence number has grown by
> - * more then 2**(bitwidth(x)-1)-1.
> - * This means that for a uint8_t with the maximum value 255, it would
> think: - *  - when adding nothing - it is neither a predecessor nor a
> successor - *  - before adding more than 127 to the starting value - it is
> a predecessor, - *  - when adding 128 - it is neither a predecessor nor a
> successor, - *  - after adding more than 127 to the starting value - it is
> a successor */ -#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
> -			_dummy > smallest_signed_int(_dummy); })
> -#define seq_after(x, y) seq_before(y, x)
> -
>  static void start_vis_timer(struct bat_priv *bat_priv);
> 
>  /* free the info */

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  parent reply	other threads:[~2011-05-19 19:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-18  7:20 [B.A.T.M.A.N.] [PATCH] batman-adv: move smallest_signed_int(), seq_before() and seq_after() into main.h Antonio Quartulli
2011-05-18 12:22 ` [B.A.T.M.A.N.] [RFC/PATCH] net: add seq_before/seq_after functions Antonio Quartulli
2011-05-18 14:10   ` Sven Eckelmann
2011-05-19 19:41 ` Sven Eckelmann [this message]
2011-05-19 19:43   ` [B.A.T.M.A.N.] [PATCH] batman-adv: Check type of x and y in seq_(before|after) Sven Eckelmann
2011-05-22  9:14     ` Marek Lindner
2011-05-22  9:06 ` [B.A.T.M.A.N.] [PATCH] batman-adv: move smallest_signed_int(), seq_before() and seq_after() into main.h Marek Lindner

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=201105192141.18647.sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /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