invert was_match -> 188 bytes

This commit is contained in:
2022-09-18 15:58:31 +02:00
parent 434769b591
commit 5bc3f88564
2 changed files with 17 additions and 20 deletions

View File

@@ -6,9 +6,9 @@ test_riscv64: build/unpack_riscv64
qemu-riscv64 $< test_data.upk /tmp/out.bin qemu-riscv64 $< test_data.upk /tmp/out.bin
cmp test_data.bin /tmp/out.bin cmp test_data.bin /tmp/out.bin
build/unpack_armv6m: ../c_unpacker/main.c ../c_unpacker/unpack.c build/unpack_armv6m: ../c_unpacker/main.c unpack_armv6m.S
mkdir -p build mkdir -p build
arm-linux-gnueabihf-gcc -g -static -o $@ $? arm-linux-gnueabihf-gcc -g -static -o $@ $^
test_armv6m: build/unpack_armv6m test_armv6m: build/unpack_armv6m
qemu-arm $< test_data.upk /tmp/out.bin qemu-arm $< test_data.upk /tmp/out.bin

View File

@@ -39,8 +39,7 @@ upkr_unpack:
// r6 = 1 // r6 = 1
lsls r5, r6, #8 lsls r5, r6, #8
cmp r4, #0 cmp r4, #0
mov r4, r6 // = 1 beq 1f
bne 1f
bl upkr_decode_bit bl upkr_decode_bit
beq 2f beq 2f
@@ -49,8 +48,7 @@ upkr_unpack:
adds r5, r5, #1 adds r5, r5, #1
bl upkr_decode_length bl upkr_decode_length
subs r5, r5, #1 subs r5, r5, #1
// r4 = 1 subs r3, r6, r4
subs r3, r4, r6
beq .Lend beq .Lend
2: 2:
@@ -60,19 +58,18 @@ upkr_unpack:
ldrb r5, [r0, r3] ldrb r5, [r0, r3]
strb r5, [r0] strb r5, [r0]
adds r0, r0, #1 adds r0, r0, #1
subs r6, r6, #1 subs r4, r4, #1
bne .Lcopy_loop bne .Lcopy_loop
b .Lloop b .Lloop
.Ldata: .Ldata:
movs r4, #0
movs r5, #1 movs r5, #1
.Ldata_loop: .Ldata_loop:
bl upkr_decode_bit bl upkr_decode_bit
lsls r5, r5, #1 lsls r5, r5, #1
adds r5, r5, r6 adds r5, r5, r6
lsrs r6, r5, #8 lsrs r4, r5, #8
beq .Ldata_loop beq .Ldata_loop
strb r5, [r0] strb r5, [r0]
@@ -87,15 +84,15 @@ upkr_unpack:
// r0 .. length tmp (saved) // r0 .. length tmp (saved)
// r1 .. // r1 ..
// r2 .. // r2 ..
// r3 .. // r3 .. bit pos (saved)
// r4 .. bit pos (saved) // r4 .. length (returned)
// r5 .. content index (saved) // r5 .. content index (saved)
// r6 .. length (returned) // r6 ..
// r7 .. // r7 ..
upkr_decode_length: upkr_decode_length:
push { r0, r4, r5, lr } push { r0, r3, r5, r6, lr }
movs r4, #0 movs r3, #0
movs r0, #0 movs r0, #0
.Lbit_loop: .Lbit_loop:
bl upkr_decode_bit bl upkr_decode_bit
@@ -104,16 +101,16 @@ upkr_decode_length:
adds r5, r5, #1 adds r5, r5, #1
bl upkr_decode_bit bl upkr_decode_bit
adds r5, r5, #1 adds r5, r5, #1
lsls r6, r6, r4 lsls r6, r6, r3
adds r4, r4, #1 adds r3, r3, #1
orrs r0, r0, r6 orrs r0, r0, r6
b .Lbit_loop b .Lbit_loop
1: 1:
movs r6, #1 movs r4, #1
lsls r6, r6, r4 lsls r4, r4, r3
orrs r6, r6, r0 orrs r4, r4, r0
pop { r0, r4, r5, pc } pop { r0, r3, r5, r6, pc }
.type upkr_decode_bit, %function .type upkr_decode_bit, %function
// r0 .. tmp / prob (saved) // r0 .. tmp / prob (saved)