New answers tagged

1 vote

Thread-safe int wrapper in c#

// read freshest value private int Get() => Interlocked.CompareExchange(ref _value, 0, 0); Using an ...
harold's user avatar
  • 9,049
2 votes
Accepted

Thread-safe int wrapper in c#

Based on the discussion in the comments section I think the code can be greatly simplified: ...
Peter Csala's user avatar
  • 8,510
1 vote

Optimisation: Fastest way to multiply every number in an array by 2

Thanks to @harold the goal of getting under 50 ns was achieved with loop unrolling and removing the unnecessary copy instruction. The code below is similar to his but is bithacked and instead of using ...
Henners2002's user avatar
1 vote

Optimisation: Fastest way to multiply every number in an array by 2

A couple of further things we can do are: Use Vector256.StoreUnsafe for the store. It's not a huge deal, but going by the assembly, the ...
harold's user avatar
  • 9,049
1 vote

Optimisation: Fastest way to multiply every number in an array by 2

After a suggestion by @harold a further 15ns has been shaved off by using the Vector.ShiftLeft(v, 1) method instead of doing the multiplication and secondly to use <...
Henners2002's user avatar
1 vote

Optimisation: Fastest way to multiply every number in an array by 2

Upon a suggestion from @iSR5 I have reimplemented the SIMD instruction using the MemoryMarshall method. This has shaved off a further 60ns. I think SIMD instructions and the memory marshall method go ...
Henners2002's user avatar
3 votes

Optimisation: Fastest way to multiply every number in an array by 2

I have shaved off about 100ns with the following improvements: used a shift operator to perform the multiplication by 2, since I know that my Vector<int>.Count...
Henners2002's user avatar

Top 50 recent answers are included