Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034033AbbKGAtl (ORCPT ); Fri, 6 Nov 2015 19:49:41 -0500 Received: from mail-ob0-f181.google.com ([209.85.214.181]:35721 "EHLO mail-ob0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033997AbbKGAtj (ORCPT ); Fri, 6 Nov 2015 19:49:39 -0500 MIME-Version: 1.0 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1CBCD4A0@AcuExch.aculab.com> References: <20151027.233235.1641084823622810663.davem@davemloft.net> <5637C8DF.800@kernel.org> <1446512176.17404.30.camel@kernel.crashing.org> <1446555200.1870849.427743457.63139285@webmail.messagingengine.com> <063D6719AE5E284EB5DD2968C1650D6D1CBCD4A0@AcuExch.aculab.com> From: Andy Lutomirski Date: Fri, 6 Nov 2015 16:49:19 -0800 Message-ID: Subject: Re: [GIT] Networking To: David Laight Cc: Linus Torvalds , Hannes Frederic Sowa , Benjamin Herrenschmidt , Andy Lutomirski , David Miller , Andrew Morton , Network Development , Linux Kernel Mailing List , Sasha Levin Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1680 Lines: 44 On Fri, Nov 6, 2015 at 7:27 AM, David Laight wrote: >> From: Linus Torvalds >> Sent: 03 November 2015 20:45 >> On Tue, Nov 3, 2015 at 12:05 PM, Linus Torvalds >> wrote: >> > result = add_overflow( >> > mul_overflow(sec, SEC_CONVERSION, &overflow), >> > mul_overflow(nsec, NSEC_CONVERSION, &overflow), >> > &overflow); >> > >> > return overflow ? MAX_JIFFIES : result; >> >> Thinking more about this example, I think the gcc interface for >> multiplication overflow is fine. >> >> It would end up something like >> >> if (mul_overflow(sec, SEC_CONVERSION, &sec)) >> return MAX_JIFFY_OFFSET; >> if (mul_overflow(nsec, NSEC_CONVERSION, &nsec)) >> return MAX_JIFFY_OFFSET; >> sum = sec + nsec; >> if (sum < sec || sum > MAX_JIFFY_OFFSET) >> return MAX_JIFFY_OFFSET; >> return sum; >> >> and that doesn't look horribly ugly to me. > > If mul_overflow() is a real function you've just forced some of the > values out to memory, generating a 'clobber' for all memory > (unless 'strict-aliasing' is enabled) and making a mess of other > optimisations. > (If it is a static inline that might not happen.) I doubt anyone would ever make it a real function. On new gcc, it would be an inline backed by an intrinsic. On old gcc it would be a normal inline or perhaps an inline with inline asm in it. --Andy -- 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/