Created
March 21, 2017 07:31
-
-
Save mgiuca/baf51bad7e3bb2d98b9965fda9e8982c to your computer and use it in GitHub Desktop.
Assembly code for iteration over StringPiece (by-value vs by-reference)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: | |
# void StringPieceIterTestVal(const std::vector<base::StringPiece>& vector) { | |
# for (base::StringPiece piece : vector) | |
# std::fwrite(piece.data(), piece.size(), 1, stdout); | |
# } | |
# | |
# void StringPieceIterTestRef(const std::vector<base::StringPiece>& vector) { | |
# for (const base::StringPiece& piece : vector) | |
# std::fwrite(piece.data(), piece.size(), 1, stdout); | |
# } | |
# (both functions generate same code) | |
# | |
# Compiler: clang++ Linux 64-bit | |
# BB#0: # %entry | |
pushq %rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
.cfi_def_cfa_register %rbp | |
pushq %r15 | |
pushq %r14 | |
pushq %rbx | |
pushq %rax | |
.cfi_offset %rbx, -40 | |
.cfi_offset %r14, -32 | |
.cfi_offset %r15, -24 | |
movq (%rdi), %rbx | |
movq 8(%rdi), %r14 | |
cmpq %r14, %rbx | |
je .LBB23_3 | |
# BB#1: | |
movq stdout@GOTPCREL(%rip), %r15 | |
.p2align 4, 0x90 | |
.LBB23_2: # %for.body | |
movq (%rbx), %rdi | |
movq 8(%rbx), %rsi | |
movq (%r15), %rcx | |
movl $1, %edx | |
callq fwrite@PLT | |
addq $16, %rbx | |
cmpq %r14, %rbx | |
jne .LBB23_2 | |
.LBB23_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