* [PATCH] save around 100 bytes on core.img by inlining small misc.c functions
@ 2009-08-15 14:47 Vladimir 'phcoder' Serbinenko
2009-08-17 13:43 ` Robert Millan
0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-15 14:47 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 106 bytes --]
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
[-- Attachment #2: misc.diff --]
[-- Type: text/plain, Size: 5853 bytes --]
diff --git a/include/grub/misc.h b/include/grub/misc.h
index 769ec5c..a63a0b4 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -37,8 +37,42 @@ void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c);
char *EXPORT_FUNC(grub_stpcpy) (char *dest, const char *src);
-char *EXPORT_FUNC(grub_strcat) (char *dest, const char *src);
-char *EXPORT_FUNC(grub_strncat) (char *dest, const char *src, int c);
+
+static inline char *
+grub_strcat (char *dest, const char *src)
+{
+ char *p = dest;
+
+ while (*p)
+ p++;
+
+ while ((*p = *src) != '\0')
+ {
+ p++;
+ src++;
+ }
+
+ return dest;
+}
+
+static inline char *
+grub_strncat (char *dest, const char *src, int c)
+{
+ char *p = dest;
+
+ while (*p)
+ p++;
+
+ while ((*p = *src) != '\0' && c--)
+ {
+ p++;
+ src++;
+ }
+
+ *p = '\0';
+
+ return dest;
+}
/* Prototypes for aliases. */
#if !defined (GRUB_UTIL) || !defined (APPLE_CC)
@@ -49,19 +83,41 @@ void *EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n);
int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n);
int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2);
int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t n);
-int EXPORT_FUNC(grub_strcasecmp) (const char *s1, const char *s2);
-int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, grub_size_t n);
+
char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
int EXPORT_FUNC(grub_strword) (const char *s, const char *w);
char *EXPORT_FUNC(grub_strstr) (const char *haystack, const char *needle);
-int EXPORT_FUNC(grub_iswordseparator) (int c);
int EXPORT_FUNC(grub_isspace) (int c);
int EXPORT_FUNC(grub_isprint) (int c);
-int EXPORT_FUNC(grub_isalpha) (int c);
-int EXPORT_FUNC(grub_isgraph) (int c);
-int EXPORT_FUNC(grub_isdigit) (int c);
-int EXPORT_FUNC(grub_tolower) (int c);
+
+static inline int
+grub_isalpha (int c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
+}
+
+static inline int
+grub_isgraph (int c)
+{
+ return (c >= '!' && c <= '~');
+}
+
+static inline int
+grub_isdigit (int c)
+{
+ return (c >= '0' && c <= '9');
+}
+
+static inline int
+grub_tolower (int c)
+{
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A' + 'a';
+
+ return c;
+}
+
static inline int
grub_toupper (int c)
{
@@ -71,6 +127,40 @@ grub_toupper (int c)
return c;
}
+static inline int
+grub_strcasecmp (const char *s1, const char *s2)
+{
+ while (*s1 && *s2)
+ {
+ if (grub_tolower (*s1) != grub_tolower (*s2))
+ break;
+
+ s1++;
+ s2++;
+ }
+
+ return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
+}
+
+static inline int
+grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
+{
+ if (n == 0)
+ return 0;
+
+ while (*s1 && *s2 && --n)
+ {
+ if (grub_tolower (*s1) != grub_tolower (*s2))
+ break;
+
+ s1++;
+ s2++;
+ }
+
+ return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
+}
+
+
unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base);
char *EXPORT_FUNC(grub_strdup) (const char *s);
diff --git a/kern/misc.c b/kern/misc.c
index d797f17..1c38fe6 100644
--- a/kern/misc.c
+++ b/kern/misc.c
@@ -24,6 +24,12 @@
#include <grub/term.h>
#include <grub/env.h>
+static int
+grub_iswordseparator (int c)
+{
+ return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&');
+}
+
void *
grub_memmove (void *dest, const void *src, grub_size_t n)
{
@@ -97,42 +103,6 @@ grub_stpcpy (char *dest, const char *src)
return d - 1;
}
-char *
-grub_strcat (char *dest, const char *src)
-{
- char *p = dest;
-
- while (*p)
- p++;
-
- while ((*p = *src) != '\0')
- {
- p++;
- src++;
- }
-
- return dest;
-}
-
-char *
-grub_strncat (char *dest, const char *src, int c)
-{
- char *p = dest;
-
- while (*p)
- p++;
-
- while ((*p = *src) != '\0' && c--)
- {
- p++;
- src++;
- }
-
- *p = '\0';
-
- return dest;
-}
-
int
grub_printf (const char *fmt, ...)
{
@@ -250,39 +220,6 @@ grub_strncmp (const char *s1, const char *s2, grub_size_t n)
return (int) *s1 - (int) *s2;
}
-int
-grub_strcasecmp (const char *s1, const char *s2)
-{
- while (*s1 && *s2)
- {
- if (grub_tolower (*s1) != grub_tolower (*s2))
- break;
-
- s1++;
- s2++;
- }
-
- return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
-}
-
-int
-grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
-{
- if (n == 0)
- return 0;
-
- while (*s1 && *s2 && --n)
- {
- if (grub_tolower (*s1) != grub_tolower (*s2))
- break;
-
- s1++;
- s2++;
- }
-
- return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
-}
-
char *
grub_strchr (const char *s, int c)
{
@@ -395,12 +332,6 @@ grub_strword (const char *haystack, const char *needle)
}
int
-grub_iswordseparator (int c)
-{
- return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&');
-}
-
-int
grub_isspace (int c)
{
return (c == '\n' || c == '\r' || c == ' ' || c == '\t');
@@ -412,33 +343,6 @@ grub_isprint (int c)
return (c >= ' ' && c <= '~');
}
-int
-grub_isalpha (int c)
-{
- return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
-}
-
-int
-grub_isdigit (int c)
-{
- return (c >= '0' && c <= '9');
-}
-
-int
-grub_isgraph (int c)
-{
- return (c >= '!' && c <= '~');
-}
-
-int
-grub_tolower (int c)
-{
- if (c >= 'A' && c <= 'Z')
- return c - 'A' + 'a';
-
- return c;
-}
-
unsigned long
grub_strtoul (const char *str, char **end, int base)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] save around 100 bytes on core.img by inlining small misc.c functions
2009-08-15 14:47 [PATCH] save around 100 bytes on core.img by inlining small misc.c functions Vladimir 'phcoder' Serbinenko
@ 2009-08-17 13:43 ` Robert Millan
2009-08-17 13:54 ` Vladimir 'phcoder' Serbinenko
0 siblings, 1 reply; 5+ messages in thread
From: Robert Millan @ 2009-08-17 13:43 UTC (permalink / raw)
To: The development of GRUB 2
On Sat, Aug 15, 2009 at 04:47:32PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> +static inline char *
> +grub_strncat (char *dest, const char *src, int c)
> +{
> + char *p = dest;
> +
> + while (*p)
> + p++;
> +
> + while ((*p = *src) != '\0' && c--)
> + {
> + p++;
> + src++;
> + }
> +
> + *p = '\0';
> +
> + return dest;
> +}
Some of them (like this one) are surprisingly big. Did you test them
separately?
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] save around 100 bytes on core.img by inlining small misc.c functions
2009-08-17 13:43 ` Robert Millan
@ 2009-08-17 13:54 ` Vladimir 'phcoder' Serbinenko
2009-08-19 15:11 ` Robert Millan
0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-17 13:54 UTC (permalink / raw)
To: The development of GRUB 2
On Mon, Aug 17, 2009 at 3:43 PM, Robert Millan<rmh@aybabtu.com> wrote:
> On Sat, Aug 15, 2009 at 04:47:32PM +0200, Vladimir 'phcoder' Serbinenko wrote:
>> +static inline char *
>> +grub_strncat (char *dest, const char *src, int c)
>> +{
>> + char *p = dest;
>> +
>> + while (*p)
>> + p++;
>> +
>> + while ((*p = *src) != '\0' && c--)
>> + {
>> + p++;
>> + src++;
>> + }
>> +
>> + *p = '\0';
>> +
>> + return dest;
>> +}
>
> Some of them (like this one) are surprisingly big. Did you test them
> separately?
Yes I did. My test environment was a core.img with pc+fat+biosdisk. I
have a log which functions save how much. In this case inlining
strncat saved 21 bytes. The reason for some bigger functions to be
inlined is that they are used only in non-size critical parts. In this
case it's used in LUA and iso9660.mod (one call). So inlining strncat
always saves space (even if iso9660.mod is in core.img but there is no
size limit when booting from cd).
>
> --
> Robert Millan
>
> The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
> how) you may access your data; but nobody's threatening your freedom: we
> still allow you to remove your data and not access it at all."
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] save around 100 bytes on core.img by inlining small misc.c functions
2009-08-17 13:54 ` Vladimir 'phcoder' Serbinenko
@ 2009-08-19 15:11 ` Robert Millan
2009-08-24 19:40 ` Vladimir 'phcoder' Serbinenko
0 siblings, 1 reply; 5+ messages in thread
From: Robert Millan @ 2009-08-19 15:11 UTC (permalink / raw)
To: The development of GRUB 2
On Mon, Aug 17, 2009 at 03:54:06PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> On Mon, Aug 17, 2009 at 3:43 PM, Robert Millan<rmh@aybabtu.com> wrote:
> > On Sat, Aug 15, 2009 at 04:47:32PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> >> +static inline char *
> >> +grub_strncat (char *dest, const char *src, int c)
> >> +{
> >> + char *p = dest;
> >> +
> >> + while (*p)
> >> + p++;
> >> +
> >> + while ((*p = *src) != '\0' && c--)
> >> + {
> >> + p++;
> >> + src++;
> >> + }
> >> +
> >> + *p = '\0';
> >> +
> >> + return dest;
> >> +}
> >
> > Some of them (like this one) are surprisingly big. Did you test them
> > separately?
> Yes I did. My test environment was a core.img with pc+fat+biosdisk. I
> have a log which functions save how much. In this case inlining
> strncat saved 21 bytes. The reason for some bigger functions to be
> inlined is that they are used only in non-size critical parts. In this
> case it's used in LUA and iso9660.mod (one call). So inlining strncat
> always saves space (even if iso9660.mod is in core.img but there is no
> size limit when booting from cd).
Ok, fine with me then.
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] save around 100 bytes on core.img by inlining small misc.c functions
2009-08-19 15:11 ` Robert Millan
@ 2009-08-24 19:40 ` Vladimir 'phcoder' Serbinenko
0 siblings, 0 replies; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-24 19:40 UTC (permalink / raw)
To: The development of GRUB 2
On Wed, Aug 19, 2009 at 5:11 PM, Robert Millan<rmh@aybabtu.com> wrote:
> On Mon, Aug 17, 2009 at 03:54:06PM +0200, Vladimir 'phcoder' Serbinenko wrote:
>> On Mon, Aug 17, 2009 at 3:43 PM, Robert Millan<rmh@aybabtu.com> wrote:
>> > On Sat, Aug 15, 2009 at 04:47:32PM +0200, Vladimir 'phcoder' Serbinenko wrote:
>> >> +static inline char *
>> >> +grub_strncat (char *dest, const char *src, int c)
>> >> +{
>> >> + char *p = dest;
>> >> +
>> >> + while (*p)
>> >> + p++;
>> >> +
>> >> + while ((*p = *src) != '\0' && c--)
>> >> + {
>> >> + p++;
>> >> + src++;
>> >> + }
>> >> +
>> >> + *p = '\0';
>> >> +
>> >> + return dest;
>> >> +}
>> >
>> > Some of them (like this one) are surprisingly big. Did you test them
>> > separately?
>> Yes I did. My test environment was a core.img with pc+fat+biosdisk. I
>> have a log which functions save how much. In this case inlining
>> strncat saved 21 bytes. The reason for some bigger functions to be
>> inlined is that they are used only in non-size critical parts. In this
>> case it's used in LUA and iso9660.mod (one call). So inlining strncat
>> always saves space (even if iso9660.mod is in core.img but there is no
>> size limit when booting from cd).
>
> Ok, fine with me then.
Comitted
>
> --
> Robert Millan
>
> The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
> how) you may access your data; but nobody's threatening your freedom: we
> still allow you to remove your data and not access it at all."
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-24 19:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-15 14:47 [PATCH] save around 100 bytes on core.img by inlining small misc.c functions Vladimir 'phcoder' Serbinenko
2009-08-17 13:43 ` Robert Millan
2009-08-17 13:54 ` Vladimir 'phcoder' Serbinenko
2009-08-19 15:11 ` Robert Millan
2009-08-24 19:40 ` Vladimir 'phcoder' Serbinenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.