Created
December 18, 2020 12:24
-
-
Save pervognsen/e1a5ba99ede4b630ed08df8ded87f27e to your computer and use it in GitHub Desktop.
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
// The buffer is terminated with "\n\0" | |
int count(const char *p) { | |
int n = 0; | |
while (*p) { | |
while (*p != '\n') p++; | |
n++; | |
while (*p == '\n') p++; | |
} | |
return n; | |
} |
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
.section __TEXT,__text,regular,pure_instructions | |
.build_version macos, 11, 0 | |
.globl _count ; -- Begin function count | |
.p2align 2 | |
_count: ; @count | |
.cfi_startproc | |
; %bb.0: ; %entry | |
ldrb w9, [x0] | |
cbz w9, LBB0_6 | |
; %bb.1: ; %while.cond1.preheader.preheader | |
mov w8, #0 | |
and w9, w9, #0xff | |
cmp w9, #10 ; =10 | |
b.eq LBB0_3 | |
LBB0_2: ; %while.cond1.while.cond1_crit_edge | |
; =>This Inner Loop Header: Depth=1 | |
ldrb w9, [x0, #1]! | |
cmp w9, #10 ; =10 | |
b.ne LBB0_2 | |
LBB0_3: ; %while.body8 | |
; =>This Inner Loop Header: Depth=1 | |
ldrb w9, [x0, #1]! | |
cmp w9, #10 ; =10 | |
b.eq LBB0_3 | |
; %bb.4: ; %while.cond.loopexit | |
; in Loop: Header=BB0_3 Depth=1 | |
add w8, w8, #1 ; =1 | |
cbz w9, LBB0_7 | |
; %bb.5: ; %while.cond1.preheader | |
; in Loop: Header=BB0_3 Depth=1 | |
and w9, w9, #0xff | |
cmp w9, #10 ; =10 | |
b.ne LBB0_2 | |
b LBB0_3 | |
LBB0_6: | |
mov w8, #0 | |
LBB0_7: ; %while.end11 | |
mov x0, x8 | |
ret | |
.cfi_endproc | |
; -- End function | |
.subsections_via_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment