sysy-data/hidden_functional_c/asm/16_k_smallest.s

335 lines
4.9 KiB
ArmAsm
Raw Permalink Normal View History

2024-06-14 13:34:46 +08:00
.text
.attribute 4, 16
.attribute 5, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
.file "16_k_smallest.sy"
.globl swap
.p2align 1
.type swap,@function
swap:
lui a2, %hi(array)
addi a2, a2, %lo(array)
slli a0, a0, 2
add a0, a0, a2
slli a1, a1, 2
add a1, a1, a2
lw a2, 0(a1)
lw a3, 0(a0)
sw a2, 0(a0)
sw a3, 0(a1)
ret
.Lfunc_end0:
.size swap, .Lfunc_end0-swap
.globl findPivot
.p2align 1
.type findPivot,@function
findPivot:
lui a2, %hi(array)
addi a7, a2, %lo(array)
slli a2, a1, 2
add a6, a2, a7
lw t0, 0(a6)
bge a0, a1, .LBB1_6
slli a2, a0, 2
add a5, a2, a7
sub a1, a1, a0
j .LBB1_3
.LBB1_2:
addi a1, a1, -1
addi a5, a5, 4
beqz a1, .LBB1_5
.LBB1_3:
lw a2, 0(a5)
blt t0, a2, .LBB1_2
sext.w a3, a0
slli a3, a3, 2
add a3, a3, a7
lw a4, 0(a3)
sw a4, 0(a5)
sw a2, 0(a3)
addiw a0, a0, 1
j .LBB1_2
.LBB1_5:
lw t0, 0(a6)
.LBB1_6:
sext.w a0, a0
slli a1, a0, 2
add a1, a1, a7
lw a2, 0(a1)
sw t0, 0(a1)
sw a2, 0(a6)
ret
.Lfunc_end1:
.size findPivot, .Lfunc_end1-findPivot
.globl findSmallest
.p2align 1
.type findSmallest,@function
findSmallest:
addi sp, sp, -32
sd ra, 24(sp)
sd s0, 16(sp)
sd s1, 8(sp)
beq a0, a1, .LBB2_17
lui a3, %hi(array)
addi t4, a3, %lo(array)
.LBB2_2:
sext.w t0, a0
neg a6, t0
slli a3, t0, 2
add a7, a3, t4
.LBB2_3:
sext.w t2, a1
slli a3, t2, 2
add t3, a3, t4
lw t5, 0(t3)
sext.w t1, a0
bge t1, t2, .LBB2_8
add a3, a6, t2
mv a4, a7
mv t6, a0
j .LBB2_6
.LBB2_5:
addi a3, a3, -1
addi a4, a4, 4
beqz a3, .LBB2_9
.LBB2_6:
lw s1, 0(a4)
blt t5, s1, .LBB2_5
sext.w s0, t6
slli s0, s0, 2
add s0, s0, t4
lw a5, 0(s0)
sw a5, 0(a4)
sw s1, 0(s0)
addiw t6, t6, 1
j .LBB2_5
.LBB2_8:
mv a3, t0
mv t6, a0
j .LBB2_10
.LBB2_9:
lw t5, 0(t3)
sext.w a3, t6
.LBB2_10:
slli a3, a3, 2
add a3, a3, t4
lw a4, 0(a3)
sw t5, 0(a3)
sext.w a3, t6
sw a4, 0(t3)
beq a3, a2, .LBB2_14
bge a2, a3, .LBB2_13
addiw a1, t6, -1
bne t1, a1, .LBB2_3
j .LBB2_17
.LBB2_13:
addiw a0, t6, 1
bne a0, t2, .LBB2_2
j .LBB2_17
.LBB2_14:
blez a2, .LBB2_17
lui a0, %hi(array)
addi s0, a0, %lo(array)
slli a0, a2, 32
srli s1, a0, 32
.LBB2_16:
lw a0, 0(s0)
call putint
li a0, 32
call putch
addi s1, s1, -1
addi s0, s0, 4
bnez s1, .LBB2_16
.LBB2_17:
ld ra, 24(sp)
ld s0, 16(sp)
ld s1, 8(sp)
addi sp, sp, 32
ret
.Lfunc_end2:
.size findSmallest, .Lfunc_end2-findSmallest
.globl main
.p2align 1
.type main,@function
main:
addi sp, sp, -48
sd ra, 40(sp)
sd s0, 32(sp)
sd s1, 24(sp)
sd s2, 16(sp)
sd s3, 8(sp)
call getint
mv s3, a0
call getint
mv s2, a0
blez s3, .LBB3_4
lui a0, %hi(array)
addi s0, a0, %lo(array)
slli a0, s3, 32
srli s1, a0, 32
.LBB3_2:
call getint
sw a0, 0(s0)
addi s1, s1, -1
addi s0, s0, 4
bnez s1, .LBB3_2
addiw t2, s3, -1
bnez t2, .LBB3_5
j .LBB3_21
.LBB3_4:
addiw t2, s3, -1
.LBB3_5:
li t0, 0
lui a1, %hi(array)
addi a1, a1, %lo(array)
.LBB3_6:
neg a6, t0
slli a2, t0, 2
add a7, a2, a1
.LBB3_7:
slli a2, t2, 2
add t1, a2, a1
lw a3, 0(t1)
bge t0, t2, .LBB3_12
add a4, a6, t2
mv s0, a7
mv a2, t0
j .LBB3_10
.LBB3_9:
addi a4, a4, -1
addi s0, s0, 4
beqz a4, .LBB3_13
.LBB3_10:
lw s1, 0(s0)
blt a3, s1, .LBB3_9
slli a5, a2, 2
add a5, a5, a1
lw a0, 0(a5)
sw a0, 0(s0)
sw s1, 0(a5)
addiw a2, a2, 1
j .LBB3_9
.LBB3_12:
mv a2, t0
j .LBB3_14
.LBB3_13:
lw a3, 0(t1)
.LBB3_14:
slli a0, a2, 2
add a0, a0, a1
lw a4, 0(a0)
sw a3, 0(a0)
sw a4, 0(t1)
beq a2, s2, .LBB3_18
bge s2, a2, .LBB3_17
addiw t2, a2, -1
bne t0, t2, .LBB3_7
j .LBB3_21
.LBB3_17:
addiw t0, a2, 1
bne t0, t2, .LBB3_6
j .LBB3_21
.LBB3_18:
blez s2, .LBB3_21
lui a0, %hi(array)
addi s0, a0, %lo(array)
slli a0, s2, 32
srli s1, a0, 32
.LBB3_20:
lw a0, 0(s0)
call putint
li a0, 32
call putch
addi s1, s1, -1
addi s0, s0, 4
bnez s1, .LBB3_20
.LBB3_21:
li a0, 0
ld ra, 40(sp)
ld s0, 32(sp)
ld s1, 24(sp)
ld s2, 16(sp)
ld s3, 8(sp)
addi sp, sp, 48
ret
.Lfunc_end3:
.size main, .Lfunc_end3-main
.type array,@object
.bss
.globl array
.p2align 2
array:
.zero 4000
.size array, 4000
.type _sysy_start,@object
.globl _sysy_start
.p2align 3
_sysy_start:
.zero 16
.size _sysy_start, 16
.type _sysy_end,@object
.globl _sysy_end
.p2align 3
_sysy_end:
.zero 16
.size _sysy_end, 16
.type _sysy_l1,@object
.globl _sysy_l1
.p2align 2
_sysy_l1:
.zero 4096
.size _sysy_l1, 4096
.type _sysy_l2,@object
.globl _sysy_l2
.p2align 2
_sysy_l2:
.zero 4096
.size _sysy_l2, 4096
.type _sysy_h,@object
.globl _sysy_h
.p2align 2
_sysy_h:
.zero 4096
.size _sysy_h, 4096
.type _sysy_m,@object
.globl _sysy_m
.p2align 2
_sysy_m:
.zero 4096
.size _sysy_m, 4096
.type _sysy_s,@object
.globl _sysy_s
.p2align 2
_sysy_s:
.zero 4096
.size _sysy_s, 4096
.type _sysy_us,@object
.globl _sysy_us
.p2align 2
_sysy_us:
.zero 4096
.size _sysy_us, 4096
.type _sysy_idx,@object
.section .sbss,"aw",@nobits
.globl _sysy_idx
.p2align 2
_sysy_idx:
.word 0
.size _sysy_idx, 4
.ident "Debian clang version 14.0.6"
.section ".note.GNU-stack","",@progbits
.addrsig