String Macros to Replace Library Run Time Calls #ifdef VAXC #pragma builtins #ifndef MIN #define MIN(a, b) (((a) < (b)) ? a : b) #endif #define strlen(cs) (0xFFFF - _LOCC('\0', 0xFFFF, cs)) #define strcpy(s, ct) (_MOVC3(strlen(ct) + 1, ct, s), s) #define strncpy(s, ct, n) (_MOVC5(MIN(n, ((n) - _LOCC('\0', n, ct)) + 1),\ ct, '\0', n, s), s) #define strchr(cs, c) (_LOCC(c, strlen(cs), (char *)cs) ?\ (char *)_READ_GPR(1) : (char *)NULL) #define strcat(s, ct) (_MOVC3(strlen(ct) + 1, ct, s + strlen(s)), s) #define strncat(s, ct, n) (_MOVC5(MIN(n, ((n) - _LOCC('\0', n, ct))), ct,\ '\0', (MIN(n, ((n) - _LOCC('\0', n, ct))) + 1),\ s + strlen(s)), s) #define memcpy(s, ct, n) (_MOVC3(n, (char *)ct, (char *)s), s) #define memmove(s, ct, n) (_MOVC3(n, (char *)ct, (char *)s), s) #define memset(s, c, n) (_MOVC5(0, (char *)_READ_GPR(14), c, n,\ (char *)s), s) #define memchr(cs, c, n) (_LOCC(c, n, (char *)cs) ?\ (void *)_READ_GPR(1) : NULL) #endif /* VAXC */ Example run used to generate strcopy statistics $ $ type strcpy1.c #include main( ) { static const char s[] = "Test string"; char t[80]; register i; for (i = 0; i < 500000; i++) strcpy(t, s); return; } $ $ cc strcpy1 $ lin strcpy1 + sys$input:/options sys$share:vaxcrtl.exe/share $ $ type strcpy2.c #include #include "strmac.h" main( ) { static const char s[] = "Test string"; char t[80]; register i; for (i = 0; i < 500000; i++) strcpy(t, s); return; } $ $ cc strcpy2 $ lin strcpy2 + sys$input:/options sys$share:vaxcrtl.exe/share $ $ show status Status on 22-MAY-1991 22:01:26.68 Elapsed CPU : 0 00:00:05.79 Buff. I/O : 175 Cur. ws. : 8196 Open files : 2 Dir. I/O : 117 Phys. Mem. : 373 Page Faults : 1815 $ $ run strcpy1 $ show status Status on 22-MAY-1991 22:01:38.00 Elapsed CPU : 0 00:00:16.80 Buff. I/O : 182 Cur. ws. : 8196 Open files : 2 Dir. I/O : 118 Phys. Mem. : 378 Page Faults : 1883 $ $ run strcpy2 $ show status Status on 22-MAY-1991 22:01:43.51 Elapsed CPU : 0 00:00:22.09 Buff. I/O : 189 Cur. ws. : 8196 Open files : 2 Dir. I/O : 120 Phys. Mem. : 378 Page Faults : 1945 $ Command file to generate statistics $ set verify $ $ type strcpy1.c $ cc strcpy1 $ lin strcpy1 + sys$input:/options sys$share:vaxcrtl.exe/share $ $ type strcpy2.c $ cc strcpy2 $ lin strcpy2 + sys$input:/options sys$share:vaxcrtl.exe/share $ $ show status $ $ run strcpy1 $ show status $ $ run strcpy2 $ show status $ $ exit C file with macro definitions #ifdef VAXC #pragma builtins #ifndef MIN #define MIN(a, b) (((a) < (b)) ? a : b) #endif #define strlen(cs) (0xFFFF - _LOCC('\0', 0xFFFF, cs)) #define strcpy(s, ct) (_MOVC3(strlen(ct) + 1, ct, s), s) #define strncpy(s, ct, n) (_MOVC5(MIN(n, (n - _LOCC('\0', n, ct)) + 1),\ ct, '\0', n, s), s) #define strchr(cs, c) (_LOCC(c, strlen(cs), (char *)cs) ?\ (char *)_READ_GPR(1) : (char *)NULL) #define strcat(s, ct) (_MOVC3(strlen(ct) + 1, ct, s + strlen(s)), s) #define strncat(s, ct, n) (_MOVC5(MIN(n, (n - _LOCC('\0', n, ct))), ct,\ '\0', (MIN(n, (n - _LOCC('\0', n, ct))) + 1),\ s + strlen(s)), s) #define memcpy(s, ct, n) (_MOVC3(n, (char *)ct, (char *)s), s) #define memmove(s, ct, n) (_MOVC3(n, (char *)ct, (char *)s), s) #define memset(s, c, n) (_MOVC5(0, (char *)_READ_GPR(14), c, n,(char *)s), s) #define memchr(cs, c, n) (_LOCC(c, n, (char *)cs) ? (void *)_READ_GPR(1) : NULL) #endif /* VAXC */ C test file 1 #include main( ) { static const char s[] = "Test string"; auto char s[80]; register char *p; register int i; for (i = 0;i <500000;i++) p=strcpy(s,ct); return; } C test file 2 #include #include "strmac.h" main( ) { static const char ct[] = "Test string"; auto char s[80]; register char *p; register int i; for (i = 0;i<500000;i++) p=strcpy(s,ct); return; }