Re: [Cfrg] Benchmarks: 384 vs 389 vs Goldilocks vs ... on Haswell

Michael Hamburg <mike@shiftleft.org> Wed, 31 December 2014 22:18 UTC

Return-Path: <mike@shiftleft.org>
X-Original-To: cfrg@ietfa.amsl.com
Delivered-To: cfrg@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 47AE81A1A83 for <cfrg@ietfa.amsl.com>; Wed, 31 Dec 2014 14:18:29 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: 1.555
X-Spam-Level: *
X-Spam-Status: No, score=1.555 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FH_HOST_EQ_D_D_D_D=0.765, FH_HOST_EQ_D_D_D_DB=0.888, HELO_MISMATCH_ORG=0.611, HOST_MISMATCH_NET=0.311, RDNS_DYNAMIC=0.982, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Qi2BXYpliSme for <cfrg@ietfa.amsl.com>; Wed, 31 Dec 2014 14:18:27 -0800 (PST)
Received: from aspartame.shiftleft.org (199-116-74-168-v301.PUBLIC.monkeybrains.net [199.116.74.168]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 9FC9C1A1A4E for <cfrg@irtf.org>; Wed, 31 Dec 2014 14:18:27 -0800 (PST)
Received: from [192.168.1.117] (unknown [192.168.1.1]) by aspartame.shiftleft.org (Postfix) with ESMTPSA id 89A283AA12; Wed, 31 Dec 2014 14:16:15 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shiftleft.org; s=sldo; t=1420064175; bh=ixb4j4EW8nxiGvlT/IQBZ43K4XvaN0x8nmHuSEv/y1I=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=KVF3SDWtUJOJtRwEHN3PxnSFGVHUIpuNF4otG1TQd5dZmfrlrbZi2VazAQGlNY8wY RDv8hQaUaMAYUe/y3KuwfMbe4SOTGEZOE18ii90dIREsV/pb3QAooa/tDq8zrvPVNz Qv5Ev3S4A9lFM7WliHUtjvGhDoxxEx7YWgTIPL4Q=
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2064\))
From: Michael Hamburg <mike@shiftleft.org>
In-Reply-To: <D0CA0568.3B27A%kenny.paterson@rhul.ac.uk>
Date: Wed, 31 Dec 2014 14:18:25 -0800
Content-Transfer-Encoding: quoted-printable
Message-Id: <8B06C2AB-A4D3-4ADD-898A-135C06497458@shiftleft.org>
References: <54A1E049.9000404@shiftleft.org> <D0CA0568.3B27A%kenny.paterson@rhul.ac.uk>
To: "Paterson, Kenny" <Kenny.Paterson@rhul.ac.uk>
X-Mailer: Apple Mail (2.2064)
Archived-At: http://mailarchive.ietf.org/arch/msg/cfrg/sMjVWflOkTRkN6VJgIcy2H0wk4E
Cc: "cfrg@irtf.org" <cfrg@irtf.org>
Subject: Re: [Cfrg] Benchmarks: 384 vs 389 vs Goldilocks vs ... on Haswell
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Crypto Forum Research Group <cfrg.irtf.org>
List-Unsubscribe: <http://www.irtf.org/mailman/options/cfrg>, <mailto:cfrg-request@irtf.org?subject=unsubscribe>
List-Archive: <http://www.irtf.org/mail-archive/web/cfrg/>
List-Post: <mailto:cfrg@irtf.org>
List-Help: <mailto:cfrg-request@irtf.org?subject=help>
List-Subscribe: <http://www.irtf.org/mailman/listinfo/cfrg>, <mailto:cfrg-request@irtf.org?subject=subscribe>
X-List-Received-Date: Wed, 31 Dec 2014 22:18:29 -0000

Hi Kenny,

I think that the differences on Haswell are probably real, but I suspect that most people on this list won’t be convinced by a <10% performance difference.  On other architectures, it may depend on how unfavorable packed arithmetic is.  So on ARM scalar, the 384-bit prime is probably OK, but on ARM NEON the 389-bit one will probably be better.  It’d be kind of nice to get actual numbers on the subject, though, instead of wishy-washy speculation.

I’m still a little bit perplexed about why you asked me to do this exercise.  The argument at the WF128 level seems to be about the existing trust and deployment of Curve25519 compared to a “rigidly-generated” ed-256-mers.  At the WF192 and WF256 levels, there are no widely deployed “safe" curves, and it is between this same notion of “rigidity” vs more “efficient” curves such as Curve41417, Ed448-Goldilocks and E-521.  [Scarequoted because it’s MSR's definition of rigidity, DJB and Tanja’s safety criteria, and Trevor’s and my efficiency metric.]

Is the introduction of another efficient curve near WF192 suggested to sway the rigidity camp’s opinion about any of these proposals?  Especially with people so sick of the endless arguments that they’re cutting backroom deals?

