[Mono-dev] Patch for IPAddress.cs

Gareth Pearce tilps.kilm at gmail.com
Sat Mar 24 23:19:01 EDT 2007


Good performance improvement, the last mask isn't needed since the left 
shift will remove the top 56bits anyway (in the long case, 24 in the int 
case and 8 in the short case), but that isn't going to help performance 
much I expect.  The first mask is still required, since right shift pads 
with 1's if the high bit is set.
My only other comment is that the masking should probably be consistent 
(applied before or after the shift for all bytes, not sometimes 
before/sometimes after) to assist any AOT pattern detection based 
optimizations which could get implemented in future to use target 
specific byte reordering instructions (I believe some processors have 
single instructions for conversion from little to big endian, and x86 
could potentially benefit from use of rot instruction).  This is just a 
conjecture since I have no experience with the AOT framework in mono.

--Gareth

Alan McGovern wrote:
> 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* wrote:
>
>
>     >
>     >     >
>     >     > However, as a comparison, the MS.NET <http://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
>



More information about the Mono-devel-list mailing list