Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Understanding assembly code of rust and c
I was going through some addition (a+b) operation in the code that I wrote and figuring out why Rust was little ยตs faster than the C in my specific implementation.
I have three distinctive assembly code of (a+b) operation.
C assembly code for a+b (release build) - this implementation took 1.3ยตs
Rust assembly code for a+b (release build) - this implementation took 1.38ยตs
Rust assembly code for a.wrapping_add(b) (release build) - this implementation took 1.24ยตs
From the above code, if you see, C and Rust with normal (a+b) have the similar assembly instructions, as they are loading the values from memory and storing the values. While, the wrapping_add function does it through the data registers, hence it is faster a bit compared to C.
What I am interested in knowing from you, which I couldn't find a concrete reason is, as to why this behaviour exists. Please correct me if my analysis of the assembly instruction is wrong here and can you tell me if this behaviour is from hightec llvm rust compiler (this is the one i am using) optimization for such functions or it is a rust language feature by default.
1 post - 1 participant
๐ท๏ธ rust_feed