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

VM machine code for list[someInt & 0xff] seems to have meaningless stuff #56828

Open
jensjoha opened this issue Oct 1, 2024 · 1 comment
Open
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P3 A lower priority bug or feature request triaged Issue has been triaged by sub team type-performance Issue relates to performance or code size

Comments

@jensjoha
Copy link
Contributor

jensjoha commented Oct 1, 2024

Annotating SimpleToken.type with @pragma("vm:never-inline") so I can easily get the disassembly I can extract this code from an AOT build:

102678  ParallelMove rdx <- C, rcx <- C
   0x000000000024bcf0 <+0>:     mov    0x3f97(%r15),%rdx
   0x000000000024bcf7 <+7>:     mov    $0xff,%ecx

102679  v4 <- LoadField(v2 . _typeAndOffset@39236933) [-9223372036854775808, 9223372036854775807] int64
   0x000000000024bcfc <+12>:    mov    0x1f(%rdi),%rsi

102680  ParallelMove rsi <- rsi
102681  v20 <- IntConverter(int64->uint32[tr], v4) uint32
   0x000000000024bd00 <+16>:    mov    %esi,%esi

102682  ParallelMove rsi <- rsi
102683  v6 <- BinaryUint32Op(& [tr], v20 T{int}, v22 T{_Smi}) [0, 255] uint32
   0x000000000024bd02 <+18>:    and    %ecx,%esi

102684  ParallelMove rsi <- rsi
102685  v21 <- IntConverter(uint32->int64, v6) int64
   0x000000000024bd04 <+20>:    mov    %esi,%esi

102686  ParallelMove rax <- C, rbx <- rsi
   0x000000000024bd06 <+22>:    mov    %rsi,%rbx
   0x000000000024bd09 <+25>:    mov    $0x9b,%eax

102687  GenericCheckBound:14(v16 T{_Smi}, v21 T{_Smi}) [-9223372036854775808, 9223372036854775807] int64
   0x000000000024bd0e <+30>:    cmp    %rax,%rbx
   0x000000000024bd11 <+33>:    jae    0x24bd1d <SimpleToken.type+45>

102688  v17 <- LoadIndexed:14([_List] v3, v21 T{_Smi}) T{TokenType}
   0x000000000024bd17 <+39>:    mov    0x17(%rdx,%rsi,8),%rax

102689  ParallelMove rax <- rax
102690  DartReturn:16(v17 T{TokenType})
   0x000000000024bd1c <+44>:    ret

102691  slow path check bound operation
102692  PrologueOffset = 45
   0x000000000024bd1d <+45>:    push   %rbp
   0x000000000024bd1e <+46>:    mov    %rsp,%rbp
   0x000000000024bd21 <+49>:    call   0x6de888 <stub _iso_stub_RangeErrorSharedWithoutFPURegsStub>
End of assembler dump.

which seems massive. Wouldn't something like this do the same thing?

   0x000000000024bcf0 <+0>:     mov    0x3f97(%r15),%rdx
   0x000000000024bcfc <+12>:    mov    0x1f(%rdi),%rsi
   0x000000000024bd00 <+16>:    mov    %sil,%sil
   0x000000000024bd0e <+30>:    cmp    $0x9b,%rsi
   0x000000000024bd11 <+33>:    jae    0x24bd1d <SimpleToken.type+45>
   0x000000000024bd17 <+39>:    mov    0x17(%rdx,%rsi,8),%rax
   0x000000000024bd1c <+44>:    ret

102691  slow path check bound operation
102692  PrologueOffset = 45
   [whatever to make stuff go into the right registries to make the stub call work]
   0x000000000024bd21 <+49>:    call   0x6de888 <stub _iso_stub_RangeErrorSharedWithoutFPURegsStub>
End of assembler dump.

(Helper for at least myself: https://cs.brown.edu/courses/cs033/docs/guides/x64_cheatsheet.pdf)

Maybe someone who actually knows something about the VM and assembly and stuff might come up with something better.

/cc @mraleph

@dart-github-bot
Copy link
Collaborator

Summary: The user observes that the VM generates complex machine code for a simple list access operation with a bitwise AND. They believe the code could be simplified, potentially leading to performance improvements.

@dart-github-bot dart-github-bot added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 1, 2024
@lrhn lrhn added type-performance Issue relates to performance or code size and removed type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Oct 1, 2024
@a-siva a-siva added P3 A lower priority bug or feature request triaged Issue has been triaged by sub team labels Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P3 A lower priority bug or feature request triaged Issue has been triaged by sub team type-performance Issue relates to performance or code size
Projects
None yet
Development

No branches or pull requests

4 participants