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

IsAsciiメソッドを追加 #94

Merged
merged 29 commits into from
Nov 14, 2021
Merged

IsAsciiメソッドを追加 #94

merged 29 commits into from
Nov 14, 2021

Conversation

finphie
Copy link
Owner

@finphie finphie commented Nov 14, 2021

closes #86

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1348 (21H1/May2021Update)
AMD Ryzen 7 5800U with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK=6.0.100
  [Host]           : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
  Runtime=.NET 6.0 : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT

Job=Runtime=.NET 6.0  Runtime=.NET 6.0  
Method Length Mean Error StdDev Allocated
IsAscii_Byte 4 3.184 ns 0.0420 ns 0.0393 ns -
IsAscii_ULong 4 1.585 ns 0.0567 ns 0.0502 ns -
IsAscii_Ulong4 4 3.119 ns 0.0132 ns 0.0123 ns -
IsAscii_Sse2 4 2.698 ns 0.0068 ns 0.0063 ns -
IsAscii_Avx2 4 3.092 ns 0.0122 ns 0.0114 ns -
IsAscii_Byte 16 17.689 ns 0.3891 ns 0.3639 ns -
IsAscii_ULong 16 2.714 ns 0.0227 ns 0.0212 ns -
IsAscii_Ulong4 16 3.122 ns 0.0230 ns 0.0215 ns -
IsAscii_Sse2 16 2.726 ns 0.0214 ns 0.0200 ns -
IsAscii_Avx2 16 3.104 ns 0.0117 ns 0.0103 ns -
IsAscii_Byte 100 119.267 ns 0.1369 ns 0.1281 ns -
IsAscii_ULong 100 8.948 ns 0.0509 ns 0.0476 ns -
IsAscii_Ulong4 100 7.444 ns 0.0253 ns 0.0237 ns -
IsAscii_Sse2 100 5.348 ns 0.0175 ns 0.0155 ns -
IsAscii_Avx2 100 4.596 ns 0.0604 ns 0.0565 ns -

SharpLab

; Core CLR 6.0.21.52210 on amd64

UnicodeUtility.IsAsciiAvx2(System.ReadOnlySpan`1<Byte>)
    L0000: vzeroupper
    L0003: mov rax, [rcx]
    L0006: mov edx, [rcx+8]
    L0009: xor ecx, ecx
    L000b: vxorps ymm0, ymm0, ymm0
    L0010: cmp edx, 0x20
    L0013: jl short L002e
    L0015: lea r8d, [rdx-0x20]
    L0019: nop [rax]
    L0020: vpor ymm0, ymm0, [rax+rcx]
    L0025: add rcx, 0x20
    L0029: cmp ecx, r8d
    L002c: jle short L0020
    L002e: xor r8d, r8d
    L0031: vpmovmskb r9d, ymm0
    L0035: mov r10d, edx
    L0038: sub r10d, ecx
    L003b: cmp r10d, 0x10
    L003f: jl short L0050
    L0041: lea r10, [rax+rcx]
    L0045: mov r8, [r10]
    L0048: or r8, [r10+8]
    L004c: add rcx, 0x10
    L0050: mov r10d, edx
    L0053: sub r10d, ecx
    L0056: cmp r10d, 8
    L005a: jl short L0064
    L005c: or r8, [rax+rcx]
    L0060: add rcx, 8
    L0064: mov r10d, edx
    L0067: sub r10d, ecx
    L006a: cmp r10d, 4
    L006e: jl short L007e
    L0070: mov r10d, [rax+rcx]
    L0074: or r10, r8
    L0077: mov r8, r10
    L007a: add rcx, 4
    L007e: mov r10d, edx
    L0081: sub r10d, ecx
    L0084: cmp r10d, 2
    L0088: jl short L0099
    L008a: movzx r10d, word ptr [rax+rcx]
    L008f: or r10, r8
    L0092: mov r8, r10
    L0095: add rcx, 2
    L0099: cmp ecx, edx
    L009b: jge short L00a7
    L009d: movzx eax, byte ptr [rax+rcx]
    L00a1: or rax, r8
    L00a4: mov r8, rax
    L00a7: mov eax, r9d
    L00aa: mov rdx, 0x8080808080808080
    L00b4: and rdx, r8
    L00b7: or rax, rdx
    L00ba: sete al
    L00bd: movzx eax, al
    L00c0: vzeroupper
    L00c3: ret

UnicodeUtility.IsAsciiSse2(System.ReadOnlySpan`1<Byte>)
    L0000: vzeroupper
    L0003: mov rax, [rcx]
    L0006: mov edx, [rcx+8]
    L0009: xor ecx, ecx
    L000b: vxorps xmm0, xmm0, xmm0
    L0010: cmp edx, 0x10
    L0013: jl short L002e
    L0015: lea r8d, [rdx-0x10]
    L0019: nop [rax]
    L0020: vpor xmm0, xmm0, [rax+rcx]
    L0025: add rcx, 0x10
    L0029: cmp ecx, r8d
    L002c: jle short L0020
    L002e: xor r8d, r8d
    L0031: vpmovmskb r9d, xmm0
    L0035: mov r10d, edx
    L0038: sub r10d, ecx
    L003b: cmp r10d, 8
    L003f: jl short L0049
    L0041: mov r8, [rax+rcx]
    L0045: add rcx, 8
    L0049: mov r10d, edx
    L004c: sub r10d, ecx
    L004f: cmp r10d, 4
    L0053: jl short L0060
    L0055: mov r10d, [rax+rcx]
    L0059: or r8, r10
    L005c: add rcx, 4
    L0060: mov r10d, edx
    L0063: sub r10d, ecx
    L0066: cmp r10d, 2
    L006a: jl short L007b
    L006c: movzx r10d, word ptr [rax+rcx]
    L0071: or r10, r8
    L0074: mov r8, r10
    L0077: add rcx, 2
    L007b: cmp ecx, edx
    L007d: jge short L0089
    L007f: movzx eax, byte ptr [rax+rcx]
    L0083: or rax, r8
    L0086: mov r8, rax
    L0089: mov eax, r9d
    L008c: mov rdx, 0x8080808080808080
    L0096: and rdx, r8
    L0099: or rax, rdx
    L009c: sete al
    L009f: movzx eax, al
    L00a2: ret

