flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Assembly with Rust: |
Author |
|
bitRAKE 02 Jun 2022, 08:10
Code: #[allow(non_snake_case)] #[inline(always)] /// Try to showcase all the asm!() features in one routine, lol: /// /// A000931: Padovan sequence (or Padovan numbers): /// [1,0,0],1,0,1,1,1,2,2,3,4,5,7,9,12,16,21,28,37,49,65,86,114,151,... /// `Plastic number, only real solution to x^3 = x + 1` fn A000931(nth: u64 ) -> u64 { let mut result:u64 = unsafe { MaybeUninit::uninit().assume_init() }; unsafe {asm!( " push 1 pop {p0} xor {p1:e}, {p1:e} xor eax, eax 7: lea {p0}, [{p0}+{p1}] xchg rax, {p1} xchg rax, {p0} loop 7b ", p0 = out(reg) _, p1 = out(reg) _, inlateout("rcx") nth => _, inlateout("rax") result, options(pure, nomem, nostack), )}; result } In some cases, many hoops need to be jumped through to get around the language safety features. For example, Code: let mut result:u64 = unsafe { MaybeUninit::uninit().assume_init() }; Posting my discovery process on github: https://github.com/bitRAKE/rust-playground _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
02 Jun 2022, 08:10 |
|
bitRAKE 02 Jun 2022, 14:02
The robustness of the HLL part is quite good, but it obviously comes at substantial cost: 100's of MB to the build system for each project; massive runtime overhead - which includes the loss of two general purpose registers; and a cryptic language which is evolving away from the low-level features.
Rust is just doing some substitution and breaking up lines for the backend (gcc/clang). Which is just enough to make it useable, imho. It's certainly better than trying to inline asm in clang/gcc directly. I still need to try out some AVX algorithms. There are subtleties in the asm!() macro where it will silently uses the same register for multiple parameters, which is usually not the desired behavior. Even having the anonymous registers labeled didn't help. Marking all clobbered registers as outputs is a must. As long as there is an assembly language I think people will program in it. |
|||
02 Jun 2022, 14:02 |
|
AsmGuru62 02 Jun 2022, 22:50
Recently I found out that all I need from HLL to code a large project is IF/ELSE/REPEAT/WHILE -- but FASM #1 already has all that!
I also have an excellent IDE -- coded it myself. |
|||
02 Jun 2022, 22:50 |
|
Furs 03 Jun 2022, 13:13
bitRAKE wrote: Marking all clobbered registers as outputs is a must. I really don't like Rust though. Is there a difference between Rust's inline asm and GCC's normal inline asm used in C/C++ code? |
|||
03 Jun 2022, 13:13 |
|
bitRAKE 03 Jun 2022, 14:02
Furs wrote: Is there a difference between Rust's inline asm and GCC's normal inline asm used in C/C++ code? https://rust-lang.github.io/rfcs/2873-inline-asm.html ... outlines the strategy Rust uses, and contrasts with methods used in other languages. Some examples, https://doc.rust-lang.org/rust-by-example/unsafe/asm.html Dev Doc, https://rustc-dev-guide.rust-lang.org/asm.html It seems mostly compatible with GCC's inline asm, but with some other features. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
03 Jun 2022, 14:02 |
|
Furs 04 Jun 2022, 12:51
Thanks, that's very intriguing.
|
|||
04 Jun 2022, 12:51 |
|
bitRAKE 23 Jun 2022, 18:45
Not too surprising ...
Meta Developing A New IR For LLVM's Clang C/C++ Compiler With Better Speed, Security _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
23 Jun 2022, 18:45 |
|
sylware 26 Jun 2022, 14:45
wonder if this inline assembly is supported in the rust-written rust compiler for supported targets.
|
|||
26 Jun 2022, 14:45 |
|
bitRAKE 26 Jun 2022, 17:46
Everything I've read indicates the LLVM backend is still used to compile ASM for Cranelift. Cranelift itself states executing a external assembler is supported/configurable.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
26 Jun 2022, 17:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.