Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1225572
| Path | csiph.com!goblin1!goblin.stu.neva.ru!newsfeed.CARNet.hr!news.spin.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Michal Nazarewicz <mina86@mina86.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values |
| Date | Wed, 16 Sep 2015 01:00:02 +0200 |
| Message-ID | <q97mG-2Ru-1@gated-at.bofh.it> (permalink) |
| References | <q8MUV-6nq-5@gated-at.bofh.it> <q8NHj-7hi-3@gated-at.bofh.it> <q8P6q-136-7@gated-at.bofh.it> <q8PpM-1pA-11@gated-at.bofh.it> <q95XB-UJ-31@gated-at.bofh.it> |
| X-Original-To | Andrew Morton <akpm@linux-foundation.org>, Tejun Heo <tj@kernel.org> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:organization:references :user-agent:face:date:message-id:mime-version:content-type :content-transfer-encoding; bh=D1gL0UrVSardRVFXjMulnB6BZ6n0Oqc/mLXvybRSb/w=; b=l4nbtjWzoft3CV/gYH02sCfeI0s4/klMIUdFsTd5XSd6GK2jTnDn/rVlL9UD34nNqr sqDojud1GRLQJPZ4Wlgn8uPGam/UbiNJCV9e7SSTlpS8qjzknjroGRSb7+2vqkg5UnQn zQ87hNeNaHTzc0Qcnim4sxqWC0T1AZ5bvv7z2J0XeEAzI7BA4iDbGq+uUiURTRMMApnQ 1HJxA96R1ubpUJ2isijjIuE983NKrepxX6+3ajUc4jA3KjGDZ/+9m7Exf1YuLovfokGI Lv7X/0K8CDMjHUYdYhT/MqUmCUf1oy8UPl01CRDRBpIYr9nQIVo7L9d0PkNqFNZmFfQA ag6w== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to :organization:references:user-agent:face:date:message-id :mime-version:content-type:content-transfer-encoding; bh=D1gL0UrVSardRVFXjMulnB6BZ6n0Oqc/mLXvybRSb/w=; b=YiVBqHtViMh6b0JsKeJMiYYuQpO+B6LYqreBrIsnib4ibzCPa/PEmugc1Wr1I3T6Mz YUkItv8UCpB7an9fcKAquujuHSxlSuVxlNTpC7fr/Whv1m+hgU6xOnjXqMWDCnQt3k6Y h0PSwDe4LoWyM3ojnp8dhuTPuxyulAroKigFC3klGT6InTXPTXtcCigC+P0k90doN4FW ariwJX6n5TBkYKGmoQxh6CU1OA6+x47lys1VX/t/VzeRTe6/e4x3HX3smyDEzLnaWV+V 7m/USJI5QDakx7Y2LJSyWKUBlNWoFBi09TilUHpUkZljO3Jt+FwWzCpgrzDE7HAHg0XS cj5w== |
| X-Gm-Message-State | ALoCoQmtDkN5HfwhCiTxVvzP7+7UPVWmOoGi6toEz1Aailfuk7e3vWoYO/oczy7comjSuiq2n0e7 |
| X-Received | by 10.194.176.201 with SMTP id ck9mr14514180wjc.108.1442357652398; Tue, 15 Sep 2015 15:54:12 -0700 (PDT) |
| Organization | http://mina86.com/ |
| User-Agent | Notmuch/0.19+53~g2e63a09 (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) |
| X-Face | PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd;KFrfMCylc}gc??'U2j,!8%xdD |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC |
| X-PGP | 50751FF4 |
| X-PGP-Fp | AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 |
| X-Hashcash | 1:20:150915:tj@kernel.org::32EMH69OIJAVYGlz:00000Jn3 |
| X-Hashcash | 1:20:150915:joe@perches.com::kfHSJ34+gzidR6Ri:000bPL |
| X-Hashcash | 1:20:150915:mingo@kernel.org::K8zNycjFsc2ZH8U0:01i+u |
| X-Hashcash | 1:20:150915:prarit@redhat.com::Rtbh7c9ZPUeY314L:000000000000000000000000000000000000000000001hFx |
| X-Hashcash | 1:20:150915:tytso@mit.edu::op3vvex61jEgIF10:00001xd+ |
| X-Hashcash | 1:20:150915:richardcochran@gmail.com::oupJpni3ZmLtUJE7:000000000000000000000000000000000000026bl |
| X-Hashcash | 1:20:150915:linux-kernel@vger.kernel.org::WHFhxWpCNcmDgZku:00000000000000000000000000000000022LQ |
| X-Hashcash | 1:20:150915:john.stultz@linaro.org::R/EA2Mn3ri6duTFB:0000000000000000000000000000000000000003inZ |
| X-Hashcash | 1:20:150915:peterz@infradead.org::1ZY82TkLQMsRBojr:0000000000000000000000000000000000000000041Ga |
| X-Hashcash | 1:20:150915:adilger.kernel@dilger.ca::3PlUjrDy6/RWGt3U:00000000000000000000000000000000000005HSW |
| X-Hashcash | 1:20:150915:tglx@linutronix.de::+M/J9TfIdkXxnaUQ:00000000000000000000000000000000000000000005flT |
| X-Hashcash | 1:20:150915:torvalds@linux-foundation.org::yzCx/tUXY3mZlP02:000000000000000000000000000000005EGK |
| X-Hashcash | 1:20:150915:dchinner@redhat.com::M9ohl8ZKauzrJ+7h:0000000000000000000000000000000000000000006i4y |
| X-Hashcash | 1:20:150915:masami.hiramatsu.pt@hitachi.com::e/FELdc6sUI2EBaY:0000000000000000000000000000007hOn |
| X-Hashcash | 1:20:150915:akpm@linux-foundation.org::xnshSchYBJSY5rXM:000000000000000000000000000000000000AI5x |
| X-Hashcash | 1:20:150915:rostedt@goodmis.org::yaY9jUgWg07T6WM/:000000000000000000000000000000000000000000Ek2m |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8BIT |
| 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 | 113 |
| X-Original-Cc | John Stultz <john.stultz@linaro.org>, LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@kernel.org>, "Steven Rostedt \(Red Hat\)" <rostedt@goodmis.org>, Peter Zijlstra <peterz@infradead.org>, Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>, Prarit Bhargava <prarit@redhat.com>, Richard Cochran <richardcochran@gmail.com>, Thomas Gleixner <tglx@linutronix.de>, Theodore Ts'o <tytso@mit.edu>, Andreas Dilger <adilger.kernel@dilger.ca>, Dave Chinner <dchinner@redhat.com>, Joe Perches <joe@perches.com>, Linus Torvalds <torvalds@linux-foundation.org> |
| X-Original-Date | Wed, 16 Sep 2015 00:54:09 +0200 |
| X-Original-Message-ID | <xa1tmvwnfg4u.fsf@mina86.com> |
| X-Original-References | <1442279124-7309-1-git-send-email-john.stultz@linaro.org> <20150915014936.GA25658@htj.duckdns.org> <CALAqxLV2qfKdNyTtnGzsgj+mWUK-wYm3OGYj6xRN_-qbtaypMg@mail.gmail.com> <20150915034632.GB25658@htj.duckdns.org> <20150915142120.7a2f7ac90b2d69b4879b68d7@linux-foundation.org> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1225572 |
Show key headers only | View raw
On Tue, Sep 15 2015, Andrew Morton wrote:
> On Mon, 14 Sep 2015 23:46:32 -0400 Tejun Heo <tj@kernel.org> wrote:
>
>> Anyways, let's please get abs() working for all types, one way or the
>> other.
>
> That would be by far the best solution, of course.
>
> This seems to work OK:
>
> --- a/include/linux/kernel.h~a
> +++ a/include/linux/kernel.h
> @@ -207,8 +207,11 @@ extern int _cond_resched(void);
> * for those.
> */
> #define abs(x) ({ \
> - long ret; \
> - if (sizeof(x) == sizeof(long)) { \
> + s64 ret; \
> + if (sizeof(x) == sizeof(s64)) { \
> + s64 __x = (x); \
> + ret = (__x < 0) ? -__x : __x; \
> + } else if (sizeof(x) == sizeof(long)) { \
> long __x = (x); \
> ret = (__x < 0) ? -__x : __x; \
> } else { \
If the return type is an issue, we can use __builtin_choose_expr, no?
#define abs(x) __builtin_choose_expr(sizeof(x) == sizeof(s64), abs64(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; \
}))
This is awkward but will make even printk happy.
>
> Test case:
>
> --- /dev/null
> +++ a/lib/xx.c
> @@ -0,0 +1,33 @@
> +#include <linux/kernel.h>
> +
> +#define newabs(x) ({ \
> + s64 ret; \
> + if (sizeof(x) == sizeof(s64)) { \
> + s64 __x = (x); \
> + ret = (__x < 0) ? -__x : __x; \
> + } else if (sizeof(x) == sizeof(long)) { \
> + long __x = (x); \
> + ret = (__x < 0) ? -__x : __x; \
> + } else { \
> + int __x = (x); \
> + ret = (__x < 0) ? -__x : __x; \
> + } \
> + ret; \
> + })
> +
> +#define oldabs(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; \
> + })
> +
> +int foo(int x)
> +{
> + return oldabs(x);
> +}
> diff -puN lib/Makefile~b lib/Makefile
> --- a/lib/Makefile~b
> +++ a/lib/Makefile
> @@ -13,7 +13,7 @@ lib-y := ctype.o string.o vsprintf.o cmd
> sha1.o md5.o irq_regs.o argv_split.o \
> proportions.o flex_proportions.o ratelimit.o show_mem.o \
> is_single_threaded.o plist.o decompress.o kobject_uevent.o \
> - earlycpio.o seq_buf.o nmi_backtrace.o
> + earlycpio.o seq_buf.o nmi_backtrace.o xx.o
>
> obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
> lib-$(CONFIG_MMU) += ioremap.o
>
>
> on i386, xx.o's text is 68 bytes with either newabs() or oldabs().
>
>
> lib/percpu_counter.o's text does get larger with newabs(). That's
> because __percpu_counter_compare() is doing abs() on an s64, doh.
>
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, ミハウ “mina86” ナザレヴイツ (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>-----ooO--(_)--Ooo--
--
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 | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC][PATCH 0/5] Fixes for abs() usage on 64bit values John Stultz <john.stultz@linaro.org> - 2015-09-15 03:10 +0200
[RFC][PATCH 1/5] clocksource: Fix abs() usage w/ 64bit values John Stultz <john.stultz@linaro.org> - 2015-09-15 03:10 +0200
[RFC][PATCH 2/5] time: Fix abs() usage with 64-bit values. John Stultz <john.stultz@linaro.org> - 2015-09-15 03:10 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Tejun Heo <tj@kernel.org> - 2015-09-15 04:00 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values John Stultz <john.stultz@linaro.org> - 2015-09-15 05:30 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Tejun Heo <tj@kernel.org> - 2015-09-15 05:50 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Jeff Epler <jepler@unpythonic.net> - 2015-09-15 14:50 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Andrew Morton <akpm@linux-foundation.org> - 2015-09-15 23:30 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Michal Nazarewicz <mina86@mina86.com> - 2015-09-16 01:00 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Ingo Molnar <mingo@kernel.org> - 2015-09-15 07:30 +0200
Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-16 01:50 +0200
csiph-web