Quote
Taking 4 µs on a 32 bit processor running at 120 MHz would indeed be awful. 480 clock cycles. Hard to see how you could even do that.
Here it is in all its ugliness!
micros()->(crit)elapsed_time->(crit)slicetime->(crit)ticker_read_us->initialize/(core_crit)/update_present_time->math
Code:
[Select]10004484 <micros>:
unsigned long micros() {
10004484: b507 push {r0, r1, r2, lr}
return timer.elapsed_time().count();
10004486: 4903 ldr r1, [pc, #12] ; (10004494 <micros+0x10>)
10004488: 4668 mov r0, sp
1000448a: f002 fc80 bl 10006d8e <mbed::TimerBase::elapsed_time() const>
}
1000448e: 9800 ldr r0, [sp, #0]
10004490: bd0e pop {r1, r2, r3, pc}
10004492: 46c0 nop ; (mov r8, r8)
10004494: 20000fc8 .word 0x20000fc8
---------
10006d8e <mbed::TimerBase::elapsed_time() const>:
10006d8e: b530 push {r4, r5, lr}
10006d90: 000d movs r5, r1
10006d92: b085 sub sp, #20
10006d94: 0004 movs r4, r0
10006d96: a803 add r0, sp, #12
10006d98: f002 f820 bl 10008ddc <mbed::CriticalSectionLock::CriticalSectionLock()>
10006d9c: 0029 movs r1, r5
10006d9e: 4668 mov r0, sp
10006da0: f7ff ffda bl 10006d58 <mbed::TimerBase::slicetime() const>
10006da4: 68a8 ldr r0, [r5, #8]
10006da6: 68e9 ldr r1, [r5, #12]
10006da8: 9a00 ldr r2, [sp, #0]
10006daa: 9b01 ldr r3, [sp, #4]
10006dac: 1812 adds r2, r2, r0
10006dae: 414b adcs r3, r1
10006db0: a803 add r0, sp, #12
10006db2: 6022 str r2, [r4, #0]
10006db4: 6063 str r3, [r4, #4]
10006db6: f002 f817 bl 10008de8 <mbed::CriticalSectionLock::~CriticalSectionLock()>
10006dba: 0020 movs r0, r4
10006dbc: b005 add sp, #20
10006dbe: bd30 pop {r4, r5, pc}
-------
10006d58 <mbed::TimerBase::slicetime() const>:
10006d58: b537 push {r0, r1, r2, r4, r5, lr}
10006d5a: 0004 movs r4, r0
10006d5c: a801 add r0, sp, #4
10006d5e: 000d movs r5, r1
10006d60: f002 f83c bl 10008ddc <mbed::CriticalSectionLock::CriticalSectionLock()>
10006d64: 2300 movs r3, #0
10006d66: 2200 movs r2, #0
10006d68: 6022 str r2, [r4, #0]
10006d6a: 6063 str r3, [r4, #4]
10006d6c: 7d6b ldrb r3, [r5, #21]
10006d6e: 2b00 cmp r3, #0
10006d70: d008 beq.n 10006d84 <mbed::TimerBase::slicetime() const+0x2c>
10006d72: 6928 ldr r0, [r5, #16]
10006d74: f001 fff0 bl 10008d58 <ticker_read_us>
10006d78: 682a ldr r2, [r5, #0]
10006d7a: 686b ldr r3, [r5, #4]
10006d7c: 1a80 subs r0, r0, r2
10006d7e: 4199 sbcs r1, r3
10006d80: 6020 str r0, [r4, #0]
10006d82: 6061 str r1, [r4, #4]
10006d84: a801 add r0, sp, #4
10006d86: f002 f82f bl 10008de8 <mbed::CriticalSectionLock::~CriticalSectionLock()>
10006d8a: 0020 movs r0, r4
10006d8c: bd3e pop {r1, r2, r3, r4, r5, pc}
------
10008d58 <ticker_read_us>:
10008d58: b570 push {r4, r5, r6, lr}
10008d5a: 0004 movs r4, r0
10008d5c: f7ff ff2e bl 10008bbc <initialize>
10008d60: f000 fc24 bl 100095ac <core_util_critical_section_enter>
10008d64: 0020 movs r0, r4
10008d66: f7ff fe41 bl 100089ec <update_present_time>
10008d6a: 6863 ldr r3, [r4, #4]
10008d6c: 6a9c ldr r4, [r3, #40] ; 0x28
10008d6e: 6add ldr r5, [r3, #44] ; 0x2c
10008d70: f000 fc32 bl 100095d8 <core_util_critical_section_exit>
10008d74: 0029 movs r1, r5
10008d76: 0020 movs r0, r4
10008d78: bd70 pop {r4, r5, r6, pc}
-------
100089ec <update_present_time>:
100089ec: b5f7 push {r0, r1, r2, r4, r5, r6, r7, lr}
100089ee: 6846 ldr r6, [r0, #4]
100089f0: 0033 movs r3, r6
100089f2: 3332 adds r3, #50 ; 0x32
100089f4: 781c ldrb r4, [r3, #0]
100089f6: 2c00 cmp r4, #0
100089f8: d132 bne.n 10008a60 <update_present_time+0x74>
100089fa: 6803 ldr r3, [r0, #0]
100089fc: 685b ldr r3, [r3, #4]
100089fe: 4798 blx r3
10008a00: 6a32 ldr r2, [r6, #32]
10008a02: 0003 movs r3, r0
10008a04: 4282 cmp r2, r0
10008a06: d02b beq.n 10008a60 <update_present_time+0x74>
10008a08: 1a82 subs r2, r0, r2
10008a0a: 6930 ldr r0, [r6, #16]
10008a0c: 6233 str r3, [r6, #32]
10008a0e: 4010 ands r0, r2
10008a10: 2233 movs r2, #51 ; 0x33
10008a12: 56b2 ldrsb r2, [r6, r2]
10008a14: 2a00 cmp r2, #0
10008a16: db24 blt.n 10008a62 <update_present_time+0x76>
10008a18: 0021 movs r1, r4
10008a1a: f7f7 feb1 bl 10000780 <__aeabi_llsl>
10008a1e: 2734 movs r7, #52 ; 0x34
10008a20: 57f7 ldrsb r7, [r6, r7]
10008a22: 0004 movs r4, r0
10008a24: 000d movs r5, r1
10008a26: 2f00 cmp r7, #0
10008a28: d014 beq.n 10008a54 <update_present_time+0x68>
10008a2a: 2100 movs r1, #0
10008a2c: 6a70 ldr r0, [r6, #36] ; 0x24
10008a2e: 1824 adds r4, r4, r0
10008a30: 414d adcs r5, r1
10008a32: 9400 str r4, [sp, #0]
10008a34: 9501 str r5, [sp, #4]
10008a36: 428f cmp r7, r1
10008a38: db1b blt.n 10008a72 <update_present_time+0x86>
10008a3a: 003a movs r2, r7
10008a3c: 0020 movs r0, r4
10008a3e: 0029 movs r1, r5
10008a40: f7f7 fe92 bl 10000768 <__aeabi_llsr>
10008a44: 003a movs r2, r7
10008a46: 0004 movs r4, r0
10008a48: 000d movs r5, r1
10008a4a: f7f7 fe99 bl 10000780 <__aeabi_llsl>
10008a4e: 9b00 ldr r3, [sp, #0]
10008a50: 1a18 subs r0, r3, r0
10008a52: 6270 str r0, [r6, #36] ; 0x24
10008a54: 6ab2 ldr r2, [r6, #40] ; 0x28
10008a56: 6af3 ldr r3, [r6, #44] ; 0x2c
10008a58: 1912 adds r2, r2, r4
10008a5a: 416b adcs r3, r5
10008a5c: 62b2 str r2, [r6, #40] ; 0x28
10008a5e: 62f3 str r3, [r6, #44] ; 0x2c
10008a60: bdf7 pop {r0, r1, r2, r4, r5, r6, r7, pc}
10008a62: 68b1 ldr r1, [r6, #8]
10008a64: 0002 movs r2, r0
10008a66: 0023 movs r3, r4
10008a68: 0008 movs r0, r1
10008a6a: 0021 movs r1, r4
10008a6c: f7f7 ff34 bl 100008d8 <__aeabi_lmul>
10008a70: e7d5 b.n 10008a1e <update_present_time+0x32>
10008a72: 68f7 ldr r7, [r6, #12]
10008a74: 000b movs r3, r1
10008a76: 9800 ldr r0, [sp, #0]
10008a78: 9901 ldr r1, [sp, #4]
10008a7a: 003a movs r2, r7
10008a7c: f7f7 ff0c bl 10000898 <__aeabi_uldivmod>
10008a80: 4347 muls r7, r0
10008a82: 9b00 ldr r3, [sp, #0]
10008a84: 0004 movs r4, r0
10008a86: 1bdf subs r7, r3, r7
10008a88: 000d movs r5, r1
10008a8a: 6277 str r7, [r6, #36] ; 0x24
10008a8c: e7e2 b.n 10008a54 <update_present_time+0x68>
-------
10008ddc <mbed::CriticalSectionLock::CriticalSectionLock()>:
10008ddc: b510 push {r4, lr}
10008dde: 0004 movs r4, r0
10008de0: f000 fbe4 bl 100095ac <core_util_critical_section_enter>
10008de4: 0020 movs r0, r4
10008de6: bd10 pop {r4, pc}
Disassembly of section .text._ZN4mbed19CriticalSectionLockD2Ev:
10008de8 <mbed::CriticalSectionLock::~CriticalSectionLock()>:
10008de8: b510 push {r4, lr}
10008dea: 0004 movs r4, r0
10008dec: f000 fbf4 bl 100095d8 <core_util_critical_section_exit>
10008df0: 0020 movs r0, r4
10008df2: bd10 pop {r4, pc}
-------
100095ac <core_util_critical_section_enter>:
100095ac: b510 push {r4, lr}
100095ae: f7ff f979 bl 100088a4 <hal_critical_section_enter>
100095b2: 4a06 ldr r2, [pc, #24] ; (100095cc <core_util_critical_section_enter+0x20>)
100095b4: 6813 ldr r3, [r2, #0]
100095b6: 1c59 adds r1, r3, #1
100095b8: d104 bne.n 100095c4 <core_util_critical_section_enter+0x18>
100095ba: 223f movs r2, #63 ; 0x3f
100095bc: 4904 ldr r1, [pc, #16] ; (100095d0 <core_util_critical_section_enter+0x24>)
100095be: 4805 ldr r0, [pc, #20] ; (100095d4 <core_util_critical_section_enter+0x28>)
100095c0: f7ff ff46 bl 10009450 <mbed_assert_internal>
100095c4: 3301 adds r3, #1
100095c6: 6013 str r3, [r2, #0]
100095c8: bd10 pop {r4, pc}
100095ca: 46c0 nop ; (mov r8, r8)
100095cc: 2000aa4c .word 0x2000aa4c
100095d0: 10013a2f .word 0x10013a2f
100095d4: 10013a59 .word 0x10013a59
Disassembly of section .text.core_util_critical_section_exit:
100095d8 <core_util_critical_section_exit>:
100095d8: 4a05 ldr r2, [pc, #20] ; (100095f0 <core_util_critical_section_exit+0x18>)
100095da: b510 push {r4, lr}
100095dc: 6813 ldr r3, [r2, #0]
100095de: 2b00 cmp r3, #0
100095e0: d005 beq.n 100095ee <core_util_critical_section_exit+0x16>
100095e2: 3b01 subs r3, #1
100095e4: 6013 str r3, [r2, #0]
100095e6: 2b00 cmp r3, #0
100095e8: d101 bne.n 100095ee <core_util_critical_section_exit+0x16>
100095ea: f7ff f96f bl 100088cc <hal_critical_section_exit>
100095ee: bd10 pop {r4, pc}
100095f0: 2000aa4c .word 0x2000aa4c
-------
100088a4 <hal_critical_section_enter>:
100088a4: b510 push {r4, lr}
100088a6: f3ef 8010 mrs r0, PRIMASK
100088aa: b672 cpsid i
100088ac: 4a05 ldr r2, [pc, #20] ; (100088c4 <hal_critical_section_enter+0x20>)
100088ae: 7813 ldrb r3, [r2, #0]
100088b0: 2b00 cmp r3, #0
100088b2: d105 bne.n 100088c0 <hal_critical_section_enter+0x1c>
100088b4: 2101 movs r1, #1
100088b6: 000c movs r4, r1
100088b8: 4b03 ldr r3, [pc, #12] ; (100088c8 <hal_critical_section_enter+0x24>)
100088ba: 4384 bics r4, r0
100088bc: 701c strb r4, [r3, #0]
100088be: 7011 strb r1, [r2, #0]
100088c0: bd10 pop {r4, pc}
100088c2: 46c0 nop ; (mov r8, r8)
100088c4: 2000adff .word 0x2000adff
100088c8: 2000adfa .word 0x2000adfa
Disassembly of section .text.hal_critical_section_exit:
100088cc <hal_critical_section_exit>:
100088cc: b510 push {r4, lr}
100088ce: f3ef 8210 mrs r2, PRIMASK
100088d2: 2301 movs r3, #1
100088d4: 4393 bics r3, r2
100088d6: d004 beq.n 100088e2 <hal_critical_section_exit+0x16>
100088d8: 2236 movs r2, #54 ; 0x36
100088da: 4906 ldr r1, [pc, #24] ; (100088f4 <hal_critical_section_exit+0x28>)
100088dc: 4806 ldr r0, [pc, #24] ; (100088f8 <hal_critical_section_exit+0x2c>)
100088de: f000 fdb7 bl 10009450 <mbed_assert_internal>
100088e2: 4a06 ldr r2, [pc, #24] ; (100088fc <hal_critical_section_exit+0x30>)
100088e4: 7013 strb r3, [r2, #0]
100088e6: 4b06 ldr r3, [pc, #24] ; (10008900 <hal_critical_section_exit+0x34>)
100088e8: 781b ldrb r3, [r3, #0]
100088ea: 2b00 cmp r3, #0
100088ec: d000 beq.n 100088f0 <hal_critical_section_exit+0x24>
100088ee: b662 cpsie i
100088f0: bd10 pop {r4, pc}
100088f2: 46c0 nop ; (mov r8, r8)
100088f4: 10013620 .word 0x10013620
100088f8: 10013651 .word 0x10013651
100088fc: 2000adff .word 0x2000adff
10008900: 2000adfa .word 0x2000adfa