From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932640AbbIYQgJ (ORCPT ); Fri, 25 Sep 2015 12:36:09 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:37014 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932609AbbIYQgF convert rfc822-to-8bit (ORCPT ); Fri, 25 Sep 2015 12:36:05 -0400 From: Michal Nazarewicz To: Linus Torvalds , Alexey Dobriyan Cc: Linux Kernel , Andrew Morton , Peter Zijlstra , John Stultz , Masami Hiramatsu , Ingo Molnar , Peter Zijlstra , Steven Rostedt Subject: Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree In-Reply-To: Organization: http://mina86.com/ References: <55fb3266.yHuY6+DaYTJdIL75%akpm@linux-foundation.org> 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:150925:masami.hiramatsu.pt@hitachi.com::J2R8R5UA633mCNPj:0000000000000000000000000000000P0A X-Hashcash: 1:20:150925:linux-kernel@vger.kernel.org::kBwTrVt2ad/MjX9U:0000000000000000000000000000000001o2y X-Hashcash: 1:20:150925:rostedt@goodmis.org::Qa5bvWliv2fBhsWB:0000000000000000000000000000000000000000001KtW X-Hashcash: 1:20:150925:akpm@linux-foundation.org::u+/ZhexbZSaqaiAD:0000000000000000000000000000000000002ad1 X-Hashcash: 1:20:150925:peterz@infradead.org::UBfxi0xrkeM5QrdE:000000000000000000000000000000000000000002yMw X-Hashcash: 1:20:150925:mingo@kernel.org::0W3QZVlZvBGXIMRD:06/SF X-Hashcash: 1:20:150925:john.stultz@linaro.org::BVhjnCAb95PKE4v+:0000000000000000000000000000000000000008E2E X-Hashcash: 1:20:150925:torvalds@linux-foundation.org::hvuOHmsg+lUEWvSe:000000000000000000000000000000006ODU X-Hashcash: 1:20:150925:adobriyan@gmail.com::ylQW5b6Lr9yOGlb9:0000000000000000000000000000000000000000009u+1 X-Hashcash: 1:20:150925:a.p.zijlstra@chello.nl::TOlWIN+PokPa/IwT:000000000000000000000000000000000000000DqMI Date: Fri, 25 Sep 2015 18:36:01 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 24 2015, Linus Torvalds wrote: > One thing that *is* interesting is "what if 'long' and 's64' are the > same size?" In particular, it means that right now Michal's patch > *always* returns "long" on a 64-bit architecture, but will return > "long" or "s64" on a 32-bit one. That’s not accurate. s64 is defined as long long so: - on 64-bit architectures, the macro will return s64 (i.e. long long) for long arguments (because sizeof(long) == 8 == sizeof(s64) and the first path is taken), but - on 32-bit architectures, it will return long for long arguments (since sizeof(long) == 4 != 8 == sizeof(long long) and the second path is taken). But yes, the point remains, depending on architecture, the macro returns different type for long arguments. > The reason that is somewhat interesting is that while the sizes and > values are the same, and the resulting C type expansions are > "equivalent" types, i people *print* things, you have to use different > modifiers for the two cases. So you might get warnings on 32-bit > architectures and not get them on 64-bit, or vice versa. > > However, I don't see a good solution for that. And assuming we don't > use "abs()" in an expression to printk(), I guess it doesn't much > matter either. This should do the trick: #define abs(x) __builtin_choose_expr( \ __builtin_types_compatible_p(typeof(x), s64) || \ __builtin_types_compatible_p(typeof(x), u64), \ ({ s64 __x = (x); __x < 0 ? -__x : __x; }), \ __builtin_choose_expr(sizeof(x) <= sizeof(long), ({ \ 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; \ }), (void)(x))) It’ll return s64 for s64 and u64 (i.e. long long and unsigned long long) types, long for anything whose sizeof <= sizeof(long) and will bail out with compile time error if used for any other type (if return value is used). I dunno whether added complexity is worth solving the problem though. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, ミハウ “mina86” ナザレヴイツ (o o) ooo +---------ooO--(_)--Ooo--