Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Renaming IndexOfVectorized to IndexOf#1320

Merged
KrzysztofCwalina merged 3 commits into
dotnet:masterfrom
ahsonkhan:IndexOfVectorized
Mar 17, 2017
Merged

Renaming IndexOfVectorized to IndexOf#1320
KrzysztofCwalina merged 3 commits into
dotnet:masterfrom
ahsonkhan:IndexOfVectorized

Conversation

@ahsonkhan
Copy link
Copy Markdown
Contributor

@ahsonkhan ahsonkhan commented Mar 16, 2017

@KrzysztofCwalina, is the method name fine?
cc @davidfowl

}

public unsafe static int IndexOfVectorized(this Span<byte> buffer, byte value)
public static int IndexOfNon_Vectorized(this Span<byte> span, byte value)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be without underscore, I think

@benaadams
Copy link
Copy Markdown
Member

benaadams commented Mar 16, 2017

Is conveying implementation detail? Maybe
IndexOfFastStart

@KrzysztofCwalina
Copy link
Copy Markdown
Member

What about calling it IndexOfSequential? or SequentialIndexOf.

length -= 8;

if (value == Unsafe.Add(ref searchSpace, index))
goto Found;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called Found0 for consistency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have intentionally named it this way: there is index and no index + 0 here either; and Found0 looked odd in the last loop that goes by single element.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. sounds good

if (length < Vector<byte>.Count)
Debug.Assert(length >= 0);

IntPtr index = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use IntPtr.Zero

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many hundreds instances of both forms in corefx. (My rule of thumb - if there are two equivalent forms, use the one that has fewer characters.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In dotnet/coreclr#9473 I found IntPtr.Zero to generally be worse as it does a memory load as a readonly static struct rather than a conversion that is then elided.

Is noted as the reason for the existence of internal IsNull()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntPtr.Zero is treated as intrinsic by the JIT and should be JITed as zero constant. Look for CORINFO_FIELD_INTRINSIC_ZERO with optimizations on. If you do not see it happening, it is a bug that should be fixed.

The comment on IsNull predates the CORINFO_FIELD_INTRINSIC_ZERO optimization.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should do the cleanup separately (if we even want).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will have a look at it again and raise issue if I come across it again (I think it was less happy to inline using IntPtr.Zero)

@KrzysztofCwalina
Copy link
Copy Markdown
Member

looks good.

@KrzysztofCwalina KrzysztofCwalina merged commit b6e2f4c into dotnet:master Mar 17, 2017
@ahsonkhan ahsonkhan deleted the IndexOfVectorized branch March 17, 2017 18:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants