Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp863090pxu; Sun, 25 Oct 2020 20:03:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHpBcvFs9wzf2BKugVwwjgLOdtflx3uWjs/bMgV0sMviMquUERkWkD10FXuVWpaMryqQnS X-Received: by 2002:a17:906:3bd7:: with SMTP id v23mr14224251ejf.100.1603681420145; Sun, 25 Oct 2020 20:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603681420; cv=none; d=google.com; s=arc-20160816; b=RSiAb6wgV8Lnt++dGGwbeCeH+N6hQZmvRrgPYMQ7sxMzoqA1D6R8c+UI57mcYVVkoS JSBnG6DKHssWvWC/5h6oTkH8xHieY86CFXEVloMAp4XtrC53flfimTJRGTzT1sgfvr7z iaQ2bmNK7UhOQRIVXaJkTybRxiWEHtvU4SoAY/sQoAX+0n2lgwCSs69FssLfBWaegy5L 6LNCKuIQcm1+dLafDEuDDv8ulEgrGkqlqiSiFo+zgH6bM6jQ5362kGTniu1TjwNrH02X beToPxPSWU2sOXnVaqodLUDqLs9xq6ag30y69F11s5EaL0Wfih3XBAfu+trBhdE2REcF gSOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:sender:dkim-signature; bh=LBtOv6ii27P7UDwcOYJQCSjkPKpG8hoxT55RTEp71C0=; b=z9ABffAxw+N1PUx8LHn65v8kP5P4TPN+LDYYprBbm0omKU08hPlPcrX6E3kOZJFlWy XeZm5gIpSwCMU7J2iCy2V05uiF8vcQES1C7pag35Y8jxJCBVzn1c1DZl1h69qOBVtIGH Dbubv/UKh7EQ/VM909CXXxLbfS+BcKCLzushVeL4kftNiW2aLUFYQlU1J3aMI7oBhe6l l5rCW1YeIFkqBPWdVgSfk7mDpCHOvn2YNPmYcwgqB5nsMeCPsTi+/lAH568bqXEEa8lK wVWm6OP2N6K4wgA+QZ3h+fAELratdF+it7FZDHVwVTzUusGWEFe9fgHWn11JT1pRd3y9 XJiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pcAX1d+T; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 h22si5873968edq.32.2020.10.25.20.03.15; Sun, 25 Oct 2020 20:03:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@gmail.com header.s=20161025 header.b=pcAX1d+T; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420714AbgJYXxy (ORCPT + 99 others); Sun, 25 Oct 2020 19:53:54 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:46138 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1418308AbgJYXxx (ORCPT ); Sun, 25 Oct 2020 19:53:53 -0400 Received: by mail-qk1-f193.google.com with SMTP id a23so6895959qkg.13; Sun, 25 Oct 2020 16:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LBtOv6ii27P7UDwcOYJQCSjkPKpG8hoxT55RTEp71C0=; b=pcAX1d+Tz+7IByaAVNQmiVtKSSi9GAqWCZmJuTz1wHVZPnBR6VUgRJWn9MuIOc7n1c ma0276pXIw6OsFn/9Ozy2JcWfH9StjzEOUwX3wUqCD0O/rXbHHGkVntSNTJtQ4CrliZp 9f9oUCatsGSGuMWnjBsFfA8M+CyZfZfUn5dB2NOTDuVssWhhpkbJb0cffixg03lMH8jp 9Jehzx+RzzrkcQ6j1gC88ZRPQNXyD73KKY4f1RNEen7QEBIjWyyDNH5aapW/fxPRAPWB VFI467yMSCdsCSx0ARQhZ8T9FoZdQ2FKUa+n5R/kSKvAGX4EoC5YBUR2otLse55FaIWt ImWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=LBtOv6ii27P7UDwcOYJQCSjkPKpG8hoxT55RTEp71C0=; b=cocOKW8YO+61OTltyTKq2RgGYJYRWMyZ6xtA1U81POWYmcbc0UHV4nhIAu4CwuQZyr IPNzgCxoJrbfxi2aDTnqdBfM0yxW8spSE4k9eR3YeDyT38qUYbZ8+Bjdge6Qr/WDMJpm jWm6+cNVdap5bKe42lns5T+l+2BdbWw+76MlTmQa+e4yKV8TkIZv0E6C4Nvh4EFlHS3R 8wIdCSjTKYRkzFGqVlLr0INRdygX2yPvah7fnw9IJZDMMA6QY7gVic8ANEBWUdVgXJZz +XSLEzfxReOplEidBX/C7ePsGLrPzgHwL+ueQmo9jSxMPkykNUpDUbWBYSHoYdH5Drjd F6HQ== X-Gm-Message-State: AOAM532iib7Doc76OXth3apOXcvvhw/vvuD02Oo2wgXroofYzkz4iUnO B3UtsVXdCsK/rc9abUI2polGQuUEAcX9aw== X-Received: by 2002:a37:ad1a:: with SMTP id f26mr13396854qkm.1.1603670032187; Sun, 25 Oct 2020 16:53:52 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id m38sm1454693qta.8.2020.10.25.16.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 16:53:51 -0700 (PDT) Sender: Arvind Sankar From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Sun, 25 Oct 2020 19:53:49 -0400 To: David Laight Cc: 'Arvind Sankar' , Herbert Xu , "David S. Miller" , "linux-crypto@vger.kernel.org" , Eric Biggers , "linux-kernel@vger.kernel.org" , Eric Biggers Subject: Re: [PATCH v4 6/6] crypto: lib/sha256 - Unroll LOAD and BLEND loops Message-ID: <20201025235349.GA1281192@rani.riverdale.lan> References: <20201025143119.1054168-1-nivedita@alum.mit.edu> <20201025143119.1054168-7-nivedita@alum.mit.edu> <05150bdb3a4c4b2682ab9cb8fb2ed411@AcuMS.aculab.com> <20201025201820.GA1237388@rani.riverdale.lan> <5d8f86fcfe84441fa5c9877959069ff1@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5d8f86fcfe84441fa5c9877959069ff1@AcuMS.aculab.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Sun, Oct 25, 2020 at 11:23:52PM +0000, David Laight wrote: > From: Arvind Sankar > > Sent: 25 October 2020 20:18 > > > > On Sun, Oct 25, 2020 at 06:51:18PM +0000, David Laight wrote: > > > From: Arvind Sankar > > > > Sent: 25 October 2020 14:31 > > > > > > > > Unrolling the LOAD and BLEND loops improves performance by ~8% on x86_64 > > > > (tested on Broadwell Xeon) while not increasing code size too much. > > > > > > I can't believe unrolling the BLEND loop makes any difference. > > > > It's actually the BLEND loop that accounts for almost all of the > > difference. The LOAD loop doesn't matter much in general: even replacing > > it with a plain memcpy() only increases performance by 3-4%. But > > unrolling it is low cost in code size terms, and clang actually does it > > without being asked. > > (memcpy is wrong - misses the byte swaps). I know it's wrong, the point is that it's impossible to gain very much from optimizing the LOAD loop because it doesn't account for much of the total time. > > That's odd, the BLEND loop is about 20 instructions. > I wouldn't expect unrolling to help - unless you manage > to use 16 registers for the active W[] values. > I am not sure about what's going on inside the hardware, but even with a straightforward assembly version that just reads out of memory the way the calculation is specified, unrolling the BLEND loop 8x speeds up the performance by 7-8%. The compiler is actually pretty bad here, just translating everything into assembler with no attempt to optimize anything gets a 10-12% speedup over the C version.