Rev 1755 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1755 | Rev 1789 | ||
---|---|---|---|
1 | 1 # 1 "isqrt.S" |
1 | 1 # 1 "isqrt.S" |
2 | 2 # 1 "<built-in>" |
- | |
3 | 1 ;-----------------------------------------------------------------------------; |
2 | 1 ;-----------------------------------------------------------------------------; |
4 | 0 |
3 | 0 |
5 | 0 |
4 | 0 |
6 | 2 ;-----------------------------------------------------------------------------; |
5 | 2 ;-----------------------------------------------------------------------------; |
7 | 3 ; Fast integer squareroot routines for avr-gcc project (C)ChaN, 2008 |
6 | 3 ; Fast integer squareroot routines for avr-gcc project (C)ChaN, 2008 |
8 | 4 ; http://elm-chan.org/docs/avrlib/sqrt32.S |
7 | 4 ; http://elm-chan.org/docs/avrlib/sqrt32.S |
9 | 5 ;-----------------------------------------------------------------------------; |
8 | 5 ;-----------------------------------------------------------------------------; |
10 | 6 ; uint16_t isqrt32 (uint32_t n); |
9 | 6 ; uint16_t isqrt32 (uint32_t n); |
11 | 7 ; uint8_t isqrt16 (uint16_t n); |
10 | 7 ; uint8_t isqrt16 (uint16_t n); |
12 | 8 ; uint16_t ihypot (int16_t x, int16_t y); |
11 | 8 ; uint16_t ihypot (int16_t x, int16_t y); |
13 | 9 |
12 | 9 |
14 | 10 ;-----------------------------------------------------------------------------: |
13 | 10 ;-----------------------------------------------------------------------------: |
15 | 11 ; 32bit integer squareroot |
14 | 11 ; 32bit integer squareroot |
16 | 12 ;-----------------------------------------------------------------------------; |
15 | 12 ;-----------------------------------------------------------------------------; |
17 | 13 ; uint16_t isqrt32 ( |
16 | 13 ; uint16_t isqrt32 ( |
18 | 14 ; uint32_t n |
17 | 14 ; uint32_t n |
19 | 15 ; ); |
18 | 15 ; ); |
20 | 16 ; |
19 | 16 ; |
21 | 17 ; Return Value: |
20 | 17 ; Return Value: |
22 | 18 ; Squareroot of n. |
21 | 18 ; Squareroot of n. |
23 | 19 ; |
22 | 19 ; |
24 | 20 ; Size = 53 words |
23 | 20 ; Size = 53 words |
25 | 21 ; Clock = 532..548 cycles |
24 | 21 ; Clock = 532..548 cycles |
26 | 22 ; Stack = 0 byte |
25 | 22 ; Stack = 0 byte |
27 | 23 |
26 | 23 |
28 | 24 .global isqrt32 |
27 | 24 .global isqrt32 |
29 | 25 .func isqrt32 |
28 | 25 .func isqrt32 |
30 | 26 |
29 | 26 |
31 | 27:isqrt.S **** isqrt32: |
30 | 27:isqrt.S **** isqrt32: |
32 | 28:isqrt.S **** clr r0 |
31 | 28:isqrt.S **** clr r0 |
33 | 29:isqrt.S **** clr r18 |
32 | 29:isqrt.S **** clr r18 |
34 | 30:isqrt.S **** clr r19 |
33 | 30:isqrt.S **** clr r19 |
35 | 31:isqrt.S **** clr r20 |
34 | 31:isqrt.S **** clr r20 |
36 | 32:isqrt.S **** ldi r21, 1 |
35 | 32:isqrt.S **** ldi r21, 1 |
37 | 33:isqrt.S **** clr r27 |
36 | 33:isqrt.S **** clr r27 |
38 | 34:isqrt.S **** clr r30 |
37 | 34:isqrt.S **** clr r30 |
39 | 35:isqrt.S **** clr r31 |
38 | 35:isqrt.S **** clr r31 |
40 | 36:isqrt.S **** ldi r26, 16 |
39 | 36:isqrt.S **** ldi r26, 16 |
41 | 37:isqrt.S **** 1: lsl r22 |
40 | 37:isqrt.S **** 1: lsl r22 |
42 | 38:isqrt.S **** rol r23 |
41 | 38:isqrt.S **** rol r23 |
43 | 39:isqrt.S **** rol r24 |
42 | 39:isqrt.S **** rol r24 |
44 | 40:isqrt.S **** rol r25 |
43 | 40:isqrt.S **** rol r25 |
45 | 41:isqrt.S **** rol r0 |
44 | 41:isqrt.S **** rol r0 |
46 | 42:isqrt.S **** rol r18 |
45 | 42:isqrt.S **** rol r18 |
47 | 43:isqrt.S **** rol r19 |
46 | 43:isqrt.S **** rol r19 |
48 | 44:isqrt.S **** rol r20 |
47 | 44:isqrt.S **** rol r20 |
49 | 45:isqrt.S **** lsl r22 |
48 | 45:isqrt.S **** lsl r22 |
50 | 46:isqrt.S **** rol r23 |
49 | 46:isqrt.S **** rol r23 |
51 | 47:isqrt.S **** rol r24 |
50 | 47:isqrt.S **** rol r24 |
52 | 48:isqrt.S **** rol r25 |
51 | 48:isqrt.S **** rol r25 |
53 | 49:isqrt.S **** rol r0 |
52 | 49:isqrt.S **** rol r0 |
54 | 50:isqrt.S **** rol r18 |
53 | 50:isqrt.S **** rol r18 |
55 | 51:isqrt.S **** rol r19 |
54 | 51:isqrt.S **** rol r19 |
56 | 52:isqrt.S **** rol r20 |
55 | 52:isqrt.S **** rol r20 |
57 | 53:isqrt.S **** brpl 2f |
56 | 53:isqrt.S **** brpl 2f |
58 | 54:isqrt.S **** add r0, r21 |
57 | 54:isqrt.S **** add r0, r21 |
59 | 55:isqrt.S **** adc r18, r27 |
58 | 55:isqrt.S **** adc r18, r27 |
60 | 56:isqrt.S **** adc r19, r30 |
59 | 56:isqrt.S **** adc r19, r30 |
61 | 57:isqrt.S **** adc r20, r31 |
60 | 57:isqrt.S **** adc r20, r31 |
62 | 58:isqrt.S **** rjmp 3f |
61 | 58:isqrt.S **** rjmp 3f |
63 | 59:isqrt.S **** 2: sub r0, r21 |
62 | 59:isqrt.S **** 2: sub r0, r21 |
64 | 60:isqrt.S **** sbc r18, r27 |
63 | 60:isqrt.S **** sbc r18, r27 |
65 | 61:isqrt.S **** sbc r19, r30 |
64 | 61:isqrt.S **** sbc r19, r30 |
66 | 62:isqrt.S **** sbc r20, r31 |
65 | 62:isqrt.S **** sbc r20, r31 |
67 | 63:isqrt.S **** 3: lsl r21 |
66 | 63:isqrt.S **** 3: lsl r21 |
68 | 64:isqrt.S **** rol r27 |
67 | 64:isqrt.S **** rol r27 |
69 | 65:isqrt.S **** rol r30 |
68 | 65:isqrt.S **** rol r30 |
70 | 66:isqrt.S **** andi r21, 0b11111000 |
69 | 66:isqrt.S **** andi r21, 0b11111000 |
71 | 67:isqrt.S **** ori r21, 0b00000101 |
70 | 67:isqrt.S **** ori r21, 0b00000101 |
72 | 68:isqrt.S **** sbrc r20, 7 |
71 | 68:isqrt.S **** sbrc r20, 7 |
73 | 69:isqrt.S **** subi r21, 2 |
72 | 69:isqrt.S **** subi r21, 2 |
74 | 70:isqrt.S **** dec r26 |
73 | 70:isqrt.S **** dec r26 |
75 | 71:isqrt.S **** brne 1b |
74 | 71:isqrt.S **** brne 1b |
76 | 72:isqrt.S **** lsr r30 |
75 | 72:isqrt.S **** lsr r30 |
77 | 73:isqrt.S **** ror r27 |
76 | 73:isqrt.S **** ror r27 |
78 | 74:isqrt.S **** ror r21 |
77 | 74:isqrt.S **** ror r21 |
79 | 75:isqrt.S **** lsr r30 |
78 | 75:isqrt.S **** lsr r30 |
80 | 76:isqrt.S **** ror r27 |
79 | 76:isqrt.S **** ror r27 |
81 | 77:isqrt.S **** ror r21 |
80 | 77:isqrt.S **** ror r21 |
82 | 78:isqrt.S **** mov r24, r21 |
81 | 78:isqrt.S **** mov r24, r21 |
83 | 79:isqrt.S **** mov r25, r27 |
82 | 79:isqrt.S **** mov r25, r27 |
84 | 80 ret |
83 | 80 ret |
85 | 81 .endfunc |
84 | 81 .endfunc |
86 | 82 |
85 | 82 |
87 | 83 |
86 | 83 |
88 | 84 |
87 | 84 |
89 | 85 ;-----------------------------------------------------------------------------: |
88 | 85 ;-----------------------------------------------------------------------------: |
90 | 86 ; 16bit integer squareroot |
89 | 86 ; 16bit integer squareroot |
91 | 87 ;-----------------------------------------------------------------------------; |
90 | 87 ;-----------------------------------------------------------------------------; |
92 | 88 ; uint8_t isqrt16 ( |
91 | 88 ; uint8_t isqrt16 ( |
93 | 89 ; uint16_t n |
92 | 89 ; uint16_t n |
94 | 90 ; ); |
93 | 90 ; ); |
95 | 91 ; |
94 | 91 ; |
96 | 92 ; Return Value: |
95 | 92 ; Return Value: |
97 | 93 ; Squareroot of n. |
96 | 93 ; Squareroot of n. |
98 | 94 ; |
97 | 94 ; |
99 | 95 ; Size = 33 words |
98 | 95 ; Size = 33 words |
100 | 96 ; Clock = 181..189 cycles |
99 | 96 ; Clock = 181..189 cycles |
101 | 97 ; Stack = 0 byte |
100 | 97 ; Stack = 0 byte |
102 | 98 |
101 | 98 |
103 | 99 .global isqrt16 |
102 | 99 .global isqrt16 |
104 | 100 .func isqrt16 |
103 | 100 .func isqrt16 |
105 | 101 |
104 | 101 |
106 | 102:isqrt.S **** isqrt16: |
105 | 102:isqrt.S **** isqrt16: |
107 | 103:isqrt.S **** clr r18 |
106 | 103:isqrt.S **** clr r18 |
108 | 104:isqrt.S **** clr r19 |
107 | 104:isqrt.S **** clr r19 |
109 | 105:isqrt.S **** ldi r20, 1 |
108 | 105:isqrt.S **** ldi r20, 1 |
110 | 106:isqrt.S **** clr r21 |
109 | 106:isqrt.S **** clr r21 |
111 | 107:isqrt.S **** ldi r22, 8 |
110 | 107:isqrt.S **** ldi r22, 8 |
112 | 108:isqrt.S **** 1: lsl r24 |
111 | 108:isqrt.S **** 1: lsl r24 |
113 | 109:isqrt.S **** rol r25 |
112 | 109:isqrt.S **** rol r25 |
114 | 110:isqrt.S **** rol r18 |
113 | 110:isqrt.S **** rol r18 |
115 | 111:isqrt.S **** rol r19 |
114 | 111:isqrt.S **** rol r19 |
116 | 112:isqrt.S **** lsl r24 |
115 | 112:isqrt.S **** lsl r24 |
117 | 113:isqrt.S **** rol r25 |
116 | 113:isqrt.S **** rol r25 |
118 | 114:isqrt.S **** rol r18 |
117 | 114:isqrt.S **** rol r18 |
119 | 115:isqrt.S **** rol r19 |
118 | 115:isqrt.S **** rol r19 |
120 | 116:isqrt.S **** brpl 2f |
119 | 116:isqrt.S **** brpl 2f |
121 | 117:isqrt.S **** add r18, r20 |
120 | 117:isqrt.S **** add r18, r20 |
122 | 118:isqrt.S **** adc r19, r21 |
121 | 118:isqrt.S **** adc r19, r21 |
123 | 119:isqrt.S **** rjmp 3f |
122 | 119:isqrt.S **** rjmp 3f |
124 | 120:isqrt.S **** 2: sub r18, r20 |
123 | 120:isqrt.S **** 2: sub r18, r20 |
125 | 121:isqrt.S **** sbc r19, r21 |
124 | 121:isqrt.S **** sbc r19, r21 |
126 | 122:isqrt.S **** 3: lsl r20 |
125 | 122:isqrt.S **** 3: lsl r20 |
127 | 123:isqrt.S **** rol r21 |
126 | 123:isqrt.S **** rol r21 |
128 | 124:isqrt.S **** andi r20, 0b11111000 |
127 | 124:isqrt.S **** andi r20, 0b11111000 |
129 | 125:isqrt.S **** ori r20, 0b00000101 |
128 | 125:isqrt.S **** ori r20, 0b00000101 |
130 | 126:isqrt.S **** sbrc r19, 7 |
129 | 126:isqrt.S **** sbrc r19, 7 |
131 | 127:isqrt.S **** subi r20, 2 |
130 | 127:isqrt.S **** subi r20, 2 |
132 | 128:isqrt.S **** dec r22 |
131 | 128:isqrt.S **** dec r22 |
133 | 129:isqrt.S **** brne 1b |
132 | 129:isqrt.S **** brne 1b |
134 | 130:isqrt.S **** lsr r21 |
133 | 130:isqrt.S **** lsr r21 |
135 | 131:isqrt.S **** ror r20 |
134 | 131:isqrt.S **** ror r20 |
136 | 132:isqrt.S **** lsr r21 |
135 | 132:isqrt.S **** lsr r21 |
137 | 133:isqrt.S **** ror r20 |
136 | 133:isqrt.S **** ror r20 |
138 | 134:isqrt.S **** mov r24, r20 |
137 | 134:isqrt.S **** mov r24, r20 |
139 | 135 ret |
138 | 135 ret |
140 | 136 .endfunc |
139 | 136 .endfunc |
141 | 137 |
140 | 137 |
142 | 138 |
141 | 138 |
143 | 139 |
142 | 139 |
144 | 140 ;-----------------------------------------------------------------------------: |
143 | 140 ;-----------------------------------------------------------------------------: |
145 | 141 ; 16bit integer hypot (megaAVR is required) |
144 | 141 ; 16bit integer hypot (megaAVR is required) |
146 | 142 ;-----------------------------------------------------------------------------; |
145 | 142 ;-----------------------------------------------------------------------------; |
147 | 143 ; uint16_t ihypot ( |
146 | 143 ; uint16_t ihypot ( |
148 | 144 ; int16_t x, |
147 | 144 ; int16_t x, |
149 | 145 ; int16_t y |
148 | 145 ; int16_t y |
150 | 146 ; ); |
149 | 146 ; ); |
151 | 147 ; |
150 | 147 ; |
152 | 148 ; Return Value: |
151 | 148 ; Return Value: |
153 | 149 ; Squareroot of (x*x + y*y) |
152 | 149 ; Squareroot of (x*x + y*y) |
154 | 150 ; |
153 | 150 ; |
155 | 151 ; Size = 42 words |
154 | 151 ; Size = 42 words |
156 | 152 ; Clock = 581..597 cycles |
155 | 152 ; Clock = 581..597 cycles |
157 | 153 ; Stack = 0 byte |
156 | 153 ; Stack = 0 byte |
158 | 154 |
157 | 154 |
159 | 155 .global ihypot |
158 | 155 .global ihypot |
160 | 156 .func ihypot |
159 | 156 .func ihypot |
161 | 157 |
160 | 157 |
162 | 158:isqrt.S **** ihypot: |
161 | 158:isqrt.S **** ihypot: |
163 | 159:isqrt.S **** clr r26 |
162 | 159:isqrt.S **** clr r26 |
164 | 160:isqrt.S **** sbrs r25, 7 |
163 | 160:isqrt.S **** sbrs r25, 7 |
165 | 161:isqrt.S **** rjmp 1f |
164 | 161:isqrt.S **** rjmp 1f |
166 | 162:isqrt.S **** com r24 |
165 | 162:isqrt.S **** com r24 |
167 | 163:isqrt.S **** com r25 |
166 | 163:isqrt.S **** com r25 |
168 | 164:isqrt.S **** adc r24, r26 |
167 | 164:isqrt.S **** adc r24, r26 |
169 | 165:isqrt.S **** adc r25, r26 |
168 | 165:isqrt.S **** adc r25, r26 |
170 | 166:isqrt.S **** 1: sbrs r23, 7 |
169 | 166:isqrt.S **** 1: sbrs r23, 7 |
171 | 167:isqrt.S **** rjmp 2f |
170 | 167:isqrt.S **** rjmp 2f |
172 | 168:isqrt.S **** com r22 |
171 | 168:isqrt.S **** com r22 |
173 | 169:isqrt.S **** com r23 |
172 | 169:isqrt.S **** com r23 |
174 | 170:isqrt.S **** adc r22, r26 |
173 | 170:isqrt.S **** adc r22, r26 |
175 | 171:isqrt.S **** adc r23, r26 |
174 | 171:isqrt.S **** adc r23, r26 |
176 | 172:isqrt.S **** 2: mul r22, r22 |
175 | 172:isqrt.S **** 2: mul r22, r22 |
177 | 173:isqrt.S **** movw r18, r0 |
176 | 173:isqrt.S **** movw r18, r0 |
178 | 174:isqrt.S **** mul r23, r23 |
177 | 174:isqrt.S **** mul r23, r23 |
179 | 175:isqrt.S **** movw r20, r0 |
178 | 175:isqrt.S **** movw r20, r0 |
180 | 176:isqrt.S **** mul r22, r23 |
179 | 176:isqrt.S **** mul r22, r23 |
181 | 177:isqrt.S **** add r19, r0 |
180 | 177:isqrt.S **** add r19, r0 |
182 | 178:isqrt.S **** adc r20, r1 |
181 | 178:isqrt.S **** adc r20, r1 |
183 | 179:isqrt.S **** adc r21, r26 |
182 | 179:isqrt.S **** adc r21, r26 |
184 | 180:isqrt.S **** add r19, r0 |
183 | 180:isqrt.S **** add r19, r0 |
185 | 181:isqrt.S **** adc r20, r1 |
184 | 181:isqrt.S **** adc r20, r1 |
186 | 182:isqrt.S **** adc r21, r26 |
185 | 182:isqrt.S **** adc r21, r26 |
187 | 183:isqrt.S **** mul r24, r24 |
186 | 183:isqrt.S **** mul r24, r24 |
188 | 184:isqrt.S **** movw r30, r0 |
187 | 184:isqrt.S **** movw r30, r0 |
189 | 185:isqrt.S **** mul r25, r25 |
188 | 185:isqrt.S **** mul r25, r25 |
190 | 186:isqrt.S **** add r18, r30 |
189 | 186:isqrt.S **** add r18, r30 |
191 | 187:isqrt.S **** adc r19, r31 |
190 | 187:isqrt.S **** adc r19, r31 |
192 | 188:isqrt.S **** adc r20, r0 |
191 | 188:isqrt.S **** adc r20, r0 |
193 | 189:isqrt.S **** adc r21, r1 |
192 | 189:isqrt.S **** adc r21, r1 |
194 | 190:isqrt.S **** mul r24, r25 |
193 | 190:isqrt.S **** mul r24, r25 |
195 | 191:isqrt.S **** add r19, r0 |
194 | 191:isqrt.S **** add r19, r0 |
196 | 192:isqrt.S **** adc r20, r1 |
195 | 192:isqrt.S **** adc r20, r1 |
197 | 193:isqrt.S **** adc r21, r26 |
196 | 193:isqrt.S **** adc r21, r26 |
198 | 194:isqrt.S **** add r19, r0 |
197 | 194:isqrt.S **** add r19, r0 |
199 | 195:isqrt.S **** adc r20, r1 |
198 | 195:isqrt.S **** adc r20, r1 |
200 | 196:isqrt.S **** adc r21, r26 |
199 | 196:isqrt.S **** adc r21, r26 |
201 | 197:isqrt.S **** movw r24, r20 |
200 | 197:isqrt.S **** movw r24, r20 |
202 | 198:isqrt.S **** movw r22, r18 |
201 | 198:isqrt.S **** movw r22, r18 |
203 | 199:isqrt.S **** clr r1 |
202 | 199:isqrt.S **** clr r1 |
204 | 200 rjmp isqrt32 |
203 | 200 rjmp isqrt32 |
205 | DEFINED SYMBOLS |
204 | DEFINED SYMBOLS |
206 | *ABS*:00000000 isqrt.S |
- | |
207 | isqrt.S:26 .text:00000000 isqrt32 |
205 | isqrt.S:26 .text:00000000 isqrt32 |
208 | isqrt.S:101 .text:0000006a isqrt16 |
206 | isqrt.S:101 .text:0000006a isqrt16 |
209 | isqrt.S:157 .text:000000ac ihypot |
207 | isqrt.S:157 .text:000000ac ihypot |
210 | 208 | ||
211 | NO UNDEFINED SYMBOLS |
209 | NO UNDEFINED SYMBOLS |