UnicodeUtility.IsAsciiUlong(System.ReadOnlySpan`1<Byte>)
    L0000: push rsi
    L0001: mov rax, [rcx]
    L0004: mov edx, [rcx+8]
    L0007: xor ecx, ecx
    L0009: xor r8d, r8d
    L000c: xor r9d, r9d
    L000f: xor r10d, r10d
    L0012: xor r11d, r11d
    L0015: cmp edx, 0x20
    L0018: jl short L003b
    L001a: lea esi, [rdx-0x20]
    L001d: nop [rax]
    L0020: or r8, [rax+rcx]
    L0024: or r9, [rax+rcx+8]
    L0029: or r10, [rax+rcx+0x10]
    L002e: or r11, [rax+rcx+0x18]
    L0033: add rcx, 0x20
    L0037: cmp ecx, esi
    L0039: jl short L0020
    L003b: mov esi, edx
    L003d: sub esi, ecx
    L003f: cmp esi, 0x10
    L0042: jl short L0053
    L0044: lea rsi, [rax+rcx]
    L0048: or r8, [rsi]
    L004b: or r8, [rsi+8]
    L004f: add rcx, 0x10
    L0053: mov esi, edx
    L0055: sub esi, ecx
    L0057: cmp esi, 8
    L005a: jl short L0064
    L005c: or r8, [rax+rcx]
    L0060: add rcx, 8
    L0064: mov esi, edx
    L0066: sub esi, ecx
    L0068: cmp esi, 4
    L006b: jl short L007a
    L006d: mov esi, [rax+rcx]
    L0070: or rsi, r8
    L0073: mov r8, rsi
    L0076: add rcx, 4
    L007a: mov esi, edx
    L007c: sub esi, ecx
    L007e: cmp esi, 2
    L0081: jl short L0091
    L0083: movzx esi, word ptr [rax+rcx]
    L0087: or rsi, r8
    L008a: mov r8, rsi
    L008d: add rcx, 2
    L0091: cmp ecx, edx
    L0093: jge short L009f
    L0095: movzx eax, byte ptr [rax+rcx]
    L0099: or rax, r8
    L009c: mov r8, rax
    L009f: mov rax, r8
    L00a2: or rax, r9
    L00a5: or rax, r10
    L00a8: or rax, r11
    L00ab: mov rdx, 0x8080808080808080
    L00b5: test rdx, rax
    L00b8: sete al
    L00bb: movzx eax, al
    L00be: pop rsi
    L00bf: ret

@github-actions github-actions bot added the enhancement New feature or request label Nov 14, 2021
@finphie finphie merged commit 6e08619 into main Nov 14, 2021
@finphie finphie deleted the enhancement/IsAscii branch November 14, 2021 09:43
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.

IsAsciiメソッド追加
1 participant