Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp599540pxj; Tue, 18 May 2021 10:00:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiZXY0fYysxwRpaWYqegLoh4kweVpszqCVp+tfPdxXPghJmMnEgwpaQt5hiQzZl4Os36Vc X-Received: by 2002:a05:6402:2298:: with SMTP id cw24mr8239221edb.156.1621357218920; Tue, 18 May 2021 10:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621357218; cv=none; d=google.com; s=arc-20160816; b=p59/DYaOIeBXJ0GZQhezTtWPkUCtDscT4vS86+37O4J4LHI6YYlUbAU9Z6PVWC3090 GD9bJ6U6L8heJAiMlhsX2lvJniir7ks3JeauB3d8QtLoYHBsyaHlGjdNYCdSVG9tDRxK +ZJQORvHo1oVABFB07Rz0CW25Ezl+Cp0nAo+xW7/HwSn1bZV2A4D5qvectrkoG4v2+Sk d2MdgrtF0rCQ4qKoTIcaQylUEGgYBTfzV0qOfWfABVBEbZ8C00jxXgKeX/Xmjp3eJJeO GjOylfdl+2qlt05wRDnH1rNEZbDqXMPU6isRl6k07qhrKW2Ny139/XRKGuISnwSAvQs7 LVoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uKcor1HCDdeUCw0baaRpSDKBQ1CY4jsw+phh5tbR0sU=; b=PY4YnZCprF85PP0KfwLWbC63SaJsv8IP9AbkT974p0PHqDhIxo0bhTdJ7mhK+ivZhh r7y0cu6ApPEUydP9Bt5Ek1JPDaIyKYhWFBlr6oOZUO1rlawv9QAm5G1+u8QSl9acwKZo 2MbnlBpt38qbgjGqHRmwZ5EbLnaq4mAdIDD8XLNvbEhzitePWyVnNR+rQ9lHS+LKH90h KLJ7pXlQ2DVIwrE/YXqtUoU0vFrwQspLPxgAYN0QQfxBo4oyOwt9X0dCy6St9Lc94ADK fwSIC2Xld1h+eeb/uVNT71F8vgLk/VOiX2LNsQPQRM/0XzeLuTzGo7SoFTtV0LMuXZ1C pbnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WGXf8RH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a29si17514737edb.492.2021.05.18.09.59.55; Tue, 18 May 2021 10:00:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WGXf8RH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346556AbhEQQGJ (ORCPT + 99 others); Mon, 17 May 2021 12:06:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:35612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344614AbhEQPpF (ORCPT ); Mon, 17 May 2021 11:45:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A1EF461D2B; Mon, 17 May 2021 14:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262614; bh=MW3yIXAfcBoXXRXxaYwi0JgwfVDxofXfnrb2vjB8MxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGXf8RH73uOlCCyruZBy/H4Vxy8usrUgx5WJdhe2jptaQnfzGx19b4c/J3CGuA945 1fPH4nSOmCN3JqpC1xYjOKtbTa9uh4hbZwoOuXWKW/HxsjMSIyIbHt5Nvw7iNhv5Nj QHKcELSrgQAvxRdg/xD9wHRfimJOoglcGM2Ke9VE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Maciej W. Rozycki" , Thomas Bogendoerfer Subject: [PATCH 5.11 306/329] MIPS: Avoid handcoded DIVU in `__div64_32 altogether Date: Mon, 17 May 2021 16:03:37 +0200 Message-Id: <20210517140312.436493109@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maciej W. Rozycki commit 25ab14cbe9d1b66fda44c71a2db7582a31b6f5cd upstream. Remove the inline asm with a DIVU instruction from `__div64_32' and use plain C code for the intended DIVMOD calculation instead. GCC is smart enough to know that both the quotient and the remainder are calculated with single DIVU, so with ISAs up to R5 the same instruction is actually produced with overall similar code. For R6 compiled code will work, but separate DIVU and MODU instructions will be produced, which are also interlocked, so scalar implementations will likely not perform as well as older ISAs with their asynchronous MD unit. Likely still faster then the generic algorithm though. This removes a compilation error for R6 however where the original DIVU instruction is not supported anymore and the MDU accumulator registers have been removed and consequently GCC complains as to a constraint it cannot find a register for: In file included from ./include/linux/math.h:5, from ./include/linux/kernel.h:13, from mm/page-writeback.c:15: ./include/linux/math64.h: In function 'div_u64_rem': ./arch/mips/include/asm/div64.h:76:17: error: inconsistent operand constraints in an 'asm' 76 | __asm__("divu $0, %z1, %z2" \ | ^~~~~~~ ./include/asm-generic/div64.h:245:25: note: in expansion of macro '__div64_32' 245 | __rem = __div64_32(&(n), __base); \ | ^~~~~~~~~~ ./include/linux/math64.h:91:22: note: in expansion of macro 'do_div' 91 | *remainder = do_div(dividend, divisor); | ^~~~~~ This has passed correctness verification with test_div64 and reduced the module's average execution time down to 1.0404s from 1.0445s with R3400 @40MHz. The module's MIPS I machine code has also shrunk by 12 bytes or 3 instructions. Signed-off-by: Maciej W. Rozycki Signed-off-by: Thomas Bogendoerfer Signed-off-by: Greg Kroah-Hartman --- arch/mips/include/asm/div64.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) --- a/arch/mips/include/asm/div64.h +++ b/arch/mips/include/asm/div64.h @@ -58,7 +58,6 @@ #define __div64_32(n, base) ({ \ unsigned long __upper, __low, __high, __radix; \ - unsigned long long __modquot; \ unsigned long long __quot; \ unsigned long long __div; \ unsigned long __mod; \ @@ -73,11 +72,8 @@ __upper = __high; \ __high = 0; \ } else { \ - __asm__("divu $0, %z1, %z2" \ - : "=x" (__modquot) \ - : "Jr" (__high), "Jr" (__radix)); \ - __upper = __modquot >> 32; \ - __high = __modquot; \ + __upper = __high % __radix; \ + __high /= __radix; \ } \ \ __mod = do_div64_32(__low, __upper, __low, __radix); \