Overhead of Cell<f32> .get, .set

One more followup to N f32's <-> Rc pointers <-> *mut f32 for blas/C - #6 by zeroexcuses

I'm writing a mini-Tensor library of sorts. As a result, there a common operation is to create a N-1 dimension tensor from a N dimension tensor by "pinning" one dimension, and iterating over all remaining dimensions.

Now, my question is:

dst[i].set( src[j].get() ); // assume both are Vec<Cell<f32>>

as cheap as

dst[i] = src[j] ;// assume both are Vec<f32>

Or is there some additional cost due to .get .set that is NOT compiled away?

If Cell .get, .set are 'zero cost' abstractions, what can I read to "prove to myself" that Cell .get.set are indeed "zero cost" ?

2 Likes

Its source code in the standard library. Notice the #[inline]

Also, play.rust-lang.org and godbolt.org are an easy way to view the generated assembly of your code.

2 Likes

Without cell the compiler is potentially able to optimise due to knowledge of noalias. Only know for sure by looking at machine code.

2 Likes