Ok, more performance ;) The SwapInt() method is now 40% faster than when i originally started and SwapLong() is now 50% faster than the original method. This means i do 15 iterations of converting a long in 8500ms, which isn't that much slower than the MS one (6700ms)
All i did this time was remove the extra bit shifts. Instead of shifting across by 48, then &'ing then shifting back by 8 i just shifted across by 40 and &'ed there. Patch attached. Let me know if it's OK to commit. Alan. On 3/25/07, Gareth Pearce <[EMAIL PROTECTED]> wrote:
> > > > > However, as a comparison, the MS.NET <http://MS.NET> > <http://MS.NET> implementation > > completes 15 loops of the benchmark in a mere 6718ms ;) > > > On this point, I suspect AOT compilation of the .Net system assemblies may be making the difference. The AOT might be able to recognize certain patterns are equivalent to rot instructions and replace a bunch of shifts and masks with a set of unsigned rots. A 32bit reorder is rot 8 on each of the 16 bit sections and a rot 16 on the full variable. I think that can be done in 3 clocks on x86 - but my assembly is rusty. --Gareth
Index: C:/programming/mcs/class/System/System.Net/IPAddress.cs =================================================================== --- C:/programming/mcs/class/System/System.Net/IPAddress.cs (revision 74942) +++ C:/programming/mcs/class/System/System.Net/IPAddress.cs (working copy) @@ -58,7 +58,7 @@ private static short SwapShort (short number) { - return (short) ( ((number >> 8) & 0xFF) + ((number << 8) & 0xFF00) ); + return (short) ( ((number >> 8) & 0xFF) | ((number << 8) & 0xFF00) ); } private static int SwapInt (int number) @@ -64,22 +64,22 @@ private static int SwapInt (int number) { return ((number >> 24) & 0xFF) - + (((number >> 16) & 0xFF) << 8) - + (((number >> 8) & 0xFF) << 16) - + ((number & 0xFF) << 24); + | (((number >> 8) & 0xFF00)) + | (((number << 8) & 0xFF0000)) + | (((number & 0xFF) << 24)); } - private static long SwapLong(long number) - { - return (((number >> 56) & 0xFF) - + (((number >> 48) & 0xFF) << 8) - + (((number >> 40) & 0xFF) << 16) - + (((number >> 32) & 0xFF) << 24) - + (((number >> 24) & 0xFF) << 32) - + (((number >> 16) & 0xFF) << 40) - + (((number >> 8) & 0xFF) << 48) - + ((number & 0xFF) << 56)); - } + private static long SwapLong(long number) + { + return (((number >> 56) & 0xFF) + | (((number >> 40) & 0xFF00)) + | (((number >> 24) & 0xFF0000)) + | (((number >> 8) & 0xFF000000)) + | (((number << 8) & 0xFF00000000)) + | (((number << 24) & 0xFF0000000000)) + | (((number << 40) & 0xFF000000000000)) + | ((number & 0xFF) << 56)); + } public static short HostToNetworkOrder(short host) { if (!BitConverter.IsLittleEndian)
_______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list