Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utf8Array.Compare実装 #70

Merged
merged 33 commits into from
Nov 3, 2021
Merged

Utf8Array.Compare実装 #70

merged 33 commits into from
Nov 3, 2021

Conversation

finphie
Copy link
Owner

@finphie finphie commented Nov 3, 2021

No description provided.

@github-actions github-actions bot added the enhancement New feature or request label Nov 3, 2021
@finphie
Copy link
Owner Author

finphie commented Nov 3, 2021

GetUtf8SequenceLength

https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIAYACY8gOgCUBXAOwwEt8YLAJI8YUCAAcAymIBuvMDFwBuGvSatOPfoIDCEfBN4AbMTKjzFKmjV48GAQXIAKYAE8MMBrOzGOMAEoaAG8aBnCGXgAzBmcfPy8AHgY6BAAOOiDqCIZQ7JyI4gB2BnJVfPCAXxsKyJjnON9/BgAyFIQAUUyGAF4e9t1MsIi8gsKS0nKc6uph8OjYxoTW9oAxbr72rqyc0bGmEoBmKYiZubrF+Oa21NW0gN7+26HavbHihhQTqpqcj4ATGBRbAcYwYcpnWbUOwYRykVweLxXQIhc5sGDYf4AeS4xjcUgk2C4iXcngAfOEACpQbAmOwAcwAQojcKtoABVSl3XoMLgwADuDFJMAA2gBdc5vArkNClWUyuWKhXK+WqpVqlVy845TW6jX69WGvXaiJ6o0Gs2W1Um8JW832u0qm0Oi2ul3q52Ot1e82e73+93G2o6gM+sNoZ10WVRlLRuOxhMxpPx5OJuORlOZtPZ1O5zMZnNZvOFktRgvFitFqtp8uy0h1hsMetNxvNtutjst53tlu9nv9zsDvsR4MRQ6y8cMSfTiezqdzmfzpeL8fO9CfWXrrfVyul86Vb7hbWwGI+KAMDDYYCmHknhgAWRg+Ggbnv2CguAAFr4WABxGAYOiURiDAXCKM41K0sYDLMp4rIcly9yHgcDDslwuDYMBLAOP8/zOHel7XjAsrOFwMIBMiAQQkAA==

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

int A1(byte value)
{
    if (value < 0x80)
    {
        return 1;
    }

    if ((value & 0xE0) == 0xC0)
    {
        return 2;
    }

    if ((value & 0xF0) == 0xE0)
    {
        return 3;
    }

    if ((value & 0xF8) == 0xF0)
    {
        return 4;
    }

    return default;
}


int A2(byte value)
{
    ReadOnlySpan<byte>  TrailingBytesForUTF8 = new byte[]
    {
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
        4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
     
    ref var table = ref MemoryMarshal.GetReference(TrailingBytesForUTF8);
    return Unsafe.Add(ref table, (nint)value) + 1;
}
<Program>$.<<Main>$>g__A1|0_0(Byte)
    L0000: movzx edx, cl
    L0003: cmp edx, 0x80
    L0009: jge short L0011
    L000b: mov eax, 1
    L0010: ret
    L0011: mov eax, edx
    L0013: and eax, 0xe0
    L0018: cmp eax, 0xc0
    L001d: jne short L0025
    L001f: mov eax, 2
    L0024: ret
    L0025: mov eax, edx
    L0027: and eax, 0xf0
    L002c: cmp eax, 0xe0
    L0031: jne short L0039
    L0033: mov eax, 3
    L0038: ret
    L0039: and edx, 0xf8
    L003f: cmp edx, 0xf0
    L0045: jne short L004e
    L0047: mov eax, 4
    L004c: jmp short L0050
    L004e: xor eax, eax
    L0050: ret

<Program>$.<<Main>$>g__A2|0_1(Byte)
    L0000: movzx eax, cl
    L0003: mov rdx, 0x19063c30954
    L000d: movzx eax, byte ptr [rax+rdx]
    L0011: ret

@finphie finphie merged commit 6f0d6a9 into main Nov 3, 2021
@finphie finphie deleted the enhancement/CompareTo branch November 3, 2021 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant