Ok, so this should be the final patch needed, i don't think i can possibly get it any faster.
I removed an excess bitshift operation from each call and made things nicer. This version is a few % faster than the previous patch. Not a huge difference, but still a difference. Let me know if it's good to commit. Alan On 3/25/07, Miguel de Icaza <[EMAIL PROTECTED]> wrote:
Hello, > x86 actually has an instruction whose sole purpose is to invert the byte > order of a 32-bit value. Look up BSWAP. It requires at least a 486, though. > Does mono otherwise run on 386 CPUs presently? If it is okay to exclude 386 > systems (or they can be detected on-the-fly and given the alternative 3 > instructions), then perhaps it would be possible to do something like > marking it as an icall and having the JIT recognize that method and inline > it as just a BSWAP. Well, we can detect if the CPU is a 486 or better, and if so use the instruction instead of our own code. This would come in handy for BitConverter and DataConverter as well. _______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list
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) @@ -63,23 +63,23 @@ private static int SwapInt (int number) { - return ((number >> 24) & 0xFF) - + (((number >> 16) & 0xFF) << 8) - + (((number >> 8) & 0xFF) << 16) - + ((number & 0xFF) << 24); + return (((number >> 24) & 0xFF) + | ((number >> 08) & 0xFF00) + | ((number << 08) & 0xFF0000) + | ((number << 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 >> 08) & 0xFF000000) + | ((number << 08) & 0xFF00000000) + | ((number << 24) & 0xFF0000000000) + | ((number << 40) & 0xFF000000000000) + | ((number << 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