Discussion:
[ast-developers] [patch] Patch for AST |restrict| ...
Roland Mainz
2013-08-17 16:48:44 UTC
Permalink
Hi!

----

Attached (as "astksh20130814_restrict001.diff.txt") is a patch which
provides the C99 flag |restrict| as |_AST_RESTRICT| if we compile with
a C99 (or better) compiler...

* Notes:
- I've converted a few functions to use |_AST_RESTRICT| already. The
point is that instrumentation tools can find issues (e.g. overlapping
memory accesses etc.) in those cases
- Tested with C89, C99 and C1X modes with gcc, clang and Sun Studio
- If this patch gets accepted (please please for the next alpha) I'll
do more conversion stuff per prototypes listed at opengroup.org. This
should give better instrumentation coverage and *MUCH* better
performance, too.

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u original/src/lib/libast/features/sys build_restrict/src/lib/libast/features/sys
--- src/lib/libast/features/sys 2013-08-09 16:55:32.000000000 +0200
+++ src/lib/libast/features/sys 2013-08-17 18:12:13.421570259 +0200
@@ -222,6 +222,14 @@
print #define extern __EXPORT__
print #endif

+print #ifndef _AST_RESTRICT
+print #if __STDC_VERSION__ >= 199901L
+print #define _AST_RESTRICT restrict
+print #else
+print #define _AST_RESTRICT
+print #endif
+print #endif
+
extern _exit void (int)
extern abort void (void)
extern abs int (int)
@@ -308,8 +316,8 @@
extern spawnvex_get intmax_t (Spawnvex_t*, int, int)
extern spawnvex_close int (Spawnvex_t*)
extern srand void (unsigned int)
-extern stpcpy char* (char*, const char*)
-extern stpncpy char* (char*, const char*, size_t)
+extern stpcpy char* (char* _AST_RESTRICT, const char* _AST_RESTRICT)
+extern stpncpy char* (char* _AST_RESTRICT, const char* _AST_RESTRICT, size_t)
extern strcasecmp int (const char*, const char*)
extern strcat char* (char*, const char*)
extern strchr char* (const char*, int)
diff -r -u original/src/lib/libast/include/ast.h build_restrict/src/lib/libast/include/ast.h
--- src/lib/libast/include/ast.h 2013-08-09 17:26:20.000000000 +0200
+++ src/lib/libast/include/ast.h 2013-08-17 18:28:01.265585566 +0200
@@ -63,6 +63,14 @@
#endif
#endif

+#ifndef _AST_RESTRICT
+#if __STDC_VERSION__ >= 199901L
+#define _AST_RESTRICT restrict
+#else
+#define _AST_RESTRICT
+#endif
+#endif
+
/*
* exit() support -- this matches shell exit codes
*/
@@ -352,7 +360,7 @@
extern ssize_t qpdecode(const void*, size_t, void**, void*, size_t, void**);
extern char* setenviron(const char*);
extern int stracmp(const char*, const char*);
-extern char* strcopy(char*, const char*);
+extern char* strcopy(char* _AST_RESTRICT, const char* _AST_RESTRICT);
extern unsigned long strelapsed(const char*, char**, int);
extern int stresc(char*);
extern int strexp(char*, int);
@@ -367,7 +375,7 @@
extern int strmatch(const char*, const char*);
extern int strmode(const char*);
extern int strnacmp(const char*, const char*, size_t);
-extern char* strncopy(char*, const char*, size_t);
+extern char* strncopy(char* _AST_RESTRICT, const char* _AST_RESTRICT, size_t);
extern int strnpcmp(const char*, const char*, size_t);
extern double strntod(const char*, size_t, char**);
extern _ast_fltmax_t strntold(const char*, size_t, char**);
diff -r -u original/src/lib/libast/string/stpcpy.c build_restrict/src/lib/libast/string/stpcpy.c
--- src/lib/libast/string/stpcpy.c 2013-08-09 16:43:42.000000000 +0200
+++ src/lib/libast/string/stpcpy.c 2013-08-17 18:09:20.527143900 +0200
@@ -48,7 +48,7 @@
*/

