Skip to content

Commit 2281fd6

Browse files
bors[bot]ovidiusaboujonas-schievink
authored
Merge #328
328: Prevent underflow when calling delay(n) with n<2 r=jonas-schievink a=ovidiusabou Calling delay(1) causes a very long wait (freeze) otherwise. 86cd463 introduced this behaviour by changing the cycle count from n / 4 + 1 to n / 2 which forces an underflow when n<2. Co-authored-by: Ovidiu Sabou <[email protected]> Co-authored-by: Jonas Schievink <[email protected]>
2 parents c714cdf + fdc3ab0 commit 2281fd6

15 files changed

+2
-1
lines changed

asm/inline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ pub unsafe fn __delay(cyc: u32) {
5555
// The loop will normally take 3 to 4 CPU cycles per iteration, but superscalar cores
5656
// (eg. Cortex-M7) can potentially do it in 2, so we use that as the lower bound, since delaying
5757
// for more cycles is okay.
58-
let real_cyc = cyc / 2;
58+
// Add 1 to prevent an integer underflow which would cause a long freeze
59+
let real_cyc = 1 + cyc / 2;
5960
asm!(
6061
// Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m.
6162
"1:",

bin/thumbv6m-none-eabi-lto.a

16 Bytes
Binary file not shown.

bin/thumbv6m-none-eabi.a

12 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi-lto.a

12 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi.a

8 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf-lto.a

12 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf.a

8 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi-lto.a

16 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi.a

4 Bytes
Binary file not shown.

bin/thumbv8m.base-none-eabi-lto.a

20 Bytes
Binary file not shown.

bin/thumbv8m.base-none-eabi.a

12 Bytes
Binary file not shown.

bin/thumbv8m.main-none-eabi-lto.a

16 Bytes
Binary file not shown.

bin/thumbv8m.main-none-eabi.a

4 Bytes
Binary file not shown.

bin/thumbv8m.main-none-eabihf-lto.a

20 Bytes
Binary file not shown.

bin/thumbv8m.main-none-eabihf.a

4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)