If you think data has a chance of moving things forward, I suggest that benchmarks of the Microsoft curves’ (or at least primes’) performance on ARM scalar/NEON would be more informative, because they’d help determine whether the efficiency camp’s curves are broadly more efficient and by how much.

Cheers,
— Mike

> On Dec 31, 2014, at 12:01 PM, Paterson, Kenny <Kenny.Paterson@rhul.ac.uk> wrote:
> 
> Hi Mike,
> 
> Thanks a lot for doing this work, especially over the holiday season -
> it's much appreciated.
> 
> My take-away from your work is that there's no strong reason (in
> performance terms) to prefer P389 over P384-mers or vice-versa - the 8-9%
> difference is there, yes, but could easily disappear or increase with
> further optimisations on either side.
> 
> Does that seem fair to you? Please feel free to give an alternative
> interpretation if you like.
> 
> Regards,
> 
> Kenny 
> 
> On 29/12/2014 23:14, "Mike Hamburg" <mike@shiftleft.org> wrote:
> 
>> 
>> 
>> 
>> Hi all, 
>> 
>> The chairs requested that I implement and benchmark 2^389 - 21, suggested
>> by Ilari.
>> 
>> I've benchmarked several primes that have been discussed on this list.  I
>> used a Haswell machine running Linux test everything, including MSR
>> ECCLib 1.1.  Cycle counts for mul/sqr:
>> 
>> MSR ECCLib (all asm, but no BMI2):
>> P256-mers: M = 59.2, S = 47.8.
>> P384-mers: M = 117.5, S = 89.8.
>> P512-mers: M = 199.9, S = 140.6.
>> 
>> My code (C with BMI2 mul+acc intrinsics):
>> P389: M = 112.5, S = 75.5.
>> Goldilocks P448: M = 118.0, S = 88.9.
>> Ridinghood P480: M = 118.2, S = 89.1.
>> NIST P521: M = 145.5, S = 110.7.
>> 
>> With this machine/compiler combination, 2^389 - 21 is showing at about
>> 8-9% faster than MSR 384-mers and Goldilocks, which are within 0.1% of
>> each other.
>> 
>> CPU:
>> Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz .
>> 
>> Compiler:
>> Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
>> Target: x86_64-pc-linux-gnu
>> Thread model: posix
>> 
>> Notes: 
>> 
>> * All benchmarks computed by timing and multiplying by 3.5932GHz, since
>> that's what calib() spat out.
>> 
>> 
>> * The P389 code is mul-after-add clean.  I did this by multiplying the
>> arguments to a multiply separately by 8 and 21.  The code without this
>> feature is marginally (<1%) faster.
>> 
>> * I haven't tested the correctness of the P389 code, nor have I built it
>> into a curve.  So sue me, I'm on vacation.
>> 
>> * ECCLib, P389*, P448: 10^8 trials, noinline'd functions, 32-byte-aligned
>> stack buffers, no dependencies in the multiplications.  TurboBoost and
>> HyperThreading disabled.  Benchmarks are stable to about 3 significant
>> figures.
>> 
>> 
>> * P480, P521, because I'm lazy: Goldilocks `make bench`, 10^8/2 trials,
>> noinlined functions, 32-byte-aligned stack buffers, no dependencies.
>> Almost exactly
>> consistent when benchmarking P448.
>> 
>> * For MSR ECCLib I called directly into ecc384.o's functions, using the
>> same benchmarking framework code as for P389.
>> 
>> * Earlier, offlist testing on a Haswell MacBook Air showed about a 2%
>> advantage to 2^389 - 21 instead of 8%.  The code improvements to P389
>> since then are not sufficient to explain the better results: they are
>> apparently machine/compiler dependent.  I thought
>> that Clang 3.5 might be responsible, since I've seen performance
>> differences in arithmetic code with it.  But clang-3.3, 3.4 and 3.5 all
>> give similar results for those primes.  GCC 4.9 gives slightly worse
>> results for everything but the MSR asm code.
>> 
>> * The P389 code is probably less tuned than its competitors. The MS code
>> is written in pure asm, but it doesn't take advantage of BMI2.  The
>> Goldilocks and P389 code are C with an asm multiply/accumulate intrinsic,
>> but I spent more time tuning the Goldilocks
>> code. 
>> 
>> * The Ridinghood code is the same as the Goldilocks code with different
>> shift constants.  The P-521 code is the arch_x86_64_r12 version, using 9
>> limbs vector-aligned to a 12-word structure.
>> 
>> * I have no data about 2^389 - 21 on other platforms, but offlist
>> discussions suggest that it will be OK, if perhaps annoying to implement,
>> on 32-bit platforms.
>> 
>> Cheers, 
>> -- Mike
>> 
>>