# Announcing support for rust 1.0 in "Rust Explorer"

**URL:** <https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287>\
**Category:** tools and infrastructure\
**Created:** [January 12, 2015, 2:56am UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287 "2015-01-12T02:56:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattgodbolt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mattgodbolt/32/611_2.png) [@mattgodbolt](https://internals.rust-lang.org/u/mattgodbolt)\
**Post date:** [January 12, 2015, 2:56am UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287/1 "2015-01-12T02:56:04Z")

</div>

Hi there,

In light of the recent rust 1.0 release I’ve added support for rust 1.0 to my compiler assembly explorer. It allows you to write code and see the assembly code emitted interactively. It’s online at [http://rust.godbolt.org/](http://rust.godbolt.org/) - you’ll need to make a “pub fn testFunc” or similar to get code actually visible.

I’m a complete rust newbie so thoughts welcomed: the source is on github if you care to look.

One thing I’ve noticed - coming from the C++ world - the rust code generation seems a little substandard. Take for example the one and only example I’ve gotten working. Visiting [http://gcc.godbolt.org/](http://gcc.godbolt.org/) and trying the same example in clang with appropriate options ([http://goo.gl/4Zexu0](http://goo.gl/4Zexu0) for example) yields beautiful vectorized code. Is there an a command-line switch I’m missing?

Hope you guys find the tool helpful, and thanks in advance for any ideas on improvements and/or how to showcase the blazing fast speed of rust better.

Thanks! Matt

---

<div class="post-metadata">

**Author:** ![Gankra](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/gankra/32/6002_2.png) [@Gankra](https://internals.rust-lang.org/u/Gankra)\
**Post date:** [January 12, 2015, 3:35am UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287/2 "2015-01-12T03:35:14Z")

</div>

It should be noted that we just released 1.0 _alpha_ which is largely a symbolic release with weak back-compat guarantees. Big changes are still coming!

That said, rustc is well-known to have substandard codegen and compile-times. As I understand it, this is due to us largely doing the minimum amount of work to generate a valid representation of the program for LLVM. It has to do a lot of work to rip through all the sloppy IR we generate to produce something reasonable, and we often aren’t giving the optimal metadata/flags for it to do what you would want.

There are some longterm plans to improve this situation after 1.0-stable lands (12+ weeks away), but for now the focus is on semantics and correctness – with the caveat that our abstractions “should” optimize well with a sufficiently good compiler implementation.

---

<div class="post-metadata">

**Author:** ![huon](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/huon/32/3698_2.png) [@huon](https://internals.rust-lang.org/u/huon)\
**Post date:** [January 12, 2015, 6:19am UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287/3 "2015-01-12T06:19:51Z")

</div>

I've always really liked this site! Thanks for your effort.

> One thing I've noticed - coming from the C++ world - the rust code generation seems a little substandard. Take for example the one and only example I've gotten working

I tweaked the code tiny a bit and got ["better" codegen](http://goo.gl/njAXpJ) (not sure if it's actually faster...):

```rust
#[allow(unstable)]
pub fn max_array(x: &mut[f64; 65536], y: &[f64; 65536]) {
  unsafe {
    std::intrinsics::assume(x.as_ptr() as usize % 64 == 0);   
    std::intrinsics::assume(y.as_ptr() as usize % 64 == 0);
  }
  for i in (0..65536) {
      x[i] = if y[i] > x[i] { y[i] } else {x[i]};
  }
}

```

(The `assume`s are a hacked up version of `__builtin_assume_aligned`, but the code only changes `movapd` to `movupd`, as one might expect, without it.)

Gives

```asm
.LBB0_3:
    movapd (%rsi,%rax,8), %xmm0
    movapd 16(%rsi,%rax,8), %xmm1
    maxpd (%rdi,%rax,8), %xmm0
    maxpd 16(%rdi,%rax,8), %xmm1
    movapd %xmm0, (%rdi,%rax,8)
    movapd %xmm1, 16(%rdi,%rax,8)
.Ltmp3:
    addq $4, %rax
    cmpq $65536, %rax
    jne .LBB0_3

```

for the loop, vs.

```asm
.LBB0_1: # %vector.body
    movupd (%rsi,%rax,8), %xmm0
    movupd (%rdi,%rax,8), %xmm1
    maxpd %xmm0, %xmm1
    movupd %xmm1, (%rdi,%rax,8)
    addq $2, %rax
    cmpq $65536, %rax # imm = 0x10000
    jne .LBB0_1

```

for clang.

> the one and only example

I ported the "sum array" one:

```rust
#[allow(unstable)]
pub fn sum_array(x: &[i32]) -> i32 {
  unsafe {
    std::intrinsics::assume(x.as_ptr() as usize % 64 == 0);   
  }
  x.iter().fold(0, |sum, next| sum + *next)
}

```

(The `unsafe` and `assume` is not necessary, but it mirrors the "opt" versions of the C code, and gives slightly nicer code.)

---

<div class="post-metadata">

**Author:** ![mattgodbolt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mattgodbolt/32/611_2.png) [@mattgodbolt](https://internals.rust-lang.org/u/mattgodbolt)\
**Post date:** [January 12, 2015, 12:18pm UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287/4 "2015-01-12T12:18:48Z")

</div>

Thanks huon! If you don’t mind I’ll put those in as the “opt” versions for rust.

---

<div class="post-metadata">

**Author:** ![comex](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/comex/32/2587_2.png) [@comex](https://internals.rust-lang.org/u/comex)\
**Post date:** [January 13, 2015, 12:45am UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287/5 "2015-01-13T00:45:22Z")

</div>

I can see two differences between the Rust and C++ versions, aside from the aligned assumption: the C++ one is on doubles rather than int32s, and the Rust one does a conditional rather than unconditional store. If those are equalized…

```rust
void maxArray(int* __restrict x, int*__ restrict y) {
    for (int i = 0; i < 65536; i++) {
        x[i] = ((y[i] > x[i]) ? y[i] : x[i]);
    }
}

```

```rust
pub fn max_array(x: &mut[i32; 65536], y: &[i32; 65536]) {
  for i in (0..65536) {
     x[i] = if y[i] > x[i] { y[i] } else { x[i] };
  }
}

```

the code generated by clang and rustc looks pretty similar, except that the Rust one goes 8 elements at a time rather than 4 for some reason. Different tuning options?

(Same goes if you change Rust to f64 instead, and compare against the non-‘opt’ C++ version which does the conditional store: similar code, but Rust goes two at a time.)

---

<div class="post-metadata">

**Author:** ![mattgodbolt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mattgodbolt/32/611_2.png) [@mattgodbolt](https://internals.rust-lang.org/u/mattgodbolt)\
**Post date:** [January 13, 2015, 3:15am UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287/6 "2015-01-13T03:15:24Z")

</div>

Wow; I hadn’t even spotted that I’d switched doubles for i32s - thanks for noticing! I’ll update the code as you suggest, and also add the “opt” tweaks that huon indicated! Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:23am UTC](https://internals.rust-lang.org/t/announcing-support-for-rust-1-0-in-rust-explorer/1287/7 "2019-03-25T08:23:37Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
