From owner-freebsd-hackers@freebsd.org Tue Jan 8 00:11:21 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EC8741481D09 for ; Tue, 8 Jan 2019 00:11:20 +0000 (UTC) (envelope-from unledev@gmail.com) Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 24D64880F8 for ; Tue, 8 Jan 2019 00:11:20 +0000 (UTC) (envelope-from unledev@gmail.com) Received: by mail-qk1-x730.google.com with SMTP id g125so1386996qke.4 for ; Mon, 07 Jan 2019 16:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CNMQFgANWzootms52hFEam07Yclc8r/NokdvPdWjEGk=; b=GNwxJwtYUg8Ni9tmyIr7eYTCcOxSDMxqZy7GILOCD/L0L9poCPodIjluCVhBFdjjyQ HsCcIEZGulPjGGvTBmwQztfqdXAIMPiHaODfCTeAsC9HZC4i2Y8JnO/nS1SspuwOl6eW vVyzwtQYuIj8URwGZ+VRFdBQ7SkRpbRkNfV7hKv8utNj5S9Yu09AEd1Oopj0wSy1fR7/ YLk0Cwrl03JtU09RQ9O62r/Ndsa3dfEqSs3HxUOph4YTfSHHe6gtz8XzOfnpST4x61DH LIDYcPNMrQwuvui8oD82GaIXKXRpLt/odlT9q3y3EkArvQa3eaVYHw2hJt7em4VnGO50 /eqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CNMQFgANWzootms52hFEam07Yclc8r/NokdvPdWjEGk=; b=CCNrX/qcAQuj70uc5IHrB807r5dkQA+dpB/D0huuHvss8j5Fnfe1xk/YReOAMroe6s I+31K44kMSKvPkeTeJ4l3kuRkMWELGXIW8ezrqZPL0+CDJlauvhviib8vFpzWK06h00b btqgXHLQiUNLmSFIlfPZG3mf/77PKf9GVIMx297ub4ZXM62+exNBP0tWJsY+t1id/Vkr 5jGQ718MkYnlHdYZ9lwTibuknZHTxFvxUAGmtDzWrgweRxKTsxWVwFr7LC8devqPp/ak gE0dAV1MDuvewAnpt9tQH9kH1SD0XJlb8YVRKJqQV2/nLwpwvEIrbikKDiNleVoG5iND CWGw== X-Gm-Message-State: AJcUukd0OrIDPGn5vWD3ih4GdB+Ke6RmWucEP2xhEBWh32tWHbgvhuRi ZCd3aSqeNuXT+Qs6t+wsywHWDbhUdufL7X7VhOv3CnMFQOezrg== X-Google-Smtp-Source: ALg8bN6od3NU7XcUDQxj0IVvtIakXx2dVNzphZBJCi9RtxMa5ybkiG8ZFSlnUQ+LGxYcUXE4wcbTD2DTGBCUsAwFpVE= X-Received: by 2002:a37:97c1:: with SMTP id z184mr58700248qkd.39.1546906279355; Mon, 07 Jan 2019 16:11:19 -0800 (PST) MIME-Version: 1.0 References: <7d7bc47d-04cf-2f9b-00a3-e3d9d92b3623@aceshardware.com> <72922F2C-9D27-47AA-BB1C-2DA8589CF008@rpi.edu> <92bd5362-d898-aa12-8f3d-9fbe23f38e0c@aceshardware.com> In-Reply-To: From: Alejandro Martinez Date: Tue, 8 Jan 2019 00:11:03 +0000 Message-ID: Subject: Re: Speculative: Rust for base system components To: Brian Neal Cc: freebsd-hackers@freebsd.org, Garance A Drosehn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 24D64880F8 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=GNwxJwtY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of unledev@gmail.com designates 2607:f8b0:4864:20::730 as permitted sender) smtp.mailfrom=unledev@gmail.com X-Spamd-Result: default: False [-6.53 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_IN_DNSWL_NONE(0.00)[0.3.7.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_TLS_LAST(0.00)[]; NEURAL_HAM_SHORT(-0.97)[-0.967,0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; IP_SCORE(-2.55)[ip: (-8.80), ipnet: 2607:f8b0::/32(-2.21), asn: 15169(-1.68), country: US(-0.08)]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jan 2019 00:11:21 -0000 Hi Brian, On Fri, Jan 4, 2019 at 4:50 PM Brian Neal wrote: > > Sure! > > Just go to http://godbolt.org/ and type a small program in each language,= enter the appropriate compilation flags and compare the output. The functi= on I used took a count as a parameter, iterated through the count, summed u= p odd numbers and returned the sum. I did the test with what I understood must had been the code you used, but my results are different. See [1]. > >> It was a debug build with no optimization for either compiler. But we > >> can easily run a variety of settings for comparison: Debug builds show also panic and overflow checks for Rust sources, which explains the difference in instruction count. > >> > >> Compiler Flags Inst. Count Build Time > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >> clang 7.0.0 none 33 296ms > >> -O3 23 341ms > >> rustc 1.31.0 none 110 606ms > >> -C opt-level=3D3 67 643ms > >> gcc 8.2 none 37 211ms > >> -O2 24 249ms > >> -O3 119* 206ms > >> > >> * With -O3, gcc unrolled and vectorized the loop. The other compilers > >> did not emit vectorized code at any of the standard optimization level= s. I did not see this. Actually I had to force Rust with extra flags to stop it from emitting such code. In fact, both Rust and clang generate the exact same code for the equivalent function. > >> So, essentially, double the build time and ~3 times the code for the > >> same logic. This is not true in the tests I did wrt instruction count. The compiler is certainly slower, although not sure it is 2x slower than clang. In fact, as you can see, there's one implementation in Rust that beats the C code in inst count for both gcc and clang. That said, instruction count is hardly a good metric, especially with relatively recent CPUs. My 2c: these tests focus on a very narrow set of properties and cases that IMO should not be the basis for considering a language. [1] https://godbolt.org/z/hqi_VX. Cheers, Alex