Skip to content

Commit fcdb8a7

Browse files
committed
pulseIn: add ASM implementation
this assembly code was generated by avr-gcc 4.8.3
1 parent e92be15 commit fcdb8a7

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
wiring_pulse.s - pulseInASM() function in different flavours
3+
Part of Arduino - http://www.arduino.cc/
4+
5+
Copyright (c) 2014 Martino Facchin
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General
18+
Public License along with this library; if not, write to the
19+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20+
Boston, MA 02111-1307 USA
21+
*/
22+
23+
# The following routine was generated by avr-gcc 4.8.3 with the following parameters
24+
# -gstabs -Wa,-ahlmsd=output.lst -dp -fverbose-asm -O2
25+
# on the original C function
26+
#
27+
# unsigned long pulseInSimpl(volatile uint8_t *port, uint8_t bit, uint8_t stateMask, unsigned long maxloops)
28+
# {
29+
# unsigned long width = 0;
30+
# // wait for any previous pulse to end
31+
# while ((*port & bit) == stateMask)
32+
# if (--maxloops == 0)
33+
# return 0;
34+
#
35+
# // wait for the pulse to start
36+
# while ((*port & bit) != stateMask)
37+
# if (--maxloops == 0)
38+
# return 0;
39+
#
40+
# // wait for the pulse to stop
41+
# while ((*port & bit) == stateMask) {
42+
# if (++width == maxloops)
43+
# return 0;
44+
# }
45+
# return width;
46+
# }
47+
#
48+
# some compiler outputs were removed but the rest of the code is untouched
49+
50+
#include <avr/io.h>
51+
52+
.section .text
53+
54+
.global countPulseASM
55+
56+
countPulseASM:
57+
58+
.LM0:
59+
.LFBB1:
60+
push r12 ; ; 130 pushqi1/1 [length = 1]
61+
push r13 ; ; 131 pushqi1/1 [length = 1]
62+
push r14 ; ; 132 pushqi1/1 [length = 1]
63+
push r15 ; ; 133 pushqi1/1 [length = 1]
64+
push r16 ; ; 134 pushqi1/1 [length = 1]
65+
push r17 ; ; 135 pushqi1/1 [length = 1]
66+
/* prologue: function */
67+
/* frame size = 0 */
68+
/* stack size = 6 */
69+
.L__stack_usage = 6
70+
mov r30,r24 ; port, port ; 2 *movhi/1 [length = 2]
71+
mov r31,r25 ; port, port
72+
/* unsigned long width = 0;
73+
*** // wait for any previous pulse to end
74+
*** while ((*port & bit) == stateMask)
75+
*/
76+
.LM1:
77+
rjmp .L2 ; ; 181 jump [length = 1]
78+
.L4:
79+
/* if (--maxloops == 0) */
80+
.LM2:
81+
subi r16,1 ; maxloops, ; 17 addsi3/2 [length = 4]
82+
sbc r17, r1 ; maxloops
83+
sbc r18, r1 ; maxloops
84+
sbc r19, r1 ; maxloops
85+
breq .L13 ; , ; 19 branch [length = 1]
86+
.L2:
87+
/* if (--maxloops == 0) */
88+
.LM3:
89+
ld r25,Z ; D.1554, *port_7(D) ; 22 movqi_insn/4 [length = 1]
90+
and r25,r22 ; D.1554, bit ; 24 andqi3/1 [length = 1]
91+
cp r25,r20 ; D.1554, stateMask ; 25 *cmpqi/2 [length = 1]
92+
breq .L4 ; , ; 26 branch [length = 1]
93+
rjmp .L6 ; ; 184 jump [length = 1]
94+
.L7:
95+
/* return 0;
96+
***
97+
*** // wait for the pulse to start
98+
*** while ((*port & bit) != stateMask)
99+
*** if (--maxloops == 0)
100+
*/
101+
.LM4:
102+
subi r16,1 ; maxloops, ; 31 addsi3/2 [length = 4]
103+
sbc r17, r1 ; maxloops
104+
sbc r18, r1 ; maxloops
105+
sbc r19, r1 ; maxloops
106+
breq .L13 ; , ; 33 branch [length = 1]
107+
.L6:
108+
/* if (--maxloops == 0) */
109+
.LM5:
110+
ld r25,Z ; D.1554, *port_7(D) ; 41 movqi_insn/4 [length = 1]
111+
and r25,r22 ; D.1554, bit ; 43 andqi3/1 [length = 1]
112+
cpse r25,r20 ; D.1554, stateMask ; 44 enable_interrupt-3 [length = 1]
113+
rjmp .L7 ;
114+
mov r12, r1 ; width ; 7 *movsi/2 [length = 4]
115+
mov r13, r1 ; width
116+
mov r14, r1 ; width
117+
mov r15, r1 ; width
118+
rjmp .L9 ; ; 186 jump [length = 1]
119+
.L10:
120+
/* return 0;
121+
***
122+
*** // wait for the pulse to stop
123+
*** while ((*port & bit) == stateMask) {
124+
*** if (++width == maxloops)
125+
*/
126+
.LM6:
127+
ldi r24,-1 ; , ; 50 addsi3/3 [length = 5]
128+
sub r12,r24 ; width,
129+
sbc r13,r24 ; width,
130+
sbc r14,r24 ; width,
131+
sbc r15,r24 ; width,
132+
cp r16,r12 ; maxloops, width ; 51 *cmpsi/2 [length = 4]
133+
cpc r17,r13 ; maxloops, width
134+
cpc r18,r14 ; maxloops, width
135+
cpc r19,r15 ; maxloops, width
136+
breq .L13 ; , ; 52 branch [length = 1]
137+
.L9:
138+
/* if (++width == maxloops) */
139+
.LM7:
140+
ld r24,Z ; D.1554, *port_7(D) ; 60 movqi_insn/4 [length = 1]
141+
and r24,r22 ; D.1554, bit ; 62 andqi3/1 [length = 1]
142+
cp r24,r20 ; D.1554, stateMask ; 63 *cmpqi/2 [length = 1]
143+
breq .L10 ; , ; 64 branch [length = 1]
144+
/* return 0;
145+
*** }
146+
*** return width;
147+
*/
148+
.LM8:
149+
mov r22,r12 ; D.1553, width ; 108 movqi_insn/1 [length = 1]
150+
mov r23,r13 ; D.1553, width ; 109 movqi_insn/1 [length = 1]
151+
mov r24,r14 ; D.1553, width ; 110 movqi_insn/1 [length = 1]
152+
mov r25,r15 ; D.1553, width ; 111 movqi_insn/1 [length = 1]
153+
/* epilogue start */
154+
.LM9:
155+
pop r17 ; ; 171 popqi [length = 1]
156+
pop r16 ; ; 172 popqi [length = 1]
157+
pop r15 ; ; 173 popqi [length = 1]
158+
pop r14 ; ; 174 popqi [length = 1]
159+
pop r13 ; ; 175 popqi [length = 1]
160+
pop r12 ; ; 176 popqi [length = 1]
161+
ret ; 177 return_from_epilogue [length = 1]
162+
.L13:
163+
.LM10:
164+
ldi r22,0 ; D.1553 ; 120 movqi_insn/1 [length = 1]
165+
ldi r23,0 ; D.1553 ; 121 movqi_insn/1 [length = 1]
166+
ldi r24,0 ; D.1553 ; 122 movqi_insn/1 [length = 1]
167+
ldi r25,0 ; D.1553 ; 123 movqi_insn/1 [length = 1]
168+
/* epilogue start */
169+
.LM11:
170+
pop r17 ; ; 138 popqi [length = 1]
171+
pop r16 ; ; 139 popqi [length = 1]
172+
pop r15 ; ; 140 popqi [length = 1]
173+
pop r14 ; ; 141 popqi [length = 1]
174+
pop r13 ; ; 142 popqi [length = 1]
175+
pop r12 ; ; 143 popqi [length = 1]
176+
ret ; 144 return_from_epilogue [length = 1]

0 commit comments

Comments
 (0)