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