Roland Mainz
2013-08-28 06:22:00 UTC
Hi!
----
Olga Kryzhanovska and Jennifer Pioch dug-out a performance and
footprint killer: The |ast.tmp_*| variables... ;-(
The basic issue looks like this:
- the |ast| structure is a global variable
- accessing it on CPU architectures with only few registers or no
support for complex indirect accesses can quickly exhaust registers
(that's not 100% true... but the number of available registers which
could be used for other stuff becomes... limited)
- typically (for embedded architectures) |ast| is not part of the L1
data cache when other code has been walked for some time. Per Jenny on
ARM CPUs with <= 16k of data cache |ast.tmp_*| were 97.2% times
outside L1 when accessed the first time in a function running a simple
multibyte character test
- The AST macros accessing the |ast.tmp_*| variables look small but
consume more code than writing the same code as |static inline|
function because of the read/write "far" accesses to the |ast.tmp_*|
variables (avoiding accesses to |ast| is not possible but it should be
minimised and preferably restricted to read-only accesses).
Question is... how can be fix this ?
AFAIK one way is to turn the "offending" CPP macros into |static
inline| functions (compilers which do not support |inline| just define
the functions as |static| ... at the expense of producing less
optimised code). The amount of code used is either the same as the CPP
macros or even less because we can use temporary variables on the
stack instead of "far" read/write accesses to the |ast.tmp_*|
structure.
The other advantage would be that without the |ast.tmp_*|-variables
instrumentation tools like "valgrind" or Rational Purify can track
values much better...
I've attached (as "astksh20130814_no_ast_tmp001.diff.txt") a prototype
patch which does this for the |mbchar()| macro (with some ugly mess
caused by the issue that |register| variables don't have an address,
e.g. |&var| doesn't work) which gives an interesting footprint
reduction (note that you have to compile with gcc -Os + use strip(1)
(to remove any extra symbol/debug info stuff) to get valid results (ad
note that padding is likely hiding individual size reduction benefits,
e.g. the code itself may become smaller but the compiler may "pad" ELF
chunks a bit to make sure the size is some kind of multiple of 2**n)):
$ ls -l ./arch/linux.i386-64/bin/ksh*
-rwxr-xr-x 1 test001 users 1844952 Aug 28 07:27
./arch/linux.i386-64/bin/ksh_mbchar_cpp
-rwxr-xr-x 1 test001 users 1841880 Aug 28 07:03
./arch/linux.i386-64/bin/ksh_mbchar_inline
$ print $((1844952 - 1841880))
3072
3072 bytes saved... and killing-off the other |ast.tmp_*| variables
and replacing them with function-local variables may likely yield a
similar code reduction...
----
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/cmd/ksh93/edit/completion.c build_noasttmp/src/cmd/ksh93/edit/completion.c
--- original/src/cmd/ksh93/edit/completion.c 2012-08-03 20:47:02.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/edit/completion.c 2013-08-28 07:05:24.476837824 +0200
@@ -37,7 +37,7 @@
static char *fmtx(Shell_t *shp,const char *string)
{
- register const char *cp = string;
+ const char *cp = string;
register int n,c;
unsigned char *state = (unsigned char*)sh_lexstates[2];
int offset = stktell(shp->stk);
@@ -97,7 +97,7 @@
*/
static char *find_begin(char outbuff[], char *last, int endchar, int *type)
{
- register char *cp=outbuff, *bp, *xp;
+ char *cp=outbuff, *bp, *xp;
register int c,inquote = 0, inassign=0;
int mode=*type;
bp = outbuff;
@@ -208,7 +208,7 @@
{
struct comnod *comptr;
struct argnod *ap;
- register char *out;
+ char *out;
char *av[2], *begin , *dir=0;
int addstar=0, rval=0, var=0, strip=1;
int nomarkdirs = !sh_isoption(ep->sh,SH_MARKDIRS);
diff -r -u original/src/cmd/ksh93/edit/edit.c build_noasttmp/src/cmd/ksh93/edit/edit.c
--- original/src/cmd/ksh93/edit/edit.c 2013-08-02 17:37:12.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/edit/edit.c 2013-08-28 07:06:08.665065251 +0200
@@ -584,7 +584,7 @@
{
Shell_t *shp = ep->sh;
register char *pp;
- register char *last, *prev;
+ char *last, *prev;
char *ppmax;
int myquote = 0;
size_t n;
@@ -1379,7 +1379,7 @@
int ed_internal(const char *src, genchar *dest)
{
- register const unsigned char *cp = (unsigned char *)src;
+ const unsigned char *cp = (unsigned char *)src;
register int c;
register wchar_t *dp = (wchar_t*)dest;
if(dest == (genchar*)roundof(cp-(unsigned char*)0,sizeof(genchar)))
diff -r -u original/src/cmd/ksh93/sh/arith.c build_noasttmp/src/cmd/ksh93/sh/arith.c
--- original/src/cmd/ksh93/sh/arith.c 2013-08-12 16:43:47.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/arith.c 2013-08-28 07:04:19.645571327 +0200
@@ -62,7 +62,7 @@
static Namval_t *scope(register Namval_t *np,register struct lval *lvalue,int assign)
{
register int flag = lvalue->flag;
- register char *sub=0, *cp=(char*)np;
+ char *sub=0, *cp=(char*)np;
register Namval_t *mp;
Shell_t *shp = lvalue->shp;
int flags = HASH_NOSCOPE|HASH_SCOPE|HASH_BUCKET;
diff -r -u original/src/cmd/ksh93/sh/macro.c build_noasttmp/src/cmd/ksh93/sh/macro.c
--- original/src/cmd/ksh93/sh/macro.c 2013-07-31 22:08:40.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/macro.c 2013-08-28 07:07:27.822053070 +0200
@@ -1104,7 +1104,7 @@
{
register int c;
register int type=0; /* M_xxx */
- register char *v,*argp=0;
+ char *v,*argp=0;
register Namval_t *np = NIL(Namval_t*);
register int dolg=0, mode=0;
Lex_t *lp = (Lex_t*)mp->shp->lex_context;
@@ -2655,7 +2655,7 @@
#if SHOPT_MULTIBYTE
if(mbwide())
{
- register const char *str = string, *strmax=string+len;
+ const char *str = string, *strmax=string+len;
register int n=0;
mbinit();
if(len>0)
diff -r -u original/src/cmd/ksh93/sh/name.c build_noasttmp/src/cmd/ksh93/sh/name.c
--- original/src/cmd/ksh93/sh/name.c 2013-08-12 16:33:09.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/name.c 2013-08-28 07:07:51.718256643 +0200
@@ -2151,7 +2151,7 @@
static int ja_size(char *str,int size,int type)
{
- register char *cp = str;
+ char *cp = str;
register int c, n=size;
register int outsize;
register char *oldcp=cp;
diff -r -u original/src/cmd/ksh93/sh/string.c build_noasttmp/src/cmd/ksh93/sh/string.c
--- original/src/cmd/ksh93/sh/string.c 2013-06-12 22:53:57.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/string.c 2013-08-28 07:10:00.752758147 +0200
@@ -294,7 +294,7 @@
*/
static char *sh_fmtcsv(const char *string)
{
- register const char *cp = string;
+ const char *cp = string;
register int c;
int offset;
if(!cp)
@@ -330,7 +330,7 @@
*/
char *sh_fmtstr(const char *string, int quote)
{
- register const char *cp = string, *op;
+ const char *cp = string, *op;
register int c, state, type=quote;
int offset;
if(!cp)
@@ -483,7 +483,7 @@
*/
char *sh_fmtqf(const char *string, int single, int fold)
{
- register const char *cp = string;
+ const char *cp = string;
register const char *bp;
register const char *vp;
register int c;
@@ -684,10 +684,10 @@
}
#if SHOPT_MULTIBYTE
- int sh_strchr(const char *string, register const char *dp)
+ int sh_strchr(const char *string, const char *dp)
{
wchar_t c, d;
- register const char *cp=string;
+ const char *cp=string;
mbinit();
d = mbchar(dp);
mbinit();
@@ -722,9 +722,9 @@
*/
char *sh_checkid(char *str, char *last)
{
- register unsigned char *cp = (unsigned char*)str;
- register unsigned char *v = cp;
- register int c;
+ unsigned char *cp = (unsigned char*)str;
+ unsigned char *v = cp;
+ int c;
if(c=mbchar(cp),isaletter(c))
while(c=mbchar(cp),isaname(c));
if(c==']' && (!last || ((char*)cp==last)))
Only in build_noasttmp/src/cmd/ksh93/tests: arrays.sh
diff -r -u original/src/lib/libast/include/ast.h build_noasttmp/src/lib/libast/include/ast.h
--- original/src/lib/libast/include/ast.h 2013-08-09 17:26:20.000000000 +0200
+++ build_noasttmp/src/lib/libast/include/ast.h 2013-08-28 07:16:32.963513021 +0200
@@ -200,14 +200,46 @@
*/
#define mbmax() (ast.mb_cur_max)
-#define mberr() (ast.tmp_int<0)
#define mbcoll() (ast.mb_xfrm!=0)
#define mbwide() (mbmax()>1)
#define mb2wc(w,p,n) (*ast.mb_towc)(&(w),(char*)(p),(n))
+#if 1
+#define mbchar(p) _mbchar(&(p))
+static inline int _mbchar(char **p)
+{
+ int tmp;
+ wchar_t wc;
+
+ if (mbwide())
+ {
+ char *dp = *p;
+ if ((tmp=(*ast.mb_towc)(&wc, dp, mbmax()))>0)
+ {
+ dp+=tmp;
+ *p=dp;
+ return wc;
+ }
+ else
+ {
+ dp+=ast.mb_sync+1;
+ *p=dp;
+ return tmp;
+ }
+ }
+ else
+ {
+ return *(unsigned char*)((*p)++);
+ }
+}
+
+#define mbnchar(p,n) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
+
+#else
#define mbchar(p) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),mbmax()))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
#define mbnchar(p,n) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
+#endif
#define mbinit() (mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0)
#define mbsize(p) (mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1))
#define mbnsize(p,n) (mbwide()?(*ast.mb_len)((char*)(p),n):((p),1))
diff -r -u original/src/lib/libast/regex/regcoll.c build_noasttmp/src/lib/libast/regex/regcoll.c
--- original/src/lib/libast/regex/regcoll.c 2012-05-11 16:43:14.000000000 +0200
+++ build_noasttmp/src/lib/libast/regex/regcoll.c 2013-08-28 06:47:07.356459448 +0200
@@ -39,7 +39,7 @@
*/
int
-regcollate(register const char* s, char** e, char* buf, size_t size, wchar_t* wc)
+regcollate(const char* s, char** e, char* buf, size_t size, wchar_t* wc)
{
register int c;
register char* b;
diff -r -u original/src/lib/libast/regex/regcomp.c build_noasttmp/src/lib/libast/regex/regcomp.c
--- original/src/lib/libast/regex/regcomp.c 2013-05-31 08:38:29.000000000 +0200
+++ build_noasttmp/src/lib/libast/regex/regcomp.c 2013-08-28 06:47:55.848910629 +0200
@@ -1031,11 +1031,11 @@
static Celt_t*
col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, int ew, int ec)
{
- register char* s;
- register unsigned char* k;
- register unsigned char* e;
- register int c;
- register int cc;
+ char* s;
+ unsigned char * k;
+ unsigned char * e;
+ int c;
+ int cc;
int bt;
int et;
Ckey_t key;
diff -r -u original/src/lib/libast/string/chresc.c build_noasttmp/src/lib/libast/string/chresc.c
--- original/src/lib/libast/string/chresc.c 2013-07-16 20:02:13.000000000 +0200
+++ build_noasttmp/src/lib/libast/string/chresc.c 2013-08-28 06:41:52.603543286 +0200
@@ -39,7 +39,7 @@
#endif
int
-chrexp(register const char* s, char** p, int* m, register int flags)
+chrexp(const char* s, char** p, int* m, register int flags)
{
register const char* q;
register int c;
diff -r -u original/src/lib/libast/string/fmtesc.c build_noasttmp/src/lib/libast/string/fmtesc.c
--- original/src/lib/libast/string/fmtesc.c 2011-01-27 22:20:45.000000000 +0100
+++ build_noasttmp/src/lib/libast/string/fmtesc.c 2013-08-28 06:46:17.186922496 +0200
@@ -47,18 +47,18 @@
char*
fmtquote(const char* as, const char* qb, const char* qe, size_t n, int flags)
{
- register unsigned char* s = (unsigned char*)as;
- register unsigned char* e = s + n;
- register char* b;
- register int c;
- register int m;
- register int escaped;
- register int spaced;
- register int doublequote;
- register int singlequote;
- int shell;
- char* f;
- char* buf;
+ unsigned char * s = (unsigned char*)as;
+ unsigned char * e = s + n;
+ char* b;
+ int c;
+ int m;
+ int escaped;
+ int spaced;
+ int doublequote;
+ int singlequote;
+ int shell;
+ char *f;
+ char *buf;
c = 4 * (n + 1);
if (qb)
diff -r -u original/src/lib/libcmd/join.c build_noasttmp/src/lib/libcmd/join.c
--- original/src/lib/libcmd/join.c 2012-01-10 19:54:21.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/join.c 2013-08-28 06:57:54.183128798 +0200
@@ -298,7 +298,7 @@
register File_t* fp = &jp->file[index];
register Field_t* field = fp->fields;
register Field_t* fieldmax = field + fp->maxfields;
- register char* cp;
+ char* cp;
register int n;
char* tp;
@@ -816,7 +816,7 @@
b_join(int argc, char** argv, Shbltin_t* context)
{
register int n;
- register char* cp;
+ char* cp;
register Join_t* jp;
char* e;
diff -r -u original/src/lib/libcmd/paste.c build_noasttmp/src/lib/libcmd/paste.c
--- original/src/lib/libcmd/paste.c 2012-01-10 19:55:31.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/paste.c 2013-08-28 06:52:05.263509322 +0200
@@ -176,7 +176,7 @@
{
register int n, sflag=0;
register Sfio_t *fp, **streams;
- register char *cp, *delim;
+ char *cp, *delim;
char *ep;
Delim_t *mp;
int dlen, dsiz;
diff -r -u original/src/lib/libcmd/rev.c build_noasttmp/src/lib/libcmd/rev.c
--- original/src/lib/libcmd/rev.c 2012-01-10 19:55:48.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/rev.c 2013-08-28 06:52:37.669147613 +0200
@@ -60,7 +60,7 @@
static int rev_char(Sfio_t *in, Sfio_t *out)
{
register int c;
- register char *ep, *bp, *cp;
+ char *ep, *bp, *cp;
register wchar_t *wp, *xp;
register size_t n;
register size_t w;
diff -r -u original/src/lib/libcmd/uniq.c build_noasttmp/src/lib/libcmd/uniq.c
--- original/src/lib/libcmd/uniq.c 2012-03-08 02:38:36.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/uniq.c 2013-08-28 06:53:11.215842002 +0200
@@ -85,7 +85,7 @@
static int uniq(Sfio_t *fdin, Sfio_t *fdout, int fields, int chars, int width, int mode, int* all, Compare_f compare)
{
register int n, f, outsize=0, mb = mbwide();
- register char *cp, *ep, *mp, *bufp, *outp;
+ char *cp, *ep, *mp, *bufp, *outp;
char *orecp, *sbufp=0, *outbuff;
int reclen,oreclen= -1,count=0,cwidth=0,sep,next;
if(mode&C_FLAG)
diff -r -u original/src/lib/libcmd/wclib.c build_noasttmp/src/lib/libcmd/wclib.c
--- original/src/lib/libcmd/wclib.c 2012-11-22 05:33:44.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/wclib.c 2013-08-28 06:53:55.452076766 +0200
@@ -164,7 +164,7 @@
wc_count(Wc_t *wp, Sfio_t *fd, const char* file)
{
register char* type = wp->type;
- register unsigned char* cp;
+ unsigned char* cp;
register Sfoff_t nbytes;
register Sfoff_t nchars;
register Sfoff_t nwords;
----
Olga Kryzhanovska and Jennifer Pioch dug-out a performance and
footprint killer: The |ast.tmp_*| variables... ;-(
The basic issue looks like this:
- the |ast| structure is a global variable
- accessing it on CPU architectures with only few registers or no
support for complex indirect accesses can quickly exhaust registers
(that's not 100% true... but the number of available registers which
could be used for other stuff becomes... limited)
- typically (for embedded architectures) |ast| is not part of the L1
data cache when other code has been walked for some time. Per Jenny on
ARM CPUs with <= 16k of data cache |ast.tmp_*| were 97.2% times
outside L1 when accessed the first time in a function running a simple
multibyte character test
- The AST macros accessing the |ast.tmp_*| variables look small but
consume more code than writing the same code as |static inline|
function because of the read/write "far" accesses to the |ast.tmp_*|
variables (avoiding accesses to |ast| is not possible but it should be
minimised and preferably restricted to read-only accesses).
Question is... how can be fix this ?
AFAIK one way is to turn the "offending" CPP macros into |static
inline| functions (compilers which do not support |inline| just define
the functions as |static| ... at the expense of producing less
optimised code). The amount of code used is either the same as the CPP
macros or even less because we can use temporary variables on the
stack instead of "far" read/write accesses to the |ast.tmp_*|
structure.
The other advantage would be that without the |ast.tmp_*|-variables
instrumentation tools like "valgrind" or Rational Purify can track
values much better...
I've attached (as "astksh20130814_no_ast_tmp001.diff.txt") a prototype
patch which does this for the |mbchar()| macro (with some ugly mess
caused by the issue that |register| variables don't have an address,
e.g. |&var| doesn't work) which gives an interesting footprint
reduction (note that you have to compile with gcc -Os + use strip(1)
(to remove any extra symbol/debug info stuff) to get valid results (ad
note that padding is likely hiding individual size reduction benefits,
e.g. the code itself may become smaller but the compiler may "pad" ELF
chunks a bit to make sure the size is some kind of multiple of 2**n)):
$ ls -l ./arch/linux.i386-64/bin/ksh*
-rwxr-xr-x 1 test001 users 1844952 Aug 28 07:27
./arch/linux.i386-64/bin/ksh_mbchar_cpp
-rwxr-xr-x 1 test001 users 1841880 Aug 28 07:03
./arch/linux.i386-64/bin/ksh_mbchar_inline
$ print $((1844952 - 1841880))
3072
3072 bytes saved... and killing-off the other |ast.tmp_*| variables
and replacing them with function-local variables may likely yield a
similar code reduction...
----
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/cmd/ksh93/edit/completion.c build_noasttmp/src/cmd/ksh93/edit/completion.c
--- original/src/cmd/ksh93/edit/completion.c 2012-08-03 20:47:02.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/edit/completion.c 2013-08-28 07:05:24.476837824 +0200
@@ -37,7 +37,7 @@
static char *fmtx(Shell_t *shp,const char *string)
{
- register const char *cp = string;
+ const char *cp = string;
register int n,c;
unsigned char *state = (unsigned char*)sh_lexstates[2];
int offset = stktell(shp->stk);
@@ -97,7 +97,7 @@
*/
static char *find_begin(char outbuff[], char *last, int endchar, int *type)
{
- register char *cp=outbuff, *bp, *xp;
+ char *cp=outbuff, *bp, *xp;
register int c,inquote = 0, inassign=0;
int mode=*type;
bp = outbuff;
@@ -208,7 +208,7 @@
{
struct comnod *comptr;
struct argnod *ap;
- register char *out;
+ char *out;
char *av[2], *begin , *dir=0;
int addstar=0, rval=0, var=0, strip=1;
int nomarkdirs = !sh_isoption(ep->sh,SH_MARKDIRS);
diff -r -u original/src/cmd/ksh93/edit/edit.c build_noasttmp/src/cmd/ksh93/edit/edit.c
--- original/src/cmd/ksh93/edit/edit.c 2013-08-02 17:37:12.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/edit/edit.c 2013-08-28 07:06:08.665065251 +0200
@@ -584,7 +584,7 @@
{
Shell_t *shp = ep->sh;
register char *pp;
- register char *last, *prev;
+ char *last, *prev;
char *ppmax;
int myquote = 0;
size_t n;
@@ -1379,7 +1379,7 @@
int ed_internal(const char *src, genchar *dest)
{
- register const unsigned char *cp = (unsigned char *)src;
+ const unsigned char *cp = (unsigned char *)src;
register int c;
register wchar_t *dp = (wchar_t*)dest;
if(dest == (genchar*)roundof(cp-(unsigned char*)0,sizeof(genchar)))
diff -r -u original/src/cmd/ksh93/sh/arith.c build_noasttmp/src/cmd/ksh93/sh/arith.c
--- original/src/cmd/ksh93/sh/arith.c 2013-08-12 16:43:47.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/arith.c 2013-08-28 07:04:19.645571327 +0200
@@ -62,7 +62,7 @@
static Namval_t *scope(register Namval_t *np,register struct lval *lvalue,int assign)
{
register int flag = lvalue->flag;
- register char *sub=0, *cp=(char*)np;
+ char *sub=0, *cp=(char*)np;
register Namval_t *mp;
Shell_t *shp = lvalue->shp;
int flags = HASH_NOSCOPE|HASH_SCOPE|HASH_BUCKET;
diff -r -u original/src/cmd/ksh93/sh/macro.c build_noasttmp/src/cmd/ksh93/sh/macro.c
--- original/src/cmd/ksh93/sh/macro.c 2013-07-31 22:08:40.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/macro.c 2013-08-28 07:07:27.822053070 +0200
@@ -1104,7 +1104,7 @@
{
register int c;
register int type=0; /* M_xxx */
- register char *v,*argp=0;
+ char *v,*argp=0;
register Namval_t *np = NIL(Namval_t*);
register int dolg=0, mode=0;
Lex_t *lp = (Lex_t*)mp->shp->lex_context;
@@ -2655,7 +2655,7 @@
#if SHOPT_MULTIBYTE
if(mbwide())
{
- register const char *str = string, *strmax=string+len;
+ const char *str = string, *strmax=string+len;
register int n=0;
mbinit();
if(len>0)
diff -r -u original/src/cmd/ksh93/sh/name.c build_noasttmp/src/cmd/ksh93/sh/name.c
--- original/src/cmd/ksh93/sh/name.c 2013-08-12 16:33:09.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/name.c 2013-08-28 07:07:51.718256643 +0200
@@ -2151,7 +2151,7 @@
static int ja_size(char *str,int size,int type)
{
- register char *cp = str;
+ char *cp = str;
register int c, n=size;
register int outsize;
register char *oldcp=cp;
diff -r -u original/src/cmd/ksh93/sh/string.c build_noasttmp/src/cmd/ksh93/sh/string.c
--- original/src/cmd/ksh93/sh/string.c 2013-06-12 22:53:57.000000000 +0200
+++ build_noasttmp/src/cmd/ksh93/sh/string.c 2013-08-28 07:10:00.752758147 +0200
@@ -294,7 +294,7 @@
*/
static char *sh_fmtcsv(const char *string)
{
- register const char *cp = string;
+ const char *cp = string;
register int c;
int offset;
if(!cp)
@@ -330,7 +330,7 @@
*/
char *sh_fmtstr(const char *string, int quote)
{
- register const char *cp = string, *op;
+ const char *cp = string, *op;
register int c, state, type=quote;
int offset;
if(!cp)
@@ -483,7 +483,7 @@
*/
char *sh_fmtqf(const char *string, int single, int fold)
{
- register const char *cp = string;
+ const char *cp = string;
register const char *bp;
register const char *vp;
register int c;
@@ -684,10 +684,10 @@
}
#if SHOPT_MULTIBYTE
- int sh_strchr(const char *string, register const char *dp)
+ int sh_strchr(const char *string, const char *dp)
{
wchar_t c, d;
- register const char *cp=string;
+ const char *cp=string;
mbinit();
d = mbchar(dp);
mbinit();
@@ -722,9 +722,9 @@
*/
char *sh_checkid(char *str, char *last)
{
- register unsigned char *cp = (unsigned char*)str;
- register unsigned char *v = cp;
- register int c;
+ unsigned char *cp = (unsigned char*)str;
+ unsigned char *v = cp;
+ int c;
if(c=mbchar(cp),isaletter(c))
while(c=mbchar(cp),isaname(c));
if(c==']' && (!last || ((char*)cp==last)))
Only in build_noasttmp/src/cmd/ksh93/tests: arrays.sh
diff -r -u original/src/lib/libast/include/ast.h build_noasttmp/src/lib/libast/include/ast.h
--- original/src/lib/libast/include/ast.h 2013-08-09 17:26:20.000000000 +0200
+++ build_noasttmp/src/lib/libast/include/ast.h 2013-08-28 07:16:32.963513021 +0200
@@ -200,14 +200,46 @@
*/
#define mbmax() (ast.mb_cur_max)
-#define mberr() (ast.tmp_int<0)
#define mbcoll() (ast.mb_xfrm!=0)
#define mbwide() (mbmax()>1)
#define mb2wc(w,p,n) (*ast.mb_towc)(&(w),(char*)(p),(n))
+#if 1
+#define mbchar(p) _mbchar(&(p))
+static inline int _mbchar(char **p)
+{
+ int tmp;
+ wchar_t wc;
+
+ if (mbwide())
+ {
+ char *dp = *p;
+ if ((tmp=(*ast.mb_towc)(&wc, dp, mbmax()))>0)
+ {
+ dp+=tmp;
+ *p=dp;
+ return wc;
+ }
+ else
+ {
+ dp+=ast.mb_sync+1;
+ *p=dp;
+ return tmp;
+ }
+ }
+ else
+ {
+ return *(unsigned char*)((*p)++);
+ }
+}
+
+#define mbnchar(p,n) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
+
+#else
#define mbchar(p) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),mbmax()))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
#define mbnchar(p,n) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
+#endif
#define mbinit() (mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0)
#define mbsize(p) (mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1))
#define mbnsize(p,n) (mbwide()?(*ast.mb_len)((char*)(p),n):((p),1))
diff -r -u original/src/lib/libast/regex/regcoll.c build_noasttmp/src/lib/libast/regex/regcoll.c
--- original/src/lib/libast/regex/regcoll.c 2012-05-11 16:43:14.000000000 +0200
+++ build_noasttmp/src/lib/libast/regex/regcoll.c 2013-08-28 06:47:07.356459448 +0200
@@ -39,7 +39,7 @@
*/
int
-regcollate(register const char* s, char** e, char* buf, size_t size, wchar_t* wc)
+regcollate(const char* s, char** e, char* buf, size_t size, wchar_t* wc)
{
register int c;
register char* b;
diff -r -u original/src/lib/libast/regex/regcomp.c build_noasttmp/src/lib/libast/regex/regcomp.c
--- original/src/lib/libast/regex/regcomp.c 2013-05-31 08:38:29.000000000 +0200
+++ build_noasttmp/src/lib/libast/regex/regcomp.c 2013-08-28 06:47:55.848910629 +0200
@@ -1031,11 +1031,11 @@
static Celt_t*
col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, int ew, int ec)
{
- register char* s;
- register unsigned char* k;
- register unsigned char* e;
- register int c;
- register int cc;
+ char* s;
+ unsigned char * k;
+ unsigned char * e;
+ int c;
+ int cc;
int bt;
int et;
Ckey_t key;
diff -r -u original/src/lib/libast/string/chresc.c build_noasttmp/src/lib/libast/string/chresc.c
--- original/src/lib/libast/string/chresc.c 2013-07-16 20:02:13.000000000 +0200
+++ build_noasttmp/src/lib/libast/string/chresc.c 2013-08-28 06:41:52.603543286 +0200
@@ -39,7 +39,7 @@
#endif
int
-chrexp(register const char* s, char** p, int* m, register int flags)
+chrexp(const char* s, char** p, int* m, register int flags)
{
register const char* q;
register int c;
diff -r -u original/src/lib/libast/string/fmtesc.c build_noasttmp/src/lib/libast/string/fmtesc.c
--- original/src/lib/libast/string/fmtesc.c 2011-01-27 22:20:45.000000000 +0100
+++ build_noasttmp/src/lib/libast/string/fmtesc.c 2013-08-28 06:46:17.186922496 +0200
@@ -47,18 +47,18 @@
char*
fmtquote(const char* as, const char* qb, const char* qe, size_t n, int flags)
{
- register unsigned char* s = (unsigned char*)as;
- register unsigned char* e = s + n;
- register char* b;
- register int c;
- register int m;
- register int escaped;
- register int spaced;
- register int doublequote;
- register int singlequote;
- int shell;
- char* f;
- char* buf;
+ unsigned char * s = (unsigned char*)as;
+ unsigned char * e = s + n;
+ char* b;
+ int c;
+ int m;
+ int escaped;
+ int spaced;
+ int doublequote;
+ int singlequote;
+ int shell;
+ char *f;
+ char *buf;
c = 4 * (n + 1);
if (qb)
diff -r -u original/src/lib/libcmd/join.c build_noasttmp/src/lib/libcmd/join.c
--- original/src/lib/libcmd/join.c 2012-01-10 19:54:21.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/join.c 2013-08-28 06:57:54.183128798 +0200
@@ -298,7 +298,7 @@
register File_t* fp = &jp->file[index];
register Field_t* field = fp->fields;
register Field_t* fieldmax = field + fp->maxfields;
- register char* cp;
+ char* cp;
register int n;
char* tp;
@@ -816,7 +816,7 @@
b_join(int argc, char** argv, Shbltin_t* context)
{
register int n;
- register char* cp;
+ char* cp;
register Join_t* jp;
char* e;
diff -r -u original/src/lib/libcmd/paste.c build_noasttmp/src/lib/libcmd/paste.c
--- original/src/lib/libcmd/paste.c 2012-01-10 19:55:31.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/paste.c 2013-08-28 06:52:05.263509322 +0200
@@ -176,7 +176,7 @@
{
register int n, sflag=0;
register Sfio_t *fp, **streams;
- register char *cp, *delim;
+ char *cp, *delim;
char *ep;
Delim_t *mp;
int dlen, dsiz;
diff -r -u original/src/lib/libcmd/rev.c build_noasttmp/src/lib/libcmd/rev.c
--- original/src/lib/libcmd/rev.c 2012-01-10 19:55:48.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/rev.c 2013-08-28 06:52:37.669147613 +0200
@@ -60,7 +60,7 @@
static int rev_char(Sfio_t *in, Sfio_t *out)
{
register int c;
- register char *ep, *bp, *cp;
+ char *ep, *bp, *cp;
register wchar_t *wp, *xp;
register size_t n;
register size_t w;
diff -r -u original/src/lib/libcmd/uniq.c build_noasttmp/src/lib/libcmd/uniq.c
--- original/src/lib/libcmd/uniq.c 2012-03-08 02:38:36.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/uniq.c 2013-08-28 06:53:11.215842002 +0200
@@ -85,7 +85,7 @@
static int uniq(Sfio_t *fdin, Sfio_t *fdout, int fields, int chars, int width, int mode, int* all, Compare_f compare)
{
register int n, f, outsize=0, mb = mbwide();
- register char *cp, *ep, *mp, *bufp, *outp;
+ char *cp, *ep, *mp, *bufp, *outp;
char *orecp, *sbufp=0, *outbuff;
int reclen,oreclen= -1,count=0,cwidth=0,sep,next;
if(mode&C_FLAG)
diff -r -u original/src/lib/libcmd/wclib.c build_noasttmp/src/lib/libcmd/wclib.c
--- original/src/lib/libcmd/wclib.c 2012-11-22 05:33:44.000000000 +0100
+++ build_noasttmp/src/lib/libcmd/wclib.c 2013-08-28 06:53:55.452076766 +0200
@@ -164,7 +164,7 @@
wc_count(Wc_t *wp, Sfio_t *fd, const char* file)
{
register char* type = wp->type;
- register unsigned char* cp;
+ unsigned char* cp;
register Sfoff_t nbytes;
register Sfoff_t nchars;
register Sfoff_t nwords;