Skip to content

Instantly share code, notes, and snippets.

@mgiuca
Last active March 21, 2017 08:02
Show Gist options
  • Save mgiuca/567df7eab7d16ab64edaa903756165db to your computer and use it in GitHub Desktop.
Save mgiuca/567df7eab7d16ab64edaa903756165db to your computer and use it in GitHub Desktop.
Assembly code for iteration over StringPiece (by-reference)
# Source:
# void StringPieceFindTestRef(const std::vector<base::StringPiece>& vector) {
# for (const 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 %rbx
pushq %rax
movq (%rdi), %rbx
movq 8(%rdi), %r15
cmpq %r15, %rbx
je .LBB26_3
# BB#1:
leaq .L.str.17(%rip), %r14
.p2align 4, 0x90
.LBB26_2: # %for.body
movl $120, %esi
xorl %edx, %edx
movq %rbx, %rdi
callq _ZN4base8internal4findERKNS_16BasicStringPieceISsEEcm@PLT
movq %rax, %rcx
xorl %eax, %eax
movq %r14, %rdi
movq %rcx, %rsi
callq printf@PLT
addq $16, %rbx
cmpq %rbx, %r15
jne .LBB26_2
.LBB26_3: # %for.cond.cleanup
addq $8, %rsp
popq %rbx
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