diff options
author | Jens Arnold <amiconn@rockbox.org> | 2008-10-28 21:07:53 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2008-10-28 21:07:53 +0000 |
commit | 2c52dee83f5c796fe471e6fab15dea17a2f508ff (patch) | |
tree | 4f90ccd3c1d5785385fea9144e5011b1943acfcd /firmware/decompressor/sh_nrv2e_d8.S | |
parent | afd2f681d18e574442f8569f1a722d5d39d79b78 (diff) | |
download | rockbox-2c52dee83f5c796fe471e6fab15dea17a2f508ff.tar.gz rockbox-2c52dee83f5c796fe471e6fab15dea17a2f508ff.zip |
Self-extractor for on-disk firmware image: UCL decompressor in SH1 assembler - less than half the size of the compiled C function, and ~45% faster.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18904 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/decompressor/sh_nrv2e_d8.S')
-rw-r--r-- | firmware/decompressor/sh_nrv2e_d8.S | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/firmware/decompressor/sh_nrv2e_d8.S b/firmware/decompressor/sh_nrv2e_d8.S new file mode 100644 index 0000000000..c002911c0c --- /dev/null +++ b/firmware/decompressor/sh_nrv2e_d8.S | |||
@@ -0,0 +1,155 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Jens Arnold | ||
11 | * | ||
12 | * based on arm_nrv2e_d8.S -- ARM decompressor for NRV2E | ||
13 | * Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer | ||
14 | * Copyright (C) 1996-2008 Laszlo Molnar | ||
15 | * Copyright (C) 2000-2008 John F. Reiser | ||
16 | * | ||
17 | * This program is free software; you can redistribute it and/or | ||
18 | * modify it under the terms of the GNU General Public License | ||
19 | * as published by the Free Software Foundation; either version 2 | ||
20 | * of the License, or (at your option) any later version. | ||
21 | * | ||
22 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
23 | * KIND, either express or implied. | ||
24 | * | ||
25 | ****************************************************************************/ | ||
26 | |||
27 | #define src r4 | ||
28 | #define dst r5 | ||
29 | #define len r6 /* overlaps 'cnt' */ | ||
30 | #define cnt r6 /* overlaps 'len' while reading an offset */ | ||
31 | #define tmp r7 | ||
32 | |||
33 | #define off r0 /* must be r0 because of indexed addressing */ | ||
34 | #define bits r1 | ||
35 | #define bitmask r2 | ||
36 | #define wrnk r3 /* -0x500 -M2_MAX_OFFSET before "wrinkle" */ | ||
37 | |||
38 | |||
39 | #define GETBIT \ | ||
40 | tst bits, bitmask; \ | ||
41 | bf 1f; \ | ||
42 | bsr get1_n2e; \ | ||
43 | 1: \ | ||
44 | shll bits /* using the delay slot on purpose */ | ||
45 | |||
46 | #define getnextb(reg) GETBIT; rotcl reg | ||
47 | #define jnextb0 GETBIT; bf | ||
48 | #define jnextb1 GETBIT; bt | ||
49 | |||
50 | .section .icode,"ax",@progbits | ||
51 | .align 2 | ||
52 | .global _ucl_nrv2e_decompress_8 | ||
53 | .type _ucl_nrv2e_decompress_8,@function | ||
54 | |||
55 | /* src_len = ucl_nrv2e_decompress_8(const unsigned char *src, | ||
56 | * unsigned char *dst, | ||
57 | * unsigned long *dst_len) | ||
58 | */ | ||
59 | |||
60 | _ucl_nrv2e_decompress_8: | ||
61 | sts.l pr, @-r15 | ||
62 | mov #-1, off ! off = -1 initial condition | ||
63 | mov.l r6, @-r15 | ||
64 | mov #-5, wrnk | ||
65 | mov.l r5, @-r15 | ||
66 | shll8 wrnk ! nrv2e -M2_MAX_OFFSET | ||
67 | mov.l r4, @-r15 | ||
68 | mov #-1, bitmask | ||
69 | shlr bitmask ! 0x7fffffff for testing before shifting | ||
70 | bra top_n2e | ||
71 | not bitmask, bits ! refill next time (MSB must be set) | ||
72 | |||
73 | eof_n2e: | ||
74 | mov.l @r15+, r0 ! r0 = orig_src | ||
75 | mov.l @r15+, r1 ! r1 = orig_dst | ||
76 | sub r0, src | ||
77 | mov.l @r15+, r2 ! r2 = plen_dst | ||
78 | sub r1, dst | ||
79 | mov.l dst, @r2 | ||
80 | lds.l @r15+, pr | ||
81 | rts | ||
82 | mov src, r0 | ||
83 | |||
84 | .align 2 | ||
85 | get1_n2e: ! in: T bit set | ||
86 | mov.b @src+, bits ! SH1 sign-extends on load | ||
87 | rotcl bits ! LSB = T, T = MSB | ||
88 | shll16 bits | ||
89 | rts | ||
90 | shll8 bits | ||
91 | |||
92 | .align 2 | ||
93 | lit_n2e: | ||
94 | mov.b @src, tmp | ||
95 | add #1, src ! Need to fill the pipeline latency anyway | ||
96 | mov.b tmp, @dst | ||
97 | add #1, dst | ||
98 | top_n2e: | ||
99 | jnextb1 lit_n2e | ||
100 | bra getoff_n2e | ||
101 | mov #1, cnt | ||
102 | |||
103 | off_n2e: | ||
104 | add #-1, cnt | ||
105 | getnextb(cnt) | ||
106 | getoff_n2e: | ||
107 | getnextb(cnt) | ||
108 | jnextb0 off_n2e | ||
109 | |||
110 | mov cnt, tmp | ||
111 | mov #0, len ! cnt and len share a reg! | ||
112 | add #-3, tmp | ||
113 | cmp/pz tmp | ||
114 | bf offprev_n2e ! cnt was 2 | ||
115 | mov.b @src+, off ! low 7+1 bits | ||
116 | shll8 tmp | ||
117 | extu.b off, off | ||
118 | or tmp, off | ||
119 | not off, off ! off = ~off | ||
120 | tst off, off | ||
121 | bt eof_n2e | ||
122 | shar off | ||
123 | bt lenlast_n2e | ||
124 | bra lenmore_n2e | ||
125 | mov #1, len | ||
126 | |||
127 | offprev_n2e: | ||
128 | jnextb1 lenlast_n2e | ||
129 | mov #1, len | ||
130 | lenmore_n2e: | ||
131 | jnextb1 lenlast_n2e | ||
132 | len_n2e: | ||
133 | getnextb(len) | ||
134 | jnextb0 len_n2e | ||
135 | bra gotlen_n2e | ||
136 | add #6-2, len | ||
137 | |||
138 | lenlast_n2e: | ||
139 | getnextb(len) ! 0,1,2,3 | ||
140 | add #2, len | ||
141 | gotlen_n2e: | ||
142 | cmp/gt off, wrnk | ||
143 | movt tmp ! too far away, so minimum match length is 3 | ||
144 | add tmp, len | ||
145 | copy_n2e: | ||
146 | add #-1, len | ||
147 | mov.b @(off,dst), tmp | ||
148 | tst len, len | ||
149 | mov.b tmp, @dst | ||
150 | add #1, dst | ||
151 | bf copy_n2e | ||
152 | bra top_n2e | ||
153 | nop | ||
154 | |||
155 | .size ucl_nrv2e_decompress_8, .-ucl_nrv2e_decompress_8 | ||