jahboater
Posts: 2049
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 12:18 pm

Interesting.
paddyg wrote:
Tue Nov 21, 2017 12:10 pm
(I noticed that although doing / 8 was just as fast as >> 3 on my laptop, on the RPi it was slower so I switched it back)
I think any modern compiler should do that by the way. In my code, rustc converted / 2 to "asr r6, r0, #1" successfully.

User avatar
paddyg
Posts: 2024
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 2:24 pm

Yes, not sure why. It's a small but real difference (0.950s c.f. 0.925s) I've not looked at the internals of the generated code.

Doing a basic prime calculation like the subject of this discussion, I get

laptop (to 100,000)
2.35s +/-0.06 C
2.31s +/-0.01 rust
RPi3 (to 50,000)
8.01s +/-0.07 C
11.4s +/-0.10 rust

So 50% slower rather than 10x slower.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

jahboater
Posts: 2049
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 2:49 pm

Rustc uses LLVM (as Clang does) which is quite respectable, and should produce fast code.
I would certainly expect it to be in the same ball park as C.

The silly program I used did "if( n % d == 0 )" in a tight inner loop .....
the ARMv6 code produced by rustc/LLVM was:

bl __aeabi_idivmod

The much faster ARMv8 code produced by GCC was:

sdiv r1, r4, r3
mls r1, r3, r1, r4

which explains the 10x performance difference (never use trivial artificial benchmarks!)

Heater
Posts: 8416
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 6:33 pm

paddyg,
Sounds like an expanded version of the Raspberry Pi forum rules "Be good to each other"... But it doesn't say you can't use rust for whatever devilish antisocial purpose you had in mind, just abide by the rules if you contribute to IRC channels, github or official rust.org forum. So you could use rust and be as unfriendly as you want on reddit (so long as you don't harass people).
I don't particularly have a desire to use Rust or any other programming language for "devilish antisocial purposes". Neither do I want to be unfriendly to anyone on reddit or anywhere else.

I do find the Rust code of conduct distasteful. Basically it says that if you ever express an opinion that someone finds "uncomfortable" then you should apologize and/or be ostracized.

Well, how could I ever use Rust? Perhaps I might want to file a bug report? It would be impossible to know if I had overstepped someones comfort zone? My disdain of Political Correctness might be detected almost immediately.

This is the kind of thinking that deposed Brendan Eich, the inventor of Javascript, from his position at a company he helped build. Simply for having a political view that others disagreed with. http://www.bbc.com/news/technology-26868536

It's the kind of thinking that got Douglas Crockford uninvited from giving a key note speech at a conference because his use of words like "promiscuous" in a technical sense made somebody feel uncomfortable. http://atom-morgan.github.io/in-defense ... -crockford

It's the kind of thinking that got James Damore fired from Google this summer: https://www.washingtonpost.com/news/mor ... 6fed795710

As a language Rust might be fine.

I find it a bit dishonest for rust-lang.org to describe Rust as a "systems programming language". As far as I can tell Rust cannot compile itself yet. You cannot build a Rust compiler using a Rust compiler. It depends on LLVM. That is to say C++.

Maybe one day.

mifwoo
Posts: 1
Joined: Sat Nov 25, 2017 8:02 pm

Re: Rust seems to bring some love to Rpi

Sat Nov 25, 2017 9:29 pm

Heater wrote:
Tue Nov 21, 2017 6:33 pm
I find it a bit dishonest for rust-lang.org to describe Rust as a "systems programming language". As far as I can tell Rust cannot compile itself yet. You cannot build a Rust compiler using a Rust compiler. It depends on LLVM. That is to say C++.

Maybe one day.
Rust compiles itself since 2011.
The same year, work shifted from the initial compiler (written in OCaml) to the self-hosting compiler written in Rust.[30] Known as rustc, it successfully compiled itself in 2011.

Heater
Posts: 8416
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Sun Nov 26, 2017 3:07 pm

That's not quite true now is it mifwoo.

Yes Rust compiles itself but it generates an intermediate representation of the code, LLVM IR.

One then needs LLVM to optimize and generate code from that intermediate representation. LLVM is written in C++.

So, if you want to build a complete Rust tool chain from scratch you need a working Rust compiler and a working C++ compiler.

https://www.quora.com/Is-Rust-a-self-hosted-language

ejolson
Posts: 1114
Joined: Tue Mar 18, 2014 11:47 am

Re: Rust seems to bring some love to Rpi

Mon Nov 27, 2017 3:44 pm

Heater wrote:
Sun Nov 26, 2017 3:07 pm
That's not quite true now is it mifwoo.

Yes Rust compiles itself but it generates an intermediate representation of the code, LLVM IR.

One then needs LLVM to optimize and generate code from that intermediate representation. LLVM is written in C++.

So, if you want to build a complete Rust tool chain from scratch you need a working Rust compiler and a working C++ compiler.

https://www.quora.com/Is-Rust-a-self-hosted-language
I think Rust being a systems programming language refers to the feature set which allows writing low-level code such as device drivers and memory managers which interact directly with the hardware.

If you want a self-hosting system based on Rust, which is a different thing in my opinion, the easiest way might be to first write a C compiler in Rust. Use the Rust-built C compiler to compile a C++ compiler, then use the C++ compiler to compile LLVM.

Heater
Posts: 8416
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Mon Nov 27, 2017 7:44 pm

ejolson,
I think Rust being a systems programming language refers to the feature set which allows writing low-level code such as device drivers and memory managers which interact directly with the hardware.
That is the way I read it as well.

There is even an entire operating system written in Rust to prove the point: https://github.com/redox-os/redox

Although, as far as I can tell, Redox does not run on bare hardware yet.
If you want a self-hosting system based on Rust, which is a different thing in my opinion, ...
I think that was my point. As it stands you cannot build a Rust only self hosting system, on Redox for example. You would have to get a C++ compiler running on Redox first.
the easiest way might be to first write a C compiler in Rust. Use the Rust-built C compiler to compile a C++ compiler, then use the C++ compiler to compile LLVM.
That all sounds far to tortuous.

Somebody did suggest recreating LLVM in Rust. That would do it. I don't think anyone is ever going to do that. But who knows? There are crazy people out there!

User avatar
paddyg
Posts: 2024
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Rust seems to bring some love to Rpi

Mon Nov 27, 2017 10:45 pm

The arguments for rust are that it's 'easier' to write 'safe' code. The problem is that if the switch is from old C and C++ utilities, not only is the switch from code that's already been written (so requires zero effort to write) and has a large pool of potential maintainers, but it's been very extensively tested in the real world. As you say it seems an extravagant task - but it would be very good training so maybe it will happen eventually.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Heater
Posts: 8416
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Mon Nov 27, 2017 11:42 pm

I think, the best bet is that Rust or whatever new language the youngn's come up with next can make use of all the existing infrastructure. That is interface and link with C easily. I have no idea if Rust can do that but I presume so.

On the other hand, this last week I have found that openssl in Debian Linux, hence Raspbian, suffers from memory leaks and race conditions. Our whole foundations are rotten.

User avatar
Paeryn
Posts: 1717
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Rust seems to bring some love to Rpi

Tue Nov 28, 2017 2:13 am

Heater wrote:
Mon Nov 27, 2017 11:42 pm
I think, the best bet is that Rust or whatever new language the youngn's come up with next can make use of all the existing infrastructure. That is interface and link with C easily. I have no idea if Rust can do that but I presume so.
Yes, Rust has a decent FFI so you can call C code from Rust and vice versa without too much hassle. It's quite a nice language.
She who travels light — forgot something.

User avatar
Gavinmc42
Posts: 1607
Joined: Wed Aug 28, 2013 3:31 am

Re: Rust seems to bring some love to Rpi

Tue Nov 28, 2017 4:45 am

What lib does Redox use re openssh/ssl?

https://www.redox-os.org/
I am hanging out waiting to try Redox on a Pi3 in Aarch64.

I was impressed on how easy it was to get Rustc working on a Pi and the language itself is too not bad.
Probably one of the nicer ones of this new gen.
And the Servo browser has some nice tricks.

Throw everything out and run Redox on RISCV?
Redox on Pi3 with simple Servo browser, I can see myself using it.
Might have to try it on a x86 box first, yuk.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

jahboater
Posts: 2049
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 28, 2017 8:42 am

Paeryn wrote:
Tue Nov 28, 2017 2:13 am
Yes, Rust has a decent FFI so you can call C code from Rust and vice versa without too much hassle. It's quite a nice language.
People could also look at "go" and "D".
Probably all inspired by the excessive complexity of modern C++.

Heater
Posts: 8416
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 28, 2017 9:20 am

Looking at the Redox cookbook we see they have a lot of recipes for making use of C libraries and programs in Redox. Like this one for openssh: https://github.com/redox-os/cookbook/pu ... 0a75884b85

Openssl for rust is here: https://github.com/sfackler/rust-openssl Which we see depends on openssl in C, OpenSSL version 1.0.1 or above, or LibreSSL.

User avatar
Gavinmc42
Posts: 1607
Joined: Wed Aug 28, 2013 3:31 am

Re: Rust seems to bring some love to Rpi

Tue Nov 28, 2017 12:16 pm

IoT not going to take off until we get secure comms.
Reusing old code with who knows what inside?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 18408
Joined: Sat Jul 30, 2011 7:41 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 28, 2017 1:23 pm

Gavinmc42 wrote:
Tue Nov 28, 2017 12:16 pm
IoT not going to take off until we get secure comms.
Reusing old code with who knows what inside?
We have secure comms, the IoT suppliers just need to use it....and some of course do.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

Heater
Posts: 8416
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 28, 2017 4:04 pm

Gavinmc42,
Reusing old code with who knows what inside?
We know exactly what's inside openssl. Here it is:
https://github.com/openssl/openssl

Arguably it's better to fix what we have if need be rather than create a whole new version with a whole lot of new issues of it's own.

I was subjecting my C++ to analysis with the memory leak and thread analyzers that come the clang/llvm C++ compiler. I found a couple of memory leaks and thread race conditions in openssl. So far I'm not sure if these issues are down to openssl itself or the way it is used by the pqxx postgress database connector I'm using. We shall see.

Then again secure comms as provided by openssl is not the end of the story. An awful lot of systems get broken for many other reasons than the crypto library they are using. This security thing is hard.

Return to “Other languages”

Who is online

Users browsing this forum: No registered users and 5 guests