Date: Sun, 6 Jan 2019 17:48:44 +0000 From: Igor Mozolevsky <igor@hybrid-lab.co.uk> To: Brian Neal <brian@aceshardware.com> Cc: Alan Somers <asomers@freebsd.org>, "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: Re: Speculative: Rust for base system components Message-ID: <CADWvR2gYVAX15RFvQcO=HNpwjwtFA=pNaQT3q5ttzyrZtLpc4w@mail.gmail.com> In-Reply-To: <26325c0b-4960-7739-72aa-c31c4e0638d3@aceshardware.com> References: <ca76e5f7-6e59-bd67-144a-90ad66f0252e@metricspace.net> <7d7bc47d-04cf-2f9b-00a3-e3d9d92b3623@aceshardware.com> <72922F2C-9D27-47AA-BB1C-2DA8589CF008@rpi.edu> <92bd5362-d898-aa12-8f3d-9fbe23f38e0c@aceshardware.com> <CAOtMX2gPrpO2O70pnwpU80bXMXo6LB9PCkU3bYw2ToMMnhf%2Bww@mail.gmail.com> <26325c0b-4960-7739-72aa-c31c4e0638d3@aceshardware.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 6 Jan 2019 at 16:58, Brian Neal <brian@aceshardware.com> 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:
<snip>
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<stdint.h>
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADWvR2gYVAX15RFvQcO=HNpwjwtFA=pNaQT3q5ttzyrZtLpc4w>
