Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2393081rda; Wed, 25 Oct 2023 01:04:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCIA4u8pgeRCuAJYJwa9a6C1lH+lKX6BZj8ktYXAu3K+LLihFjlmvAR4coIsT/zS/4hCXh X-Received: by 2002:a0d:cc48:0:b0:5a7:fcaf:c1c0 with SMTP id o69-20020a0dcc48000000b005a7fcafc1c0mr16967663ywd.8.1698221049561; Wed, 25 Oct 2023 01:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698221049; cv=none; d=google.com; s=arc-20160816; b=u3MErhZY5eUQPi+6vRDjRY3u2MXhevgbddSjvyxU5uMncyPSvHqbEm7KhGdKU/uG7Q qaIfoMs/h/wXRkqRyk3m+LJv5Dl7+5iF4DdrK0A9yVWFmWvz3lqXu92godv3AvecrQMH dE6Oi6psYl5sTuDkHLLqFaXBZ8w6+XMwUbfgYOAA3OgHniJKi24AIA2CP+Jr8TzWgfeT rCIbxMeB+Ocu4HN0Y9WFQGVsn6dE5rG7p5NiJQRpQ2x9vIJRmfJfSfl5ljkM0mMMDP+h BSPVHaI/0FKf4y1scFtpC4gO3KBlXdSEQSqwi8NIGjExivBiestLcwcO34ZlabB+cYJS sdiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=gIO339/qu08wZ2r0nZAHdrWAaLG7qQMU/yUxr7tkE5M=; fh=mLK40AOx5M++k1POrI1vUOrR9L9JiKszrWRsLuBZd6Q=; b=cyH5PSEz58LwNDhGN3aXQ005rnH9jzSPlzhb1jtCfh/LQ+EMrqRolAQ88OrA7bHQmf e4A+fGSDoy2P1unyV3r1/i6pMoCidH9ygPR+//SGTVCgkHLQikYICEgc3ljnSr/7CAkv q9OXdfh9JYkDFoprz285vIcZlAKNMrKU1Jw9C1IlqX9iqVnC/NW4jNc7nuBPSIeIwOJW bx6jBUbK7aZdqfc2tDI0QZfxGeJtRu3NvZ+6honbFS5LmB3z9nJ0BPT+KUo6F49VYcMg vMuOtkivXtyhMYQXa/pCn2ARJEr8iL8sCWeZGYW6f/+B9QuvGR5iJgJ6HNgXAKuxkdRl YbbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=e0ZzUaMx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id a11-20020a0dd80b000000b005a80f09948asi10186942ywe.131.2023.10.25.01.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 01:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=e0ZzUaMx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id F20768030FB0; Wed, 25 Oct 2023 01:04:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbjJYIDs (ORCPT + 99 others); Wed, 25 Oct 2023 04:03:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231542AbjJYIDq (ORCPT ); Wed, 25 Oct 2023 04:03:46 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11B5E99 for ; Wed, 25 Oct 2023 01:03:44 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-53d9b94731aso8415056a12.1 for ; Wed, 25 Oct 2023 01:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1698221022; x=1698825822; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=gIO339/qu08wZ2r0nZAHdrWAaLG7qQMU/yUxr7tkE5M=; b=e0ZzUaMxxfxqOktqAu3669tUiw9sla/v26rSS+MpGDGOwQrjn0LZYFPBPKmDYK4oE/ bTxSy8koVi9lDuXFAOWfraVyMhZTk3mHuec/HchHBIr13Yj2n3TZTgrNqhtPSxvJb7tW YwylHsr5mC0pKyTRGPA82zGs1VdN8unpTLHPU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698221022; x=1698825822; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gIO339/qu08wZ2r0nZAHdrWAaLG7qQMU/yUxr7tkE5M=; b=ggyICGjP3qV7gOKy27xYX2bRYPHj64vhFRJMX7zGwg827Dbf0WtrDIe7fX1zXi3ZI5 1oN2TvnMbMHVxk1u9BN2IPQL1s5wVMTco/XJGIlsBsrGUVHigvhl4R+cHmybBbt3vPRZ ilwMpbM6Q9TZS42BQ8qCjbE0iGLf2ap30cpNU/r3dn2aB5yh9Kza77fni2nCY9FD+9Je 8pTk9I6qm3XGeVLEGSvE4zopMPIt5SIwDDrzCS8gO8KqJItXUOZqiPYyYjjU4iCuvG5k S7GzZRxgLqhsqOPMbnYThAj69oH3a+LKgY+Z6xlSSuggY0652OT9ygWjBYbj4KSS3JGo K87w== X-Gm-Message-State: AOJu0Yy76aq8TI2kR3xuECCb7Lf+yptcNhCt7U6OsUNt5LzD9SrDrAU+ xdapF1AW5vVdOoVvwmjcgYtueQ== X-Received: by 2002:a50:d098:0:b0:540:164c:2be1 with SMTP id v24-20020a50d098000000b00540164c2be1mr7734823edd.0.1698221022310; Wed, 25 Oct 2023 01:03:42 -0700 (PDT) Received: from [172.16.11.116] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id cw3-20020a056402228300b0053eb69ca1bcsm9021465edb.92.2023.10.25.01.03.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Oct 2023 01:03:42 -0700 (PDT) Message-ID: <7ba90240-33ba-4e08-af38-3ec2d40c3837@rasmusvillemoes.dk> Date: Wed, 25 Oct 2023 10:03:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/3] math.h: add DIV_ROUND_UP_NO_OVERFLOW Content-Language: en-US, da To: Linus Torvalds , Sebastian Reichel Cc: Andy Shevchenko , Michael Turquette , Stephen Boyd , David Laight , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Niklas Schnelle , kernel@collabora.com References: <20231024161931.78567-1-sebastian.reichel@collabora.com> <20231024161931.78567-2-sebastian.reichel@collabora.com> From: Rasmus Villemoes In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 01:04:07 -0700 (PDT) On 25/10/2023 00.53, Linus Torvalds wrote: > I'm hoping that somebody will go "Linus, you're just being > *completely* silly, it's much easier to do XYZ". I don't have better suggestions, but a few notes: Both the existing and new implementation are simply wrong for negative n, because / doesn't do floor(), it does round-towards-0 (I do believe that's a bug in the C standard, but not much one can do about that). So both the old and new say that dru(-5, 5) == 0, dru(-7, 5) == 0, dru(-10, 5) == -1. They are correct for dru(-9, 5) == -1 and other "1 mod d" cases. But the new implementation disagrees with the old for -d+1 < n < 0: The old implementation correctly says dru(-3, 5) == 0, but the new gives 1 (!). Preventing signed types from being used is probably too difficult. But it would be nice if we could at least catch a negative _value_ and do something sensible. Can we make the build fail for a negative, compile-time constant, n? I have no idea what to do for run-time negative values - we already don't do the math right, but starting to return a positive number for some negative n's really doesn't seem right. Aside: I don't think uapi/ stuff can include non-uapi/ stuff. Aside2: do_div(n-1, d); probably doesn't compile :) Rasmus