Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
10bde693
Commit
10bde693
authored
Nov 02, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/utime_mphal: ticks_diff(): Optimize to avoid if conditions.
parent
5fae9143
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
6 deletions
+4
-6
extmod/utime_mphal.c
extmod/utime_mphal.c
+4
-6
No files found.
extmod/utime_mphal.c
View file @
10bde693
...
...
@@ -89,12 +89,10 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) {
// we assume that the arguments come from ticks_xx so are small ints
uint32_t
start
=
MP_OBJ_SMALL_INT_VALUE
(
start_in
);
uint32_t
end
=
MP_OBJ_SMALL_INT_VALUE
(
end_in
);
int32_t
diff
=
end
-
start
;
if
(
diff
<
(
signed
)
-
(
MICROPY_PY_UTIME_TICKS_PERIOD
/
2
))
{
diff
+=
MICROPY_PY_UTIME_TICKS_PERIOD
;
}
else
if
(
diff
>=
(
signed
)(
MICROPY_PY_UTIME_TICKS_PERIOD
/
2
))
{
diff
-=
MICROPY_PY_UTIME_TICKS_PERIOD
;
}
// Optimized formula avoiding if conditions. We adjust difference "forward",
// wrap it around and adjust back.
int32_t
diff
=
((
end
-
start
+
MICROPY_PY_UTIME_TICKS_PERIOD
/
2
)
&
(
MICROPY_PY_UTIME_TICKS_PERIOD
-
1
))
-
MICROPY_PY_UTIME_TICKS_PERIOD
/
2
;
return
MP_OBJ_NEW_SMALL_INT
(
diff
);
}
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_utime_ticks_diff_obj
,
time_ticks_diff
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment