Created
June 14, 2024 01:48
-
-
Save vhxs/12db67d02a9ad9531f021b2f48dbc680 to your computer and use it in GitHub Desktop.
messing with popcnt
This file contains hidden or 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
#include <stdio.h> | |
int main(void) { | |
int input; | |
scanf("%d", &input); | |
printf("%s", __builtin_popcount(input)); | |
} |
This file contains hidden or 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, 14, 0 sdk_version 14, 2 | |
.globl _main ; -- Begin function main | |
.p2align 2 | |
_main: ; @main | |
.cfi_startproc | |
; %bb.0: | |
sub sp, sp, #32 | |
.cfi_def_cfa_offset 32 | |
stp x29, x30, [sp, #16] ; 16-byte Folded Spill | |
add x29, sp, #16 | |
.cfi_def_cfa w29, 16 | |
.cfi_offset w30, -8 | |
.cfi_offset w29, -16 | |
mov x9, sp | |
sub x8, x29, #4 | |
str x8, [x9] | |
adrp x0, l_.str@PAGE | |
add x0, x0, l_.str@PAGEOFF | |
bl _scanf | |
ldur w8, [x29, #-4] | |
; kill: def $x8 killed $w8 | |
fmov d0, x8 | |
cnt.8b v0, v0 | |
uaddlv.8b h1, v0 | |
; implicit-def: $q0 | |
fmov s0, s1 | |
; kill: def $s0 killed $s0 killed $q0 | |
mov x9, sp | |
fmov w10, s0 | |
; implicit-def: $x8 | |
mov x8, x10 | |
str x8, [x9] | |
adrp x0, l_.str.1@PAGE | |
add x0, x0, l_.str.1@PAGEOFF | |
bl _printf | |
mov w0, #0 | |
ldp x29, x30, [sp, #16] ; 16-byte Folded Reload | |
add sp, sp, #32 | |
ret | |
.cfi_endproc | |
; -- End function | |
.section __TEXT,__cstring,cstring_literals | |
l_.str: ; @.str | |
.asciz "%d" | |
l_.str.1: ; @.str.1 | |
.asciz "%s" | |
.subsections_via_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment