Skip to content

Instantly share code, notes, and snippets.

@mgiuca
Created March 21, 2017 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgiuca/fb081ed2a9442ce72db52fb3e87cfe86 to your computer and use it in GitHub Desktop.
Save mgiuca/fb081ed2a9442ce72db52fb3e87cfe86 to your computer and use it in GitHub Desktop.
Assembly code for iteration over StringPiece (by-value)
# Source:
# void StringPieceFindTestVal(const std::vector<base::StringPiece>& vector) {
# for (base::StringPiece piece : vector)
# printf("%zu\n", piece.find('x'));
# }
#
# Compiler: clang++ Linux 64-bit
# BB#0: # %entry
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $16, %rsp
movq (%rdi), %rbx
movq 8(%rdi), %r12
cmpq %r12, %rbx
je .LBB25_3
# BB#1:
leaq -48(%rbp), %r14
leaq .L.str.17(%rip), %r15
.p2align 4, 0x90
.LBB25_2: # %for.body
movups (%rbx), %xmm0
movaps %xmm0, -48(%rbp)
movl $120, %esi
xorl %edx, %edx
movq %r14, %rdi
callq _ZN4base8internal4findERKNS_16BasicStringPieceISsEEcm@PLT
movq %rax, %rcx
xorl %eax, %eax
movq %r15, %rdi
movq %rcx, %rsi
callq printf@PLT
addq $16, %rbx
cmpq %rbx, %r12
jne .LBB25_2
.LBB25_3: # %for.cond.cleanup
addq $16, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment