From bb99df0cbf2ddc1e325ff5030fc96ab85ed70486 Mon Sep 17 00:00:00 2001 From: Venelin Efremov Date: Sat, 18 Aug 2018 11:30:52 -0700 Subject: [PATCH 1/5] Don't call __delay_4cycles for 0 cycle delay - takes a really long time. --- Marlin/src/HAL/shared/Delay.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h index 9b5f1aa123d7..510f8e3d1d81 100644 --- a/Marlin/src/HAL/shared/Delay.h +++ b/Marlin/src/HAL/shared/Delay.h @@ -115,7 +115,10 @@ #undef MAXNOPS } else - __delay_4cycles(x / 4); + { + if ((x = (x) / 4)) + __delay_4cycles(x); + } } #undef nop From aa43c1cd6beba95256dbb56dc70a782927ca980e Mon Sep 17 00:00:00 2001 From: Venelin Efremov Date: Sat, 18 Aug 2018 12:07:14 -0700 Subject: [PATCH 2/5] Place the fix in the correct CPU architecture. --- Marlin/src/HAL/shared/Delay.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h index 510f8e3d1d81..d166d408ce75 100644 --- a/Marlin/src/HAL/shared/Delay.h +++ b/Marlin/src/HAL/shared/Delay.h @@ -75,8 +75,10 @@ } #undef MAXNOPS } - else - __delay_4cycles(x / 4); + else { + if ((x = (x) / 4)) + __delay_4cycles(x / 4); + } } #undef nop @@ -115,10 +117,7 @@ #undef MAXNOPS } else - { - if ((x = (x) / 4)) - __delay_4cycles(x); - } + __delay_4cycles(x / 4); } #undef nop From 022df7575b82e1bf454f8bb8a1fc0fda818dfd2a Mon Sep 17 00:00:00 2001 From: Venelin Efremov Date: Sat, 18 Aug 2018 12:08:49 -0700 Subject: [PATCH 3/5] One of these days I'll get it right. --- Marlin/src/HAL/shared/Delay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h index d166d408ce75..cde30551b89c 100644 --- a/Marlin/src/HAL/shared/Delay.h +++ b/Marlin/src/HAL/shared/Delay.h @@ -77,7 +77,7 @@ } else { if ((x = (x) / 4)) - __delay_4cycles(x / 4); + __delay_4cycles(x); } } #undef nop From 84f368234a2b2e13b18358fa60736f4c4ed3ae53 Mon Sep 17 00:00:00 2001 From: Venelin Efremov Date: Sat, 18 Aug 2018 12:13:29 -0700 Subject: [PATCH 4/5] Have consistent brackets style. --- Marlin/src/HAL/shared/Delay.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h index cde30551b89c..26070817ee14 100644 --- a/Marlin/src/HAL/shared/Delay.h +++ b/Marlin/src/HAL/shared/Delay.h @@ -75,7 +75,8 @@ } #undef MAXNOPS } - else { + else + { if ((x = (x) / 4)) __delay_4cycles(x); } From 3078e4d0885846c51f4acc6df7446b4e54d1d1b3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 18 Aug 2018 22:49:06 -0500 Subject: [PATCH 5/5] Confirm non-zero before call --- Marlin/src/HAL/shared/Delay.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h index 26070817ee14..04771a2e0385 100644 --- a/Marlin/src/HAL/shared/Delay.h +++ b/Marlin/src/HAL/shared/Delay.h @@ -75,11 +75,8 @@ } #undef MAXNOPS } - else - { - if ((x = (x) / 4)) - __delay_4cycles(x); - } + else if ((x >>= 2)) + __delay_4cycles(x); } #undef nop @@ -117,8 +114,8 @@ #undef MAXNOPS } - else - __delay_4cycles(x / 4); + else if ((x >>= 2)) + __delay_4cycles(x); } #undef nop