Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
2cae0f62
Commit
2cae0f62
authored
May 28, 2015
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Reduce size of mp_printf by eliminating unnecessary code.
Saves around 120 bytes on Thumb2 archs.
parent
78744c4f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/mpprint.c
+12
-2
12 additions, 2 deletions
py/mpprint.c
py/mpprint.h
+0
-1
0 additions, 1 deletion
py/mpprint.h
with
12 additions
and
3 deletions
py/mpprint.c
+
12
−
2
View file @
2cae0f62
...
@@ -120,9 +120,13 @@ int mp_print_strn(const mp_print_t *print, const char *str, mp_uint_t len, int f
...
@@ -120,9 +120,13 @@ int mp_print_strn(const mp_print_t *print, const char *str, mp_uint_t len, int f
// We can use 16 characters for 32-bit and 32 characters for 64-bit
// We can use 16 characters for 32-bit and 32 characters for 64-bit
#define INT_BUF_SIZE (sizeof(mp_int_t) * 4)
#define INT_BUF_SIZE (sizeof(mp_int_t) * 4)
// This function is used by stmhal port to implement printf.
// Our mp_vprintf function below does not support the '#' format modifier to
// print the prefix of a non-base-10 number, so we don't need code for this.
#define SUPPORT_INT_BASE_PREFIX (0)
// This function is used exclusively by mp_vprintf to format ints.
// It needs to be a separate function to mp_print_mp_int, since converting to a mp_int looses the MSB.
// It needs to be a separate function to mp_print_mp_int, since converting to a mp_int looses the MSB.
int
mp_print_int
(
const
mp_print_t
*
print
,
mp_uint_t
x
,
int
sgn
,
int
base
,
int
base_char
,
int
flags
,
char
fill
,
int
width
)
{
STATIC
int
mp_print_int
(
const
mp_print_t
*
print
,
mp_uint_t
x
,
int
sgn
,
int
base
,
int
base_char
,
int
flags
,
char
fill
,
int
width
)
{
char
sign
=
0
;
char
sign
=
0
;
if
(
sgn
)
{
if
(
sgn
)
{
if
((
mp_int_t
)
x
<
0
)
{
if
((
mp_int_t
)
x
<
0
)
{
...
@@ -153,6 +157,7 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
...
@@ -153,6 +157,7 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
}
while
(
b
>
buf
&&
x
!=
0
);
}
while
(
b
>
buf
&&
x
!=
0
);
}
}
#if SUPPORT_INT_BASE_PREFIX
char
prefix_char
=
'\0'
;
char
prefix_char
=
'\0'
;
if
(
flags
&
PF_FLAG_SHOW_PREFIX
)
{
if
(
flags
&
PF_FLAG_SHOW_PREFIX
)
{
...
@@ -164,6 +169,7 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
...
@@ -164,6 +169,7 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
prefix_char
=
base_char
+
'x'
-
'a'
;
prefix_char
=
base_char
+
'x'
-
'a'
;
}
}
}
}
#endif
int
len
=
0
;
int
len
=
0
;
if
(
flags
&
PF_FLAG_PAD_AFTER_SIGN
)
{
if
(
flags
&
PF_FLAG_PAD_AFTER_SIGN
)
{
...
@@ -171,16 +177,20 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
...
@@ -171,16 +177,20 @@ int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int ba
len
+=
mp_print_strn
(
print
,
&
sign
,
1
,
flags
,
fill
,
1
);
len
+=
mp_print_strn
(
print
,
&
sign
,
1
,
flags
,
fill
,
1
);
width
--
;
width
--
;
}
}
#if SUPPORT_INT_BASE_PREFIX
if
(
prefix_char
)
{
if
(
prefix_char
)
{
len
+=
mp_print_strn
(
print
,
"0"
,
1
,
flags
,
fill
,
1
);
len
+=
mp_print_strn
(
print
,
"0"
,
1
,
flags
,
fill
,
1
);
len
+=
mp_print_strn
(
print
,
&
prefix_char
,
1
,
flags
,
fill
,
1
);
len
+=
mp_print_strn
(
print
,
&
prefix_char
,
1
,
flags
,
fill
,
1
);
width
-=
2
;
width
-=
2
;
}
}
#endif
}
else
{
}
else
{
#if SUPPORT_INT_BASE_PREFIX
if
(
prefix_char
&&
b
>
&
buf
[
1
])
{
if
(
prefix_char
&&
b
>
&
buf
[
1
])
{
*
(
--
b
)
=
prefix_char
;
*
(
--
b
)
=
prefix_char
;
*
(
--
b
)
=
'0'
;
*
(
--
b
)
=
'0'
;
}
}
#endif
if
(
sign
&&
b
>
buf
)
{
if
(
sign
&&
b
>
buf
)
{
*
(
--
b
)
=
sign
;
*
(
--
b
)
=
sign
;
}
}
...
...
This diff is collapsed.
Click to expand it.
py/mpprint.h
+
0
−
1
View file @
2cae0f62
...
@@ -57,7 +57,6 @@ extern const mp_print_t mp_sys_stdout_print;
...
@@ -57,7 +57,6 @@ extern const mp_print_t mp_sys_stdout_print;
int
mp_print_str
(
const
mp_print_t
*
print
,
const
char
*
str
);
int
mp_print_str
(
const
mp_print_t
*
print
,
const
char
*
str
);
int
mp_print_strn
(
const
mp_print_t
*
print
,
const
char
*
str
,
mp_uint_t
len
,
int
flags
,
char
fill
,
int
width
);
int
mp_print_strn
(
const
mp_print_t
*
print
,
const
char
*
str
,
mp_uint_t
len
,
int
flags
,
char
fill
,
int
width
);
int
mp_print_int
(
const
mp_print_t
*
print
,
mp_uint_t
x
,
int
sgn
,
int
base
,
int
base_char
,
int
flags
,
char
fill
,
int
width
);
#if MICROPY_PY_BUILTINS_FLOAT
#if MICROPY_PY_BUILTINS_FLOAT
int
mp_print_float
(
const
mp_print_t
*
print
,
mp_float_t
f
,
char
fmt
,
int
flags
,
char
fill
,
int
width
,
int
prec
);
int
mp_print_float
(
const
mp_print_t
*
print
,
mp_float_t
f
,
char
fmt
,
int
flags
,
char
fill
,
int
width
,
int
prec
);
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment