4 ms·
Learn Rust the Dangerous Way
- deleted 2y ago[deleted]
- einpoklum 2y agoTL;DR: An introduction to Rust which starts with a Rust-unsafe C program, writing a Rust equivalent, then evolves it towards some of the higher-level abstractions in Rust. (As opposed to the non-dangerous way which means writing safe code to begin with and mentioning unsafe as the exception)
- Epholys 2y agoTo complete the TL;DR : the safe Rust code is at 97% the speed of the C code, if keeping manual vectorization.
- simon_void 2y agoTo complete the completion of the TL;DR : the 95% safe Rust Code using auto vectorization is even slightly faster than the C code.
- FFFXXX 2y agoThe 95% safe Rust Code does not use any auto-vectorization (https://cliffle.com/p/dangerust/5/nbody-5.rs https://cliffle.com/p/dangerust/5/nbody-5.rs) Only the 100% Rust-safe implementation uses auto-vectorization and is at 0.73% of the RUNTIME of the C code. (https://cliffle.com/p/dangerust/6/#performance-evaluation https://cliffle.com/p/dangerust/6/#performance-evaluation)
- estebank 2y ago*73%
- FFFXXX 2y agoNo, the Rust code is at 97% of the RUNTIME of the C code (https://cliffle.com/p/dangerust/5/#evaluation https://cliffle.com/p/dangerust/5/#evaluation) when keeping the manual vectorization.
- deleted 2y ago[deleted]
- kookamamie 2y agoAFAIK, auto-vectorization has the same limitation in Rust as in C and C++ - it cannot be required. Hence, it is very easy to break the vectorization in brittle ways, without even noticing the issue. It would be nice to have a sort of autovec-or-error annotation for preventing this.
- dwattttt 2y agoRust is experimenting with "portable SIMD": https://doc.rust-lang.org/std/simd/index.html https://doc.rust-lang.org/std/simd/index.html It defines a generic `Simd<T, N>` type, expressing "This is a vector of T elements (such as i8), and is present in chunks of N". Methods that are easily vectorisable are defined on it, so if you can express what you want to do with one, you'll get well defined vectorised operations. Maybe not as perfect as you could hand write if you know what you're doing, but it _does_ guarantee to use vector instructions, so you're not at the behest of the compiler recognising a loop idiom.
- kookamamie 2y agoYes, that's a variant of manual vectorization. However, AFAIK Rust doesn't provide dynamic dispatching as part of the portable SIMD? If this is the case, ISPC still looks like a better option, I think, albeit it is unlikely to be seen as the Rusty way of doing things.
- flohofwoe 2y agoIt's most likely built onto the same LLVM features which enable the 'Clang extended vector extension' for C (it even compiles down to scalar code for CPUs without SIMD support): https://www.godbolt.org/z/MW8WeYjGo https://www.godbolt.org/z/MW8WeYjGo Not sure why Rust needs a lot of experimenting tbh, it's been in Clang since forever.
- steveklabnik 2y agoJust because the underlying infrastructure works doesn’t mean experimentation isn’t warranted, it’s about how you present the API to the user. Note that the ALI you’ve shown off here is different than the one shown above, maybe one or the other is better to use, hence experimenting with it.
- 0xpgm 2y agoReminds me of Learn x the hard way series by Zedshaw
- deleted 2y ago[deleted]
- davidhyde 2y agoIf you learned Rust first but find yourself reading a lot of C then this is also a good thing to read because of the parallels it draws with the languages.
- dagw 2y agoWow! At least for me this is by far the best, clearest and most useful quick intro to Rust I've seen.
- incognito124 2y agoTo OP: having this jarring purple, combined with a dark background and dotted underline is really painful for my eyes
- muyanapar 2y agoContrary to the guidelines of design, I really like it.