Speculative: Rust for base system components

Igor Mozolevsky igor at hybrid-lab.co.uk
Sun Jan 6 17:49:27 UTC 2019


On Sun, 6 Jan 2019 at 16:58, Brian Neal <brian at 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.


More information about the freebsd-hackers mailing list