diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-13 23:54:56 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-13 23:54:56 +0100 |
| commit | 5b10b24044b3350a19ab3d3c0b37b5e9c12365b1 (patch) | |
| tree | 3f6aa8de29becc5d7511fcca50e6d31982c1b64b /zahl.h | |
| parent | Optimisations (diff) | |
| download | libzahl-5b10b24044b3350a19ab3d3c0b37b5e9c12365b1.tar.gz libzahl-5b10b24044b3350a19ab3d3c0b37b5e9c12365b1.tar.bz2 libzahl-5b10b24044b3350a19ab3d3c0b37b5e9c12365b1.tar.xz | |
Multiple changes:
1) Compile test with -O0, it takes too long otherwise.
2) Add error codes: ZERROR_0_POW_0, ZERROR_0_DIV_0, ZERROR_DIV_0, ZERROR_NEGATIVE.
3) Add workaround for a bug in clang (src/allocator.c).
4) Cleanups.
5) Minor optimisations.
6) Add inclusion guard for zahl.h.
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'zahl.h')
| -rw-r--r-- | zahl.h | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -3,6 +3,9 @@ /* Warning: libzahl is not thread-safe. */ /* Caution: Do not use libzahl for cryptographic applications, use a specialised library. */ +#ifndef ZAHL_H +#define ZAHL_H + #include <stddef.h> #include <setjmp.h> @@ -27,7 +30,11 @@ enum zranddev { FAST_RANDOM = 0, SECURE_RANDOM }; enum zranddist { QUASIUNIFORM = 0, UNIFORM }; enum zerror { - ZERROR_ERRNO_SET = 0 + ZERROR_ERRNO_SET = 0, /* Please refer to errno. */ + ZERROR_0_POW_0, /* Indeterminate form: 0:th power of 0. (Translatable to EDOM.) */ + ZERROR_0_DIV_0, /* Indeterminate form: 0 divided by 0. (Translatable to EDOM.) */ + ZERROR_DIV_0, /* Undefined result: Division by 0. (Translatable to EDOM.) */ + ZERROR_NEGATIVE /* Argument must be non-negative. (Translatable to EDOM or EINVAL.) */ }; @@ -160,7 +167,7 @@ zlsb(z_t a) return SIZE_MAX; for (; !a->chars[i]; i++); i *= 8 * sizeof(zahl_char_t); - i += __builtin_ctzll(a->chars[i]); + i += (size_t)__builtin_ctzll(a->chars[i]); return i; } #else @@ -190,7 +197,7 @@ zbits(z_t a) return 1; while (!a->chars[a->used - 1]) a->used--; /* TODO should not be necessary */ rc = a->used * 8 * sizeof(zahl_char_t); - rc -= __builtin_clzll(a->chars[a->used - 1]); + rc -= (size_t)__builtin_clzll(a->chars[a->used - 1]); return rc; } #else @@ -208,3 +215,6 @@ zbits(z_t a) return rc; } #endif + + +#endif |
