Re: [Mono-dev] What's the most efficient way to do XOR two byte arrays?

2014-11-19 Thread Chris Eelmaa
There is virtually no difference between Array.Copy and
Buffer.BlockCopy when dealing with large buffers.

If you are rapidly calling Array.Copy with smaller buffers, then yes,
you can save some milliseconds if you switch to Buffer.BlockCopy,
because it skips checks / makes less function calls, and there's less
overhead. As I said, the difference comes to play when we are dealing
with very small data rapidly.


That said,

you can make some serious gains when you're dealing with large
buffers. You just need to parallelize it, and make sure there is no
false cache sharing.

The other trick is to see what Mono.Simd offers. I don't see a reason
why Xoring 128-bit blocks at once shouldn't be possible. You want
something similiar:
http://stackoverflow.com/questions/15067119/how-can-i-use-simd-to-accelerate-xor-two-blocks-of-memory

Note I have absolutely no experience with Mono.Simd but I imagine it's
pretty cool.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] What's the most efficient way to do XOR two byte arrays?

2014-11-18 Thread Edward Ned Harvey (mono)
Obviously, I could just use a for-loop.  But then my code is theoretically 
telling the system to XOR each byte individually, wasting most of the CPU on 
each instruction.

I wrote unsafe code to do this with 32-bit and 64-bit int pointers.  
Surprisingly they both performed about the same (I guess, at least on my 
system, 64bit instructions take longer to execute, effectively eliminating most 
of the gains of the wider bus).  Unsurprisingly, they greatly outperformed the 
unoptimized for-loop.

Surprisingly, the difference between the optimized unsafe code and the 
optimized for-loop suggested it was a waste of effort.  (Only marginally 
faster.)

I don't know what kind of optimizations the compilers are able to perform on 
this code:

for (int i=0; i___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list