Date: Sun, 6 Jan 2019 10:54:35 -0700 From: Alan Somers <asomers@freebsd.org> To: Igor Mozolevsky <igor@hybrid-lab.co.uk> Cc: Brian Neal <brian@aceshardware.com>, "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: Re: Speculative: Rust for base system components Message-ID: <CAOtMX2hZnDSgBRFG0Pnx0TtRHknHWj5X18QrxMx8F-EREh0wiw@mail.gmail.com> In-Reply-To: <CADWvR2gYVAX15RFvQcO=HNpwjwtFA=pNaQT3q5ttzyrZtLpc4w@mail.gmail.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> <CADWvR2gYVAX15RFvQcO=HNpwjwtFA=pNaQT3q5ttzyrZtLpc4w@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jan 6, 2019 at 10:49 AM Igor Mozolevsky <igor@hybrid-lab.co.uk> wrote: > > 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. Igor, please stop commenting unless you have something constructive to add.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2hZnDSgBRFG0Pnx0TtRHknHWj5X18QrxMx8F-EREh0wiw>