Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1231452

Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Alexey Dobriyan <adobriyan@gmail.com>
Newsgroups linux.kernel
Subject Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree
Date Wed, 23 Sep 2015 15:50:03 +0200
Message-ID <qbSAP-5Me-29@gated-at.bofh.it> (permalink)
References <qbSAP-5Me-31@gated-at.bofh.it>
X-Original-To Linux Kernel <linux-kernel@vger.kernel.org>, Andrew Morton <akpm@linux-foundation.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Ie4rqy8w1lfNhQYMP+WRAukKFqqTI0QMuNh0Dlti9UU=; b=skLdpD/9ZMG0E7IlkaiUw80JLvUO1dLbITsC0CGqS5uBpzVmyVM868rs0Hqq4DZKMA yEmotrxABpM0MuR2+SioJ+HAGvGu28HvpD2PePA/l2W915rGSm9TN/OHkpwjjYIBBSvS 4nO0rrr3UTLtP3VQ9CT61jbHpTXnNvRxRxCwQerzB78a7RcovLGkd6kTiNKTPThv8FJv uUF20OMvjaGIjeJnJmgHLzGOB0zr4antFlqfmTUxQDCL8vXc+P9TlEqq3DVtO2IE/ElN v6G4vx7d3meNxxJhhDcV2gcUOOdxldY8UAQjW34yuD6Aq9iRwS4UfHrkYGqHqkl85HLH mD6w==
MIME-Version 1.0
X-Received by 10.194.223.68 with SMTP id qs4mr8075099wjc.38.1443015869477; Wed, 23 Sep 2015 06:44:29 -0700 (PDT)
Content-Type text/plain; charset=UTF-8
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 48
Organization linux.* mail to news gateway
X-Original-Cc Michal Nazarewicz <mina86@mina86.com>, Peter Zijlstra <a.p.zijlstra@chello.nl>, john.stultz@linaro.org, Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>, Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Steven Rostedt <rostedt@goodmis.org>, Linus Torvalds <torvalds@linux-foundation.org>
X-Original-Date Wed, 23 Sep 2015 16:44:29 +0300
X-Original-Message-ID <CACVxJT_0KRtZyhsUh9P6SisQ2qwDtWki0xQW-RsGzHnobq0R4Q@mail.gmail.com>
X-Original-References <55fb3266.yHuY6+DaYTJdIL75%akpm@linux-foundation.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1231452

Show key headers only | View raw


On Fri, Sep 18, 2015 at 12:36 AM,  <akpm@linux-foundation.org> wrote:


> -#define abs(x) ({                                              \
> -               long ret;                                       \
> -               if (sizeof(x) == sizeof(long)) {                \
> -                       long __x = (x);                         \
> -                       ret = (__x < 0) ? -__x : __x;           \
> -               } else {                                        \
> -                       int __x = (x);                          \
> -                       ret = (__x < 0) ? -__x : __x;           \
> -               }                                               \
> -               ret;                                            \
> -       })
> +#define abs(x) __builtin_choose_expr(sizeof(x) == sizeof(s64), ({      \
> +               s64 __x = (x);                                          \
> +               (__x < 0) ? -__x : __x;                                 \
> +       }), ({                                                          \
> +               long ret;                                               \
> +               if (sizeof(x) == sizeof(long)) {                        \
> +                       long __x = (x);                                 \
> +                       ret = (__x < 0) ? -__x : __x;                   \
> +               } else {                                                \
> +                       int __x = (x);                                  \
> +                       ret = (__x < 0) ? -__x : __x;                   \
> +               }                                                       \
> +               ret;                                                    \
> +       }))

1. "char" should be banned, because it's signedness is not well defined.
2. there is unnecessary expansion to long.

I've sent kabs() before which didn't go in because it didn't work for
INT_MAX et al
(don't worry, this abs() doens't as well) but it is nicer that this
version in other aspects
(hopefully).

[PATCH v2] Add kabs()
http://marc.info/?l=linux-kernel&m=133518745522740&w=4

As for INT_MIN, it pretty impossible to make compiler to not generate a branch
despite generating correct result without a branch.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree Alexey Dobriyan <adobriyan@gmail.com> - 2015-09-23 15:50 +0200
  Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm  tree Andrew Morton <akpm@linux-foundation.org> - 2015-09-23 22:10 +0200
  Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree Michal Nazarewicz <mina86@mina86.com> - 2015-09-24 15:40 +0200
    Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree Alexey Dobriyan <adobriyan@gmail.com> - 2015-09-24 16:30 +0200
  Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-24 20:10 +0200
    Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree Michal Nazarewicz <mina86@mina86.com> - 2015-09-25 18:40 +0200

csiph-web