From owner-freebsd-hackers@freebsd.org Sun Jan 6 17:49:27 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 8F3B014957C3 for ; Sun, 6 Jan 2019 17:49:27 +0000 (UTC) (envelope-from mozolevsky@gmail.com) Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 A768687843; Sun, 6 Jan 2019 17:49:26 +0000 (UTC) (envelope-from mozolevsky@gmail.com) Received: by mail-ot1-f53.google.com with SMTP id f18so35980751otl.11; Sun, 06 Jan 2019 09:49:26 -0800 (PST) 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; bh=uB72MC15MbzUfv5XXxWq20KkL1DYgTVgn8wVg/4fQS8=; b=eBLzHaG1425NJNz4fQixoOuKfY8MpJc1V1YnlISV07RU3SbR5cb9c9Tq9DphiS526q SJRNxfW0tJAeqbKrXswr22np0nVQvwKw8nTbvzHcTlyH9Hz6+MxlDohl411hTIZLlLAI zPfA/Zb67TXIhSQO4YvOqsd2gE+9BsXyHJMyW3xabVIrpWtVIF5qir2c8LoACo0oouAD Xtj+EotANaRyIVSlx7chvka38bHcwBaclnPdQEihqZZXV43/R7/ePLR017NjXl1+0ZQs DIitSjggVQLm20BbsQiN0guUUbpEnXUaIWTPBg8YFt1CalGuTSVcF18mz5NvWmotJ+7T fF1Q== X-Gm-Message-State: AJcUukfJD2EKBkmIrACGHbf070bglE3WMai0+oGA43yXYhWKhsPupqaR A621KR5m38SGfezY2JtOnpSOJpibmHv4IpGgaAfDS95a X-Google-Smtp-Source: ALg8bN6k0le4yrJHPdrAQzuiij5oqtLBjl+l7GGyK0CIfYiqwlq0nd9zWwVeN0jUzdbpt6Nmxa594VGCiFKlD06dXYk= X-Received: by 2002:a9d:620f:: with SMTP id g15mr38307923otj.296.1546796959956; Sun, 06 Jan 2019 09:49: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> <26325c0b-4960-7739-72aa-c31c4e0638d3@aceshardware.com> In-Reply-To: <26325c0b-4960-7739-72aa-c31c4e0638d3@aceshardware.com> From: Igor Mozolevsky Date: Sun, 6 Jan 2019 17:48:44 +0000 Message-ID: Subject: Re: Speculative: Rust for base system components To: Brian Neal Cc: Alan Somers , "freebsd-hackers@freebsd.org" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: A768687843 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of mozolevsky@gmail.com designates 209.85.210.53 as permitted sender) smtp.mailfrom=mozolevsky@gmail.com X-Spamd-Result: default: False [-4.12 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; NEURAL_HAM_LONG(-1.00)[-0.996,0]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[hybrid-lab.co.uk]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.91)[-0.907,0]; RCVD_IN_DNSWL_NONE(0.00)[53.210.85.209.list.dnswl.org : 127.0.5.0]; IP_SCORE(-1.21)[ip: (-0.52), ipnet: 209.85.128.0/17(-3.78), asn: 15169(-1.67), country: US(-0.08)]; FORGED_SENDER(0.30)[igor@hybrid-lab.co.uk,mozolevsky@gmail.com]; MIME_TRACE(0.00)[0:+]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[igor@hybrid-lab.co.uk,mozolevsky@gmail.com]; RCVD_COUNT_TWO(0.00)[2] 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: Sun, 06 Jan 2019 17:49:27 -0000 On Sun, 6 Jan 2019 at 16:58, Brian Neal wrote: > I don't have it anymore, but yours is close enough. When compiling your > first example, I get 156 instructions, including map iterators and rust > result assert/unwrap logic. Your second example produces 21 lines, > including a loop iterator: All of *nine* instructions in C including (a) constant running time, i. e. O(1) cf. O(c), and (b) integer wrapping check-signal:- #include int32_t oddcount(int32_t c) { const int32_t max_c = 92679; /* sqrt(INT32_MAX)*2-1 */ return((c > max_c) ? 0: ((c + 1) / 2) * ((c + 1) / 2)); } oddcount: xor eax, eax cmp edi, 92679 jg .L1 lea eax, [rdi+1] mov ecx, 2 cdq idiv ecx imul eax, eax .L1: ret Like I said, no matter what tool one uses, bugs are easy to introduce (yes, even in Rust!), wrapping ints in the instant case... -- Igor M.