Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp652860pxb; Fri, 16 Apr 2021 14:55:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOSN7e1LH+LKwIjx1CMjYviB6PEo657bKRJiKtGJ/jhUi6toppX1e0w3nIVAF75ScEWXFx X-Received: by 2002:a17:90a:990a:: with SMTP id b10mr11760248pjp.178.1618610142454; Fri, 16 Apr 2021 14:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618610142; cv=none; d=google.com; s=arc-20160816; b=NEKBgv3b/5wfqZcdtX1EgGXCzccWmpCirQyk9DlA37e1Ojq5wXI2eqrmeVcYP6GiBK QX4H4h0gbPT51UESMTu5fmNo5okt/m9P/xL7VqapRC1WlzRqo4NGgo9APsp1L7IqZnnW 9CzQVP7Yz5HjEBVih6z89Qy4OPkYD9LEvsXQ0+uJ7Ky+sNzyzrYw91G9piUDgkMl3KR/ wjS3ztbwSkPCXFdKdFm7s/2nCpppIO4KBRvRa0KHjXozxRii9lqlbn6acdd66WI+ATzo 82+lhFG0o2QjAesUmyBNKiWSgIwmwDBUF2Kt+TnoeHuQQCEEu5M9HgUypgwqCkbrKGJe MS2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=RvcM3BbpAqS4vnb4mmq+WfuNLSB+ko17fq4aiOwMoEk=; b=DpIZ8CHTKceQ1yAv/ZpLGE8DswBoZgrx0Pr0nux883g0fl/idPiteAydTPTlUEXaaA EOHJu/M4bToLOUJHG91pYFpEW6wkVYgk4yF56rxvKsVFZAwNEqmTeUP+ejTmuzia2t6n 5LkA5lz21QbZ8Cyt6E6K77FsDPvXkIyV6VCyzVku9p3Cb2rfwSdFhGFl1NP9GPcuz7Km UkLDivkBE8mGCtBsSRtQ/xfI76MrH0QV/AWxRp1UW4j75JZLN2ovyG1JM/JFidJ68l6D 3jsjGIvlIEWQBnxaB4JUQFDFfBMUIS/Ulh9G3GcT+fzDDmVrKA1/wn+I30u+AIc8Jx2a +PvA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p3si8227958plo.211.2021.04.16.14.55.30; Fri, 16 Apr 2021 14:55:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236112AbhDPTok (ORCPT + 99 others); Fri, 16 Apr 2021 15:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235258AbhDPToh (ORCPT ); Fri, 16 Apr 2021 15:44:37 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A36E7C061574 for ; Fri, 16 Apr 2021 12:44:12 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lXUNq-005q1X-4h; Fri, 16 Apr 2021 19:44:06 +0000 Date: Fri, 16 Apr 2021 19:44:06 +0000 From: Al Viro To: Eric Dumazet Cc: Thomas Gleixner , Linus Torvalds , linux-kernel , Eric Dumazet Subject: Re: [PATCH] x86/uaccess: small optimization in unsafe_copy_to_user() Message-ID: References: <20210416192413.1514419-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210416192413.1514419-1-eric.dumazet@gmail.com> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 16, 2021 at 12:24:13PM -0700, Eric Dumazet wrote: > From: Eric Dumazet > > We have to loop only to copy u64 values. > After this first loop, we copy at most one u32, one u16 and one byte. Does it actually yield a better code? FWIW, this void bar(unsigned); void foo(unsigned n) { while (n >= 8) { bar(n); n -= 8; } while (n >= 4) { bar(n); n -= 4; } while (n >= 2) { bar(n); n -= 2; } while (n >= 1) { bar(n); n -= 1; } } will compile (with -O2) to pushq %rbp pushq %rbx movl %edi, %ebx subq $8, %rsp cmpl $7, %edi jbe .L2 movl %edi, %ebp .L3: movl %ebp, %edi subl $8, %ebp call bar@PLT cmpl $7, %ebp ja .L3 andl $7, %ebx .L2: cmpl $3, %ebx jbe .L4 movl %ebx, %edi andl $3, %ebx call bar@PLT .L4: cmpl $1, %ebx jbe .L5 movl %ebx, %edi andl $1, %ebx call bar@PLT .L5: testl %ebx, %ebx je .L1 addq $8, %rsp movl $1, %edi popq %rbx popq %rbp jmp bar@PLT .L1: addq $8, %rsp popq %rbx popq %rbp ret i.e. loop + if + if + if...