From 9b483673c0c8a52d81127a23788fa4c976f2b10f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 12 Jun 2022 18:48:26 +0200 Subject: Replace to last static inline's with line + extern inline, and fix warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- memsetelem.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'memsetelem.c') diff --git a/memsetelem.c b/memsetelem.c index 32c3f74..75190f2 100644 --- a/memsetelem.c +++ b/memsetelem.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #ifndef TEST @@ -12,37 +12,41 @@ extern inline void *libsimple_memsetelem(void *, const void *, size_t, size_t); int main(void) { - char p_[4096]; - char *p = p_; + _Alignas(8) char buf_[4096]; + _Alignas(8) char *buf = buf_; size_t i; - memset(p, 0, sizeof(p_)); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 0, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 0, 10) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 1, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 2, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 4, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 8, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 16, 0) == p); - assert(libsimple_memsetelem(p, &(uint64_t){~(uint64_t)0}, 3, 0) == p); - assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p); - assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p); - assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p); - assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p); - assert(libsimple_memsetelem(p, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == p); + memset(buf, 0, sizeof(buf_)); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 0, 10) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 1, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 2, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 4, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 8, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 16, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){~(uint64_t)0}, 3, 0) == buf); + assert(libsimple_memsetelem(buf, &(uint8_t){0x09}, 1, 3000) == buf); + assert(libsimple_memsetelem(buf, &(uint16_t){0x0807}, 2, 1000) == buf); + assert(libsimple_memsetelem(buf, &(uint32_t){0x10203040UL}, 4, 300) == buf); + assert(libsimple_memsetelem(buf, &(uint64_t){0x0102030450607080ULL}, 8, 100) == buf); + assert(libsimple_memsetelem(buf, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == buf); + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wcast-align" +#endif for (i = 0; i < 48; i++) - assert(p[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]); + assert(buf[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]); for (; i < 800; i += 8) - assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL); + assert(*(uint64_t *)&buf[i] == 0x0102030450607080ULL); for (; i < 1200; i += 4) - assert(*(uint32_t *)&p[i] == 0x10203040UL); + assert(*(uint32_t *)&buf[i] == 0x10203040UL); for (; i < 2000; i += 2) - assert(*(uint16_t *)&p[i] == 0x0807); + assert(*(uint16_t *)&buf[i] == 0x0807); for (; i < 3000; i++) - assert(p[i] == 0x09); - for (; i < sizeof(p_); i++) - assert(p[i] == 0); + assert(buf[i] == 0x09); + for (; i < sizeof(buf_); i++) + assert(buf[i] == 0); return 0; } -- cgit v1.2.3-70-g09d2