diff options
author | Michael Jennings <mej@lbl.gov> | 2013-03-05 13:32:22 -0800 |
---|---|---|
committer | Michael Jennings <mej@lbl.gov> | 2013-03-05 13:32:22 -0800 |
commit | 09bcd1eaf51113439da2fad8a37c42725a37c8f4 (patch) | |
tree | 2abf9de9f6870fcd8e7257d83d42315e08f59bfc | |
parent | 9d0be7b7d259415771e22565fe29bafe52df3606 (diff) | |
download | libast-09bcd1eaf51113439da2fad8a37c42725a37c8f4.tar.gz |
The MEMSET() macro is now an order of magnitude *slower* than glibc.
It has been removed and relegated to the annals of SCM history.
-rw-r--r-- | include/libast.h | 70 | ||||
-rw-r--r-- | src/array.c | 2 | ||||
-rw-r--r-- | src/conf.c | 10 | ||||
-rw-r--r-- | src/pthreads.c | 2 | ||||
-rw-r--r-- | test/perf.c | 2 | ||||
-rw-r--r-- | test/perf.h | 50 | ||||
-rw-r--r-- | test/test.c | 12 |
7 files changed, 59 insertions, 89 deletions
diff --git a/include/libast.h b/include/libast.h index 8d243f1..cf22050 100644 --- a/include/libast.h +++ b/include/libast.h @@ -1257,76 +1257,6 @@ extern int re_exec(); # define GC_DUMP() NOP #endif -/* Fast memset() macro contributed by vendu */ -#if !defined(SIZEOF_LONG) || (SIZEOF_LONG == 8) -/** UNDOCUMENTED */ -# define MEMSET_LONG() (l |= l<<32) -#else -/** UNDOCUMENTED */ -# define MEMSET_LONG() NOP -#endif - -/** - * @def MEMSET(s, c, count) - * Initialize a memory region to a particular value. - * - * This macro is a replacement for the libc function memset(). It - * initializes the memory region pointed to by @a s to the value - * specified by @a c. The size of the memory region is specified by - * @a count. Note that @a c must be a byte (char) value. - * - * This macro has been optimized to set as many bytes simultaneously as - * the architecture can handle, so it should offer superior - * performance to libc's memset() function. - * - * @param s A pointer to the memory region to initialize. - * @param c The value to which all bytes in the block will be - * set. - * @param count The size, in bytes, of the memory region. - * @see @link DOXGRP_MEM Memory Management Subsystem @endlink - * @ingroup DOXGRP_MEM - */ -#define MEMSET(s, c, count) do { \ - char *end = (char *)(s) + (count); \ - long l; \ - long *l_dest = (long *)(s); \ - char *c_dest; \ - \ - if (!(s)) { \ - break; \ - } \ - /* areas of less than 4 * sizeof(long) are set in 1-byte chunks. */ \ - if (((unsigned long) count) >= 4 * sizeof(long)) { \ - /* fill l with c. */ \ - l = (c) | (c)<<8; \ - l |= l<<16; \ - MEMSET_LONG(); \ - \ - /* fill in 1-byte chunks until boundary of long is reached. */ \ - if ((unsigned long)l_dest & (unsigned long)(sizeof(long) -1)) { \ - c_dest = (char *)l_dest; \ - while ((unsigned long)c_dest & (unsigned long)(sizeof(long) -1)) { \ - *(c_dest++) = (c); \ - } \ - l_dest = (long *)c_dest; \ - } \ - \ - /* fill in long-size chunks as long as possible. */ \ - while (((unsigned long) (end - (char *)l_dest)) >= sizeof(long)) { \ - *(l_dest++) = l; \ - } \ - } \ - \ - /* fill the tail in 1-byte chunks. */ \ - if ((char *)l_dest < end) { \ - c_dest = (char *)l_dest; \ - *(c_dest++) = (c); \ - while (c_dest < end) { \ - *(c_dest++) = (c); \ - } \ - } \ - } while (0) - /******************************* STRINGS GOOP *********************************/ diff --git a/src/array.c b/src/array.c index 55fc532..f32a7b0 100644 --- a/src/array.c +++ b/src/array.c @@ -683,7 +683,7 @@ spif_array_insert_at(spif_array_t self, spif_obj_t obj, spif_listidx_t idx) } else if (left < 0) { /* NULL out the new gap in the list. */ left = -left; - MEMSET(self->items + (idx - left), 0, sizeof(spif_obj_t) * left); + memset(self->items + (idx - left), 0, sizeof(spif_obj_t) * left); } self->items[idx] = obj; self->len++; @@ -74,7 +74,7 @@ spifconf_init_subsystem(void) ctx_cnt = 20; ctx_idx = 0; context = (ctx_t *) MALLOC(sizeof(ctx_t) * ctx_cnt); - MEMSET(context, 0, sizeof(ctx_t) * ctx_cnt); + memset(context, 0, sizeof(ctx_t) * ctx_cnt); context[0].name = (spif_charptr_t) STRDUP("null"); context[0].handler = parse_null; @@ -82,19 +82,19 @@ spifconf_init_subsystem(void) ctx_state_cnt = 20; ctx_state_idx = 0; ctx_state = (ctx_state_t *) MALLOC(sizeof(ctx_state_t) * ctx_state_cnt); - MEMSET(ctx_state, 0, sizeof(ctx_state_t) * ctx_state_cnt); + memset(ctx_state, 0, sizeof(ctx_state_t) * ctx_state_cnt); /* Initialize the file state stack */ fstate_cnt = 10; fstate_idx = 0; fstate = (fstate_t *) MALLOC(sizeof(fstate_t) * fstate_cnt); - MEMSET(fstate, 0, sizeof(fstate_t) * fstate_cnt); + memset(fstate, 0, sizeof(fstate_t) * fstate_cnt); /* Initialize the builtin function table */ builtin_cnt = 10; builtin_idx = 0; builtins = (spifconf_func_t *) MALLOC(sizeof(spifconf_func_t) * builtin_cnt); - MEMSET(builtins, 0, sizeof(spifconf_func_t) * builtin_cnt); + memset(builtins, 0, sizeof(spifconf_func_t) * builtin_cnt); /* Register the omni-present builtin functions */ spifconf_register_builtin("appname", builtin_appname); @@ -203,7 +203,7 @@ spifconf_new_var(void) spifconf_var_t *v; v = (spifconf_var_t *) MALLOC(sizeof(spifconf_var_t)); - MEMSET(v, 0, sizeof(spifconf_var_t)); + memset(v, 0, sizeof(spifconf_var_t)); return v; } diff --git a/src/pthreads.c b/src/pthreads.c index 2fe76d6..5948e16 100644 --- a/src/pthreads.c +++ b/src/pthreads.c @@ -343,7 +343,7 @@ spif_pthreads_tls_calloc(spif_pthreads_t self, size_t count, size_t size) handle = spif_pthreads_tls_malloc(self, count * size); data = spif_pthreads_tls_get(self, handle); - MEMSET(data, 0, count * size); + memset(data, 0, count * size); return handle; } diff --git a/test/perf.c b/test/perf.c index 038dcd0..c0e9f11 100644 --- a/test/perf.c +++ b/test/perf.c @@ -680,7 +680,7 @@ perf_url(void) spif_charptr_t tmp3 = "/path/to/some/file.jpg"; spif_charptr_t tmp4 = "pop3://dummy:moo@pop.nowhere.com:110"; - PERF_SET_REPS(100); + PERF_SET_REPS(10); PERF_BEGIN("spif_url_new_from_ptr() function"); PERF_TEST(testurl = spif_url_new_from_ptr(tmp1); spif_url_del(testurl);); diff --git a/test/perf.h b/test/perf.h index 625455a..fff2f3a 100644 --- a/test/perf.h +++ b/test/perf.h @@ -24,6 +24,56 @@ #ifndef _LIBAST_PERF_H_ # define _LIBAST_PERF_H_ +/* "Fast" memset() macro contributed by vendu. Now an order of magnitude + * slower than glibc, so it's only included here for performance testing + * in the future. It very likely should not be used. + */ +#if !defined(SIZEOF_LONG) || (SIZEOF_LONG == 8) +# define MEMSET_LONG() (l |= l<<32) +#else +# define MEMSET_LONG() NOP +#endif +#define MEMSET(s, c, count) do { \ + char *end = (char *)(s) + (count); \ + long l; \ + long *l_dest = (long *)(s); \ + char *c_dest; \ + \ + if (!(s)) { \ + break; \ + } \ + /* areas of less than 4 * sizeof(long) are set in 1-byte chunks. */ \ + if (((unsigned long) count) >= 4 * sizeof(long)) { \ + /* fill l with c. */ \ + l = (c) | (c)<<8; \ + l |= l<<16; \ + MEMSET_LONG(); \ + \ + /* fill in 1-byte chunks until boundary of long is reached. */ \ + if ((unsigned long)l_dest & (unsigned long)(sizeof(long) -1)) { \ + c_dest = (char *)l_dest; \ + while ((unsigned long)c_dest & (unsigned long)(sizeof(long) -1)) { \ + *(c_dest++) = (c); \ + } \ + l_dest = (long *)c_dest; \ + } \ + \ + /* fill in long-size chunks as long as possible. */ \ + while (((unsigned long) (end - (char *)l_dest)) >= sizeof(long)) { \ + *(l_dest++) = l; \ + } \ + } \ + \ + /* fill the tail in 1-byte chunks. */ \ + if ((char *)l_dest < end) { \ + c_dest = (char *)l_dest; \ + *(c_dest++) = (c); \ + while (c_dest < end) { \ + *(c_dest++) = (c); \ + } \ + } \ + } while (0) + # define PERF_SET_REPS(c) do {rep_cnt = (c) * rep_mult; if (rep_cnt < (c)) {rep_cnt = (size_t) -1;}} while (0) # define TDIFF(t1, t2) (((t2).tv_sec + ((double) (t2).tv_usec / 1000000.0)) \ - ((t1).tv_sec + ((double) (t1).tv_usec / 1000000.0))) diff --git a/test/test.c b/test/test.c index 1fdff41..16d2a18 100644 --- a/test/test.c +++ b/test/test.c @@ -60,16 +60,6 @@ test_macros(void) unsigned long sl1 = 0x98765432, sl2 = 0xffeeddff; void *vp1 = &sc1, *vp2 = &sc2; - TEST_BEGIN("MEMSET() macro"); - MEMSET(memset_test, '!', CONST_STRLEN(memset_test)); - TEST_FAIL_IF(strcmp((char *) memset_test, "!!!!!!!!!!!!!!!!!!!!!!!!!!")); - MEMSET(memset_test + 3, '*', 14); - TEST_FAIL_IF(strcmp((char *) memset_test, "!!!**************!!!!!!!!!")); - MEMSET(memset_test, '&', 0 ); - TEST_FAIL_IF(strcmp((char *) memset_test, "!!!**************!!!!!!!!!")); - MEMSET((spif_charptr_t) NULL, '_', CONST_STRLEN(memset_test)); - TEST_PASS(); - TEST_BEGIN("SWAP() macro"); SWAP(sc1, sc2); SWAP(si1, si2); @@ -2709,7 +2699,7 @@ test_hash_functions(void) && (key_length % 4)) { continue; } - MEMSET(buff, 0, sizeof(buff)); + memset(buff, 0, sizeof(buff)); if (hash_func == spifhash_jenkins32) { ref_hash = hash_func(pbuff, key_length / 4, 1); |