extern char*
-stpcpy(register char* t, register const char* f)
+stpcpy(register char _AST_RESTRICT* t, register const char _AST_RESTRICT* f)
{
if (!f)
return t;
diff -r -u original/src/lib/libast/string/stpncpy.c build_restrict/src/lib/libast/string/stpncpy.c
--- src/lib/libast/string/stpncpy.c 2013-08-14 07:46:52.000000000 +0200
+++ src/lib/libast/string/stpncpy.c 2013-08-17 18:09:31.431304811 +0200
@@ -54,7 +54,7 @@
*/

extern char*
-stpncpy(char *t, const char *f, size_t n)
+stpncpy(char *_AST_RESTRICT t, const char *_AST_RESTRICT f, size_t n)
{
const char* e = f + n;

diff -r -u original/src/lib/libast/string/strcopy.c build_restrict/src/lib/libast/string/strcopy.c
--- src/lib/libast/string/strcopy.c 2012-08-09 09:37:53.000000000 +0200
+++ src/lib/libast/string/strcopy.c 2013-08-17 18:27:41.443472883 +0200
@@ -28,7 +28,7 @@
*/

char*
-strcopy(register char* s, register const char* t)
+strcopy(register char* _AST_RESTRICT s, register const char* _AST_RESTRICT t)
{
if (!t)
return s;
diff -r -u original/src/lib/libast/string/strncopy.c build_restrict/src/lib/libast/string/strncopy.c
--- src/lib/libast/string/strncopy.c 2002-11-18 19:42:21.000000000 +0100
+++ src/lib/libast/string/strncopy.c 2013-08-17 18:28:44.048145275 +0200
@@ -30,7 +30,7 @@
*/

char*
-strncopy(register char* t, register const char* f, size_t n)
+strncopy(register char* _AST_RESTRICT t, register const char* _AST_RESTRICT f, size_t n)
{
register char* e = t + n - 1;
Glenn Fowler
2013-08-19 16:31:46 UTC
Permalink
we will most likely handle "restrict" in a similar way to "const"
to keep the code readable
where
all ast code will use "restrict"
#ifdef magic in ast_common.h will do one of the following
possibly augmented by probe info when nmake is used to build:
(1) nothing -- "restrict" or its expansion will be seen by the compiler
(2) #define restrict __restrict
(3) #define restrict
with (3) being the fallback position
Roland Mainz
2013-09-12 00:29:52 UTC
Permalink
Post by Glenn Fowler
we will most likely handle "restrict" in a similar way to "const"
to keep the code readable
where
all ast code will use "restrict"
#ifdef magic in ast_common.h will do one of the following
(1) nothing -- "restrict" or its expansion will be seen by the compiler
(2) #define restrict __restrict
(3) #define restrict
with (3) being the fallback position
Ok...
... can we do this for the next alpha, please (technically... without
consumers... it should not harm anything (currently) ... right ?) ?

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Roland Mainz
2013-09-30 13:46:55 UTC
Permalink
Post by Roland Mainz
Post by Glenn Fowler
we will most likely handle "restrict" in a similar way to "const"
to keep the code readable
where
all ast code will use "restrict"
#ifdef magic in ast_common.h will do one of the following
(1) nothing -- "restrict" or its expansion will be seen by the compiler
(2) #define restrict __restrict
(3) #define restrict
with (3) being the fallback position
Ok...
... can we do this for the next alpha, please (technically... without
consumers... it should not harm anything (currently) ... right ?) ?
Erm... ping!
... can we do this for the next alpha, please (just the infrastructure
to minimise the risk... and then make step-by-step patches to convert
the possible consumers to claim our 1.6-3.8% performance benefit (this
is the average the clang people measured across all software they
tested with+without |restrict|)) ?

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Continue reading on narkive:
Loading...