diff options
| -rw-r--r-- | doc/Examples/PakReader.c | 28 | ||||
| -rw-r--r-- | doc/HowTo/PakReader.md | 12 | ||||
| -rw-r--r-- | doc/Manual/en/BH_Args.pod | 2 | ||||
| -rw-r--r-- | doc/Manual/ru/BH_Args.pod | 2 | ||||
| -rw-r--r-- | src/Algo.c | 42 | ||||
| -rw-r--r-- | src/Args.c | 48 | ||||
| -rw-r--r-- | src/Hashmap.c | 32 | ||||
| -rw-r--r-- | src/Platform/Posix/Thread.c | 16 | ||||
| -rw-r--r-- | src/Platform/Posix/Tss.c | 12 | ||||
| -rw-r--r-- | src/Platform/Win32/Thread.c | 12 | ||||
| -rw-r--r-- | src/Platform/Win32/Tss.c | 12 | ||||
| -rw-r--r-- | src/Queue.c | 14 | ||||
| -rw-r--r-- | src/String/Float.c | 96 | ||||
| -rw-r--r-- | src/String/Inline/Mpi.h | 74 | ||||
| -rw-r--r-- | unit/src/Unit.c | 4 |
15 files changed, 203 insertions, 203 deletions
diff --git a/doc/Examples/PakReader.c b/doc/Examples/PakReader.c index 4a8cca1..1fc4e11 100644 --- a/doc/Examples/PakReader.c +++ b/doc/Examples/PakReader.c @@ -27,7 +27,7 @@ typedef struct PakEntry } PakEntry; -static int ParseHeader(BH_IO *io, +static int parseHeader(BH_IO *io, PakHeader *header) { char buffer[HEADER_SIZE]; @@ -47,7 +47,7 @@ static int ParseHeader(BH_IO *io, } -static int ParseEntry(BH_IO *io, +static int parseEntry(BH_IO *io, PakEntry *entry) { char buffer[ENTRY_SIZE]; @@ -84,14 +84,14 @@ static BH_ArgsOption options[] = { }; -static void PrintHelp(void) +static void printHelp(void) { printf("Usage: PakReader [options...] <file>\n"); BH_ArgsHelp(options, 0); } -static int OptionsCallback(int key, +static int optionsCallback(int key, char *arg, void *data) { @@ -101,7 +101,7 @@ static int OptionsCallback(int key, { case BH_ARGS_UNKNOWN: break; case BH_ARGS_ARGUMENT: if (!config->file) config->file = arg; break; - case 'h': PrintHelp(); exit(0); + case 'h': printHelp(); exit(0); case 'l': config->list = 1; break; case 'i': config->input = arg; break; case 'o': config->output = arg; break; @@ -112,7 +112,7 @@ static int OptionsCallback(int key, /* Copy data between two IO */ -static int CopyData(BH_IO *from, +static int copyData(BH_IO *from, BH_IO *to, size_t size) { @@ -137,7 +137,7 @@ static int CopyData(BH_IO *from, /* Process pack (list files or extract file) */ -static int ProcessPack(Config *config, +static int processPack(Config *config, BH_IO *io) { PakHeader header; @@ -146,7 +146,7 @@ static int ProcessPack(Config *config, size_t i; /* Read header and seek to begging of the file table */ - if (ParseHeader(io, &header)) + if (parseHeader(io, &header)) return BH_ERROR; if (BH_IOSeek(io, header.offset, BH_IO_SEEK_SET)) @@ -155,7 +155,7 @@ static int ProcessPack(Config *config, /* Parse and output entries */ for (i = header.size / 64; i; i--) { - if (ParseEntry(io, &entry)) + if (parseEntry(io, &entry)) return BH_ERROR; if (config->list) @@ -167,7 +167,7 @@ static int ProcessPack(Config *config, output = BH_FileNew(config->output, BH_FILE_WRITE | BH_FILE_TRUNCATE, NULL); if (!output || BH_IOSeek(io, entry.offset, BH_IO_SEEK_SET) || - CopyData(io, output, entry.size)) + copyData(io, output, entry.size)) { BH_IOFree(output); return BH_ERROR; @@ -193,9 +193,9 @@ int main(int argc, char **argv) /* Parse arguments */ memset(&config, 0, sizeof(config)); - if (BH_ArgsParse(argc, argv, options, OptionsCallback, &config) || !config.file) + if (BH_ArgsParse(argc, argv, options, optionsCallback, &config) || !config.file) { - PrintHelp(); + printHelp(); return -1; } @@ -203,7 +203,7 @@ int main(int argc, char **argv) if (!config.list && (!config.input || !config.output)) { printf("Specify input and output files\n"); - PrintHelp(); + printHelp(); return -1; } @@ -215,7 +215,7 @@ int main(int argc, char **argv) return -1; } - result = ProcessPack(&config, io); + result = processPack(&config, io); BH_IOFree(io); return result; diff --git a/doc/HowTo/PakReader.md b/doc/HowTo/PakReader.md index fb99796..8ea0f9f 100644 --- a/doc/HowTo/PakReader.md +++ b/doc/HowTo/PakReader.md @@ -222,7 +222,7 @@ typedef struct PakEntry } PakEntry; -static int ParseHeader(BH_IO *io, +static int parseHeader(BH_IO *io, PakHeader *header) { char buffer[HEADER_SIZE]; @@ -242,7 +242,7 @@ static int ParseHeader(BH_IO *io, } -static int ParseEntry(BH_IO *io, +static int parseEntry(BH_IO *io, PakEntry *entry) { char buffer[ENTRY_SIZE]; @@ -279,14 +279,14 @@ static BH_ArgsOption options[] = { }; -static void PrintHelp(void) +static void printHelp(void) { printf("Usage: PakReader [options...] <file>\n"); BH_ArgsHelp(options, 0); } -static int OptionsCallback(int key, +static int optionsCallback(int key, char *arg, void *data) { @@ -307,7 +307,7 @@ static int OptionsCallback(int key, /* Copy data between two IO */ -static int CopyData(BH_IO *from, +static int copyData(BH_IO *from, BH_IO *to, size_t size) { @@ -332,7 +332,7 @@ static int CopyData(BH_IO *from, /* Process pack (list files or extract file) */ -static int ProcessPack(Config *config, +static int processPack(Config *config, BH_IO *io) { PakHeader header; diff --git a/doc/Manual/en/BH_Args.pod b/doc/Manual/en/BH_Args.pod index cd3d633..3794640 100644 --- a/doc/Manual/en/BH_Args.pod +++ b/doc/Manual/en/BH_Args.pod @@ -19,7 +19,7 @@ BH_Args - command line argument processing {0, NULL, 0, NULL} }; - static int OptionsCallback(int key, + static int optionsCallback(int key, char *arg, void *data) { diff --git a/doc/Manual/ru/BH_Args.pod b/doc/Manual/ru/BH_Args.pod index cf4ee3d..dd130e3 100644 --- a/doc/Manual/ru/BH_Args.pod +++ b/doc/Manual/ru/BH_Args.pod @@ -19,7 +19,7 @@ BH_Args - обработка аргументов командной строк {0, NULL, 0, NULL} }; - static int OptionsCallback(int key, + static int optionsCallback(int key, char *arg, void *data) { @@ -77,10 +77,10 @@ void *BH_Partition(void *pivot, #if 0 -static void BH_SortInsert(void *array, - size_t size, - size_t element, - BH_EqualCallback equal) +static void sortInsert(void *array, + size_t size, + size_t element, + BH_EqualCallback equal) { size_t i, j; @@ -105,10 +105,10 @@ static void BH_SortInsert(void *array, #endif -static void BH_SortShell(void *array, - size_t size, - size_t element, - BH_EqualCallback equal) +static void sortShell(void *array, + size_t size, + size_t element, + BH_EqualCallback equal) { static const size_t gaps[10] = {1750, 701, 301, 132, 57, 23, 10, 4, 1, 0}; const size_t *gap; @@ -136,10 +136,10 @@ static void BH_SortShell(void *array, } -static void BH_SortHeap(void *array, - size_t size, - size_t element, - BH_EqualCallback equal) +static void sortHeap(void *array, + size_t size, + size_t element, + BH_EqualCallback equal) { size_t i; @@ -149,11 +149,11 @@ static void BH_SortHeap(void *array, } -static void BH_SortIntroR(void *array, - size_t size, - size_t element, - BH_EqualCallback equal, - size_t depth) +static void sortIntroR(void *array, + size_t size, + size_t element, + BH_EqualCallback equal, + size_t depth) { /* Introsort (with manual tail call optimization) */ while (1) @@ -163,13 +163,13 @@ static void BH_SortIntroR(void *array, if (size < 16) { /* There are less then 16 elements left - use Shell/Insert sort */ - BH_SortShell(array, size, element, equal); + sortShell(array, size, element, equal); return; } else if (!depth) { /* Max depth reached - use heap sort */ - BH_SortHeap(array, size, element, equal); + sortHeap(array, size, element, equal); return; } @@ -202,7 +202,7 @@ static void BH_SortIntroR(void *array, middle = BH_Partition(pivot, array, size, element, equal); /* Recursive call into first half */ - BH_SortIntroR(array, (middle - start) / element, element, equal, depth - 1); + sortIntroR(array, (middle - start) / element, element, equal, depth - 1); /* Setup array and size for the second half */ array = middle; @@ -229,7 +229,7 @@ void BH_Sort(void *array, } /* Call main sorting function */ - BH_SortIntroR(array, size, element, equal, depth); + sortIntroR(array, size, element, equal, depth); } @@ -5,14 +5,14 @@ #include <memory.h> -static int BH_ArgsExtractArg(int argc, - char **argv, - BH_ArgsOption *option, - BH_ArgsCallback callback, - void *data, - int *i, - int isLong, - char *next) +static int extractArg(int argc, + char **argv, + BH_ArgsOption *option, + BH_ArgsCallback callback, + void *data, + int *i, + int isLong, + char *next) { if (isLong && *next == '=') return callback(option->key, next + 1, data); @@ -30,12 +30,12 @@ static int BH_ArgsExtractArg(int argc, } -static int BH_ArgsParseShort(int argc, - char **argv, - BH_ArgsOption *options, - BH_ArgsCallback callback, - void *data, - int *i) +static int parseShort(int argc, + char **argv, + BH_ArgsOption *options, + BH_ArgsCallback callback, + void *data, + int *i) { char *symbol; BH_ArgsOption *option; @@ -49,7 +49,7 @@ static int BH_ArgsParseShort(int argc, continue; if (option->flags & BH_ARGS_VALUE) - return BH_ArgsExtractArg(argc, argv, option, callback, data, i, 0, symbol + 1); + return extractArg(argc, argv, option, callback, data, i, 0, symbol + 1); if (callback(option->key, NULL, data)) return BH_ERROR; @@ -69,12 +69,12 @@ static int BH_ArgsParseShort(int argc, } -static int BH_ArgsParseLong(int argc, - char **argv, - BH_ArgsOption *options, - BH_ArgsCallback callback, - void *data, - int *i) +static int parseLong(int argc, + char **argv, + BH_ArgsOption *options, + BH_ArgsCallback callback, + void *data, + int *i) { char *start, *end; BH_ArgsOption *option; @@ -98,7 +98,7 @@ static int BH_ArgsParseLong(int argc, continue; if (option->flags & BH_ARGS_VALUE) - return BH_ArgsExtractArg(argc, argv, option, callback, data, i, 1, end); + return extractArg(argc, argv, option, callback, data, i, 1, end); return callback(option->key, NULL, data); } @@ -128,13 +128,13 @@ int BH_ArgsParse(int argc, /* Parse ingore, short or long option */ if (arg[1] == '-') { - if (arg[2] && BH_ArgsParseLong(argc, argv, options, callback, data, &i)) + if (arg[2] && parseLong(argc, argv, options, callback, data, &i)) return BH_ERROR; else if (!arg[2]) ignoreRest = 1; } - else if (arg[1] && BH_ArgsParseShort(argc, argv, options, callback, data, &i)) + else if (arg[1] && parseShort(argc, argv, options, callback, data, &i)) return BH_ERROR; i++; diff --git a/src/Hashmap.c b/src/Hashmap.c index 9f58abd..0bc5e5f 100644 --- a/src/Hashmap.c +++ b/src/Hashmap.c @@ -23,9 +23,9 @@ struct BH_Hashmap }; -static void BH_HashmapInit(BH_Hashmap *hashmap, - BH_EqualCallback equal, - BH_HashCallback hash) +static void hashmapInit(BH_Hashmap *hashmap, + BH_EqualCallback equal, + BH_HashCallback hash) { memset(hashmap, 0, sizeof(*hashmap)); hashmap->factor = 0.75f; @@ -34,7 +34,7 @@ static void BH_HashmapInit(BH_Hashmap *hashmap, } -static void BH_HashmapDestroy(BH_Hashmap *hashmap) +static void hashmapDestroy(BH_Hashmap *hashmap) { if (hashmap->capacity) { @@ -44,10 +44,10 @@ static void BH_HashmapDestroy(BH_Hashmap *hashmap) } -static int BH_CalcCapacity(size_t size, - float factor, - size_t *capacity, - size_t *threshold) +static int calcCapacity(size_t size, + float factor, + size_t *capacity, + size_t *threshold) { /* Check if we need any capacity at all */ if (!size) @@ -78,8 +78,8 @@ static int BH_CalcCapacity(size_t size, } -static void BH_CopyHashmap(BH_Hashmap *dest, - BH_Hashmap *src) +static void copyHashmap(BH_Hashmap *dest, + BH_Hashmap *src) { void *iter; @@ -105,7 +105,7 @@ BH_Hashmap *BH_HashmapNew(BH_EqualCallback equal, result = malloc(sizeof(*result)); if (result) - BH_HashmapInit(result, equal, hash); + hashmapInit(result, equal, hash); return result; } @@ -113,7 +113,7 @@ BH_Hashmap *BH_HashmapNew(BH_EqualCallback equal, void BH_HashmapFree(BH_Hashmap *hashmap) { - BH_HashmapDestroy(hashmap); + hashmapDestroy(hashmap); free(hashmap); } @@ -137,7 +137,7 @@ int BH_HashmapReserve(BH_Hashmap *hashmap, size = hashmap->size; /* Calculate new capacity */ - if (BH_CalcCapacity(size, hashmap->factor, &capacity, &threshold)) + if (calcCapacity(size, hashmap->factor, &capacity, &threshold)) return BH_OOM; /* Prevent same size reallocation */ @@ -145,7 +145,7 @@ int BH_HashmapReserve(BH_Hashmap *hashmap, return BH_OK; /* Initialize new hashmap */ - BH_HashmapInit(&other, hashmap->equal, hashmap->hash); + hashmapInit(&other, hashmap->equal, hashmap->hash); other.factor = hashmap->factor; if (capacity) @@ -170,11 +170,11 @@ int BH_HashmapReserve(BH_Hashmap *hashmap, memset(other.psls, 0, sizeof(size_t) * other.capacity); /* Copy data from old hashmap to the new hashmap */ - BH_CopyHashmap(&other, hashmap); + copyHashmap(&other, hashmap); } /* Swap hashmaps */ - BH_HashmapDestroy(hashmap); + hashmapDestroy(hashmap); *hashmap = other; return BH_OK; } diff --git a/src/Platform/Posix/Thread.c b/src/Platform/Posix/Thread.c index 21a0b14..2c249d8 100644 --- a/src/Platform/Posix/Thread.c +++ b/src/Platform/Posix/Thread.c @@ -11,7 +11,7 @@ struct BH_ThreadContext }; -static void *BH_ThreadRun(void *context) +static void *threadRun(void *context) { BH_ThreadCallback callback; void *data; @@ -27,10 +27,10 @@ static void *BH_ThreadRun(void *context) } -static int BH_ThreadInit(BH_Thread *thread, - size_t stack, - BH_ThreadCallback callback, - void *data) +static int threadInit(BH_Thread *thread, + size_t stack, + BH_ThreadCallback callback, + void *data) { struct BH_ThreadContext *context; pthread_attr_t attributes; @@ -46,13 +46,13 @@ static int BH_ThreadInit(BH_Thread *thread, pthread_attr_init(&attributes); if (!stack) - result = pthread_create(&thread->handle, NULL, BH_ThreadRun, context); + result = pthread_create(&thread->handle, NULL, threadRun, context); else { if (stack < PTHREAD_STACK_MIN) stack = PTHREAD_STACK_MIN; pthread_attr_setstacksize(&attributes, stack); - result = pthread_create(&thread->handle, &attributes, BH_ThreadRun, context); + result = pthread_create(&thread->handle, &attributes, threadRun, context); } pthread_attr_destroy(&attributes); @@ -67,7 +67,7 @@ BH_Thread *BH_ThreadNew(size_t stack, BH_Thread *thread; thread = malloc(sizeof(BH_Thread)); - if (thread && BH_ThreadInit(thread, stack, callback, data)) + if (thread && threadInit(thread, stack, callback, data)) { free(thread); return NULL; diff --git a/src/Platform/Posix/Tss.c b/src/Platform/Posix/Tss.c index 8a7a2fb..ba04f2b 100644 --- a/src/Platform/Posix/Tss.c +++ b/src/Platform/Posix/Tss.c @@ -13,7 +13,7 @@ static int tssReady = 0; static pthread_key_t tssKey; -static void BH_TssKeyCleanup(void *data) +static void keyCleanup(void *data) { int i; @@ -34,7 +34,7 @@ static void BH_TssKeyCleanup(void *data) } -static void **BH_TssDataFetch(void) +static void **dataFetch(void) { void **result; @@ -42,7 +42,7 @@ static void **BH_TssDataFetch(void) BH_SpinlockLock(&tssLock); if (!tssReady) { - if (pthread_key_create(&tssKey, BH_TssKeyCleanup)) + if (pthread_key_create(&tssKey, keyCleanup)) abort(); tssReady = 1; } @@ -67,7 +67,7 @@ static void **BH_TssDataFetch(void) void BH_TssCleanup(void) { - BH_TssKeyCleanup(BH_TssDataFetch()); + keyCleanup(dataFetch()); } @@ -92,12 +92,12 @@ int BH_TssCreate(BH_GenericCallback callback) void *BH_TssRead(int index) { - return BH_TssDataFetch()[index]; + return dataFetch()[index]; } void BH_TssWrite(int index, void *value) { - BH_TssDataFetch()[index] = value; + dataFetch()[index] = value; } diff --git a/src/Platform/Win32/Thread.c b/src/Platform/Win32/Thread.c index eafb947..f256d87 100644 --- a/src/Platform/Win32/Thread.c +++ b/src/Platform/Win32/Thread.c @@ -10,7 +10,7 @@ struct BH_ThreadContext }; -static unsigned __stdcall BH_ThreadRun(void *context) +static unsigned __stdcall threadRun(void *context) { BH_ThreadCallback callback; @@ -27,10 +27,10 @@ static unsigned __stdcall BH_ThreadRun(void *context) } -static int BH_ThreadInit(BH_Thread *thread, - size_t stack, - BH_ThreadCallback callback, - void *data) +static int threadInit(BH_Thread *thread, + size_t stack, + BH_ThreadCallback callback, + void *data) { struct BH_ThreadContext *context; @@ -58,7 +58,7 @@ BH_Thread *BH_ThreadNew(size_t stack, BH_Thread *thread; thread = malloc(sizeof(BH_Thread)); - if (thread && BH_ThreadInit(thread, stack, callback, data)) + if (thread && threadInit(thread, stack, callback, data)) { free(thread); return NULL; diff --git a/src/Platform/Win32/Tss.c b/src/Platform/Win32/Tss.c index 584bc46..7249a12 100644 --- a/src/Platform/Win32/Tss.c +++ b/src/Platform/Win32/Tss.c @@ -14,7 +14,7 @@ static int tssReady = 0; static DWORD tssKey; -static void __stdcall BH_TssKeyCleanup(void *data) +static void __stdcall keyCleanup(void *data) { int i; @@ -35,7 +35,7 @@ static void __stdcall BH_TssKeyCleanup(void *data) } -static void **BH_TssDataFetch(void) +static void **dataFetch(void) { void **result; @@ -43,7 +43,7 @@ static void **BH_TssDataFetch(void) BH_SpinlockLock(&tssLock); if (!tssReady) { - tssKey = FlsAlloc(BH_TssKeyCleanup); + tssKey = FlsAlloc(keyCleanup); if (tssKey == FLS_OUT_OF_INDEXES) abort(); tssReady = 1; @@ -69,7 +69,7 @@ static void **BH_TssDataFetch(void) void BH_TssCleanup(void) { - BH_TssKeyCleanup(BH_TssDataFetch()); + keyCleanup(dataFetch()); } @@ -94,12 +94,12 @@ int BH_TssCreate(BH_GenericCallback callback) void *BH_TssRead(int index) { - return BH_TssDataFetch()[index]; + return dataFetch()[index]; } void BH_TssWrite(int index, void *value) { - BH_TssDataFetch()[index] = value; + dataFetch()[index] = value; } diff --git a/src/Queue.c b/src/Queue.c index 746e8bf..7886759 100644 --- a/src/Queue.c +++ b/src/Queue.c @@ -13,20 +13,20 @@ struct BH_Queue }; -static void BH_QueueInit(BH_Queue *queue) +static void queueInit(BH_Queue *queue) { memset(queue, 0, sizeof(*queue)); } -static void BH_QueueDestroy(BH_Queue *queue) +static void queueDestroy(BH_Queue *queue) { if (queue->capacity) free(queue->data); } -static void BH_QueueCopy(BH_Queue *dest, +static void queueCopy(BH_Queue *dest, BH_Queue *src) { void *iter; @@ -47,7 +47,7 @@ BH_Queue *BH_QueueNew(void) result = malloc(sizeof(*result)); if (result) - BH_QueueInit(result); + queueInit(result); return result; } @@ -55,7 +55,7 @@ BH_Queue *BH_QueueNew(void) void BH_QueueFree(BH_Queue *queue) { - BH_QueueDestroy(queue); + queueDestroy(queue); free(queue); } @@ -86,7 +86,7 @@ int BH_QueueReserve(BH_Queue *queue, return BH_OK; /* Prepare new empty queue */ - BH_QueueInit(&other); + queueInit(&other); if (size) { /* Allocate new capacity for the queue */ @@ -96,7 +96,7 @@ int BH_QueueReserve(BH_Queue *queue, return BH_OOM; /* Iterate over old queue and insert data into new queue */ - BH_QueueCopy(&other, queue); + queueCopy(&other, queue); } /* If old queue had allocated data - free it */ diff --git a/src/String/Float.c b/src/String/Float.c index a8ed44d..47ab871 100644 --- a/src/String/Float.c +++ b/src/String/Float.c @@ -55,21 +55,21 @@ static void dragonFixup(struct DragonState *state, /* Account for unqual gaps */ if (f == (((uint64_t)1) << 52)) { - MpiLsh(&state->mp, 1, &state->mp); - MpiLsh(&state->r, 1, &state->r); - MpiLsh(&state->s, 1, &state->s); + mpiLsh(&state->mp, 1, &state->mp); + mpiLsh(&state->r, 1, &state->r); + mpiLsh(&state->s, 1, &state->s); } state->k = 0; /* Burger/Dybvig approach */ #ifndef BH_TWEAK_SHORT_BINT - state->k = MpiClz((f >> 32) & MPI_MASK); - state->k += (state->k == 32) ? (MpiClz(f & MPI_MASK)) : (0); + state->k = mpiClz((f >> 32) & MPI_MASK); + state->k += (state->k == 32) ? (mpiClz(f & MPI_MASK)) : (0); #else - state->k = MpiClz((f >> 48) & MPI_MASK); - state->k += (state->k == 16) ? (MpiClz((f >> 32) & MPI_MASK)) : (0); - state->k += (state->k == 32) ? (MpiClz((f >> 16) & MPI_MASK)) : (0); - state->k += (state->k == 48) ? (MpiClz(f & MPI_MASK)) : (0); + state->k = mpiClz((f >> 48) & MPI_MASK); + state->k += (state->k == 16) ? (mpiClz((f >> 32) & MPI_MASK)) : (0); + state->k += (state->k == 32) ? (mpiClz((f >> 16) & MPI_MASK)) : (0); + state->k += (state->k == 48) ? (mpiClz(f & MPI_MASK)) : (0); #endif /* 77 / 256 is an approximation for Log(2) or 0.30102999 */ @@ -82,18 +82,18 @@ static void dragonFixup(struct DragonState *state, /* Scale numbers accordinaly */ if (state->k < 0) { - MpiPow10(&state->r, -state->k, &state->r, state->tmp); - MpiPow10(&state->mm, -state->k, &state->mm, state->tmp); - MpiPow10(&state->mp, -state->k, &state->mp, state->tmp); + mpiPow10(&state->r, -state->k, &state->r, state->tmp); + mpiPow10(&state->mm, -state->k, &state->mm, state->tmp); + mpiPow10(&state->mp, -state->k, &state->mp, state->tmp); } else if (state->k > 0) - MpiPow10(&state->s, state->k, &state->s, state->tmp); + mpiPow10(&state->s, state->k, &state->s, state->tmp); /* Scale S if we underestimated */ - if (MpiCompare(&state->r, &state->s) >= 0) + if (mpiCompare(&state->r, &state->s) >= 0) { state->k += 1; - MpiMulDigit(&state->s, 10, &state->s); + mpiMulDigit(&state->s, 10, &state->s); } /* Find cutoff */ @@ -122,8 +122,8 @@ static void dragonRound(struct DragonState *state, /* Check if rounding up required */ if (high == low) { - MpiLsh(&state->r, 1, &state->tmp[0]); - i = MpiCompare(&state->tmp[0], &state->s); + mpiLsh(&state->r, 1, &state->tmp[0]); + i = mpiCompare(&state->tmp[0], &state->s); if (i < 0) { low = 1; high = 0; } else if (i > 0) { low = 0; high = 1; } else low = (((s - '0') & 0x1) == 0); @@ -185,12 +185,12 @@ static void dragon(double value, state.r.data[3] = (f >> 48) & MPI_MASK; state.r.size = 4; #endif - MpiTrim(&state.r); + mpiTrim(&state.r); - MpiLsh(&state.r, MAX(e - 53, 0), &state.r); - MpiLsh(&BInt1, MAX(0, -(e - 53)), &state.s); - MpiLsh(&BInt1, MAX(e - 53, 0), &state.mm); - MpiLsh(&BInt1, MAX(e - 53, 0), &state.mp); + mpiLsh(&state.r, MAX(e - 53, 0), &state.r); + mpiLsh(&BInt1, MAX(0, -(e - 53)), &state.s); + mpiLsh(&BInt1, MAX(e - 53, 0), &state.mm); + mpiLsh(&BInt1, MAX(e - 53, 0), &state.mp); dragonFixup(&state, precision, mode, f, e); /* Main digit generation loop */ @@ -198,8 +198,8 @@ static void dragon(double value, while(1) { state.k -= 1; - MpiMulDigit(&state.r, 10, &state.r); - MpiDiv(&state.r, &state.s, &state.tmp[0], &state.r, &state.tmp[1]); + mpiMulDigit(&state.r, 10, &state.r); + mpiDiv(&state.r, &state.s, &state.tmp[0], &state.r, &state.tmp[1]); s = '0'; if (state.tmp[0].size) @@ -208,13 +208,13 @@ static void dragon(double value, if (mode == NORMAL) { - MpiMulDigit(&state.mm, 10, &state.mm); - MpiMulDigit(&state.mp, 10, &state.mp); - MpiLsh(&state.r, 1, &state.tmp[1]); - MpiLsh(&state.s, 1, &state.tmp[2]); - MpiAdd(&state.tmp[1], &state.mp, &state.tmp[3]); - low = MpiCompare(&state.tmp[1], &state.mm) < 0; - high = MpiCompare(&state.tmp[3], &state.tmp[2]) > 0; + mpiMulDigit(&state.mm, 10, &state.mm); + mpiMulDigit(&state.mp, 10, &state.mp); + mpiLsh(&state.r, 1, &state.tmp[1]); + mpiLsh(&state.s, 1, &state.tmp[2]); + mpiAdd(&state.tmp[1], &state.mp, &state.tmp[3]); + low = mpiCompare(&state.tmp[1], &state.mm) < 0; + high = mpiCompare(&state.tmp[3], &state.tmp[2]) > 0; if (low || high || state.k == state.cutoff || buffer->size >= BUFSIZE) break; } @@ -668,43 +668,43 @@ double BH_StringToDouble(const char *string, for (i = 0; i < count; i++) { tmp[0].data[0] = buffer[i] - '0'; - MpiMulDigit(&r, 10, &r); - MpiAdd(&r, &tmp[0], &r); + mpiMulDigit(&r, 10, &r); + mpiAdd(&r, &tmp[0], &r); } if (e >= 0) - MpiPow10(&r, e, &r, &tmp[0]); + mpiPow10(&r, e, &r, &tmp[0]); else - MpiPow10(&s, -e, &s, &tmp[0]); + mpiPow10(&s, -e, &s, &tmp[0]); /* Calculate required shift */ shift = -52; - if (MpiCompare(&r, &s) >= 0) + if (mpiCompare(&r, &s) >= 0) { - MpiDiv(&r, &s, &tmp[0], &tmp[1], &tmp[2]); - shift += MpiLog2(&tmp[0]); + mpiDiv(&r, &s, &tmp[0], &tmp[1], &tmp[2]); + shift += mpiLog2(&tmp[0]); } else { - MpiDiv(&s, &r, &tmp[0], &tmp[1], &tmp[2]); - shift += -(MpiLog2(&tmp[0]) + 1); + mpiDiv(&s, &r, &tmp[0], &tmp[1], &tmp[2]); + shift += -(mpiLog2(&tmp[0]) + 1); } /* Shift */ if (shift > 0) - MpiLsh(&s, shift, &s); + mpiLsh(&s, shift, &s); else if (shift < 0) - MpiLsh(&r, -shift, &r); + mpiLsh(&r, -shift, &r); /* Calculate final exponent and 53 bit integer */ - MpiDiv(&r, &s, &tmp[0], &tmp[1], &tmp[2]); - MpiRsh(&s, 1, &s); - if (MpiCompare(&tmp[1], &s) > 0 || (MpiCompare(&tmp[1], &s) == 0 && (tmp[0].data[0] & 0x1))) + mpiDiv(&r, &s, &tmp[0], &tmp[1], &tmp[2]); + mpiRsh(&s, 1, &s); + if (mpiCompare(&tmp[1], &s) > 0 || (mpiCompare(&tmp[1], &s) == 0 && (tmp[0].data[0] & 0x1))) { - MpiAdd(&tmp[0], &BInt1, &tmp[0]); - if (MpiCompare(&tmp[0], &BInt53) >= 0) + mpiAdd(&tmp[0], &BInt1, &tmp[0]); + if (mpiCompare(&tmp[0], &BInt53) >= 0) { - MpiRsh(&tmp[0], 1, &tmp[0]); + mpiRsh(&tmp[0], 1, &tmp[0]); shift++; } } diff --git a/src/String/Inline/Mpi.h b/src/String/Inline/Mpi.h index efaa388..27a5682 100644 --- a/src/String/Inline/Mpi.h +++ b/src/String/Inline/Mpi.h @@ -68,7 +68,7 @@ static const Mpi powLookup[] = }; -static int MpiClz(MPI_TYPE value) +static int mpiClz(MPI_TYPE value) { if (value & 0xFF000000ul) return clzLookup[(value >> 24) & 0xFF]; @@ -110,7 +110,7 @@ static const Mpi powLookup[] = }; -static int MpiClz(MPI_TYPE value) +static int mpiClz(MPI_TYPE value) { if (value & 0xFF00) return clzLookup[(value >> 8) & 0xFF]; @@ -120,18 +120,18 @@ static int MpiClz(MPI_TYPE value) #endif -static int MpiLog2(const Mpi *in) +static int mpiLog2(const Mpi *in) { /* Preconditions */ assert(in != NULL); assert(in->size != 0); assert(in->data[in->size - 1] != 0); - return (MPI_BITS - 1) - MpiClz(in->data[in->size - 1]) + MPI_BITS * (in->size - 1); + return (MPI_BITS - 1) - mpiClz(in->data[in->size - 1]) + MPI_BITS * (in->size - 1); } -static void MpiTrim(Mpi *in) +static void mpiTrim(Mpi *in) { /* Preconditions */ assert(in != NULL); @@ -141,7 +141,7 @@ static void MpiTrim(Mpi *in) } -static int MpiCompare(const Mpi *a, +static int mpiCompare(const Mpi *a, const Mpi *b) { int i; @@ -167,7 +167,7 @@ static int MpiCompare(const Mpi *a, } -static void MpiAdd(const Mpi *a, +static void mpiAdd(const Mpi *a, const Mpi *b, Mpi *out) { @@ -200,7 +200,7 @@ static void MpiAdd(const Mpi *a, } -static void MpiSub(const Mpi *a, +static void mpiSub(const Mpi *a, const Mpi *b, Mpi *out) { @@ -209,7 +209,7 @@ static void MpiSub(const Mpi *a, /* Preconditions */ assert(a != NULL && b != NULL && out != NULL); - assert(MpiCompare(a, b) >= 0); + assert(mpiCompare(a, b) >= 0); /* Main subtraction loop */ carry = 0; @@ -227,11 +227,11 @@ static void MpiSub(const Mpi *a, /* Trim leading zeros */ out->size = a->size; - MpiTrim(out); + mpiTrim(out); } -static void MpiMul(const Mpi *a, +static void mpiMul(const Mpi *a, const Mpi *b, Mpi *out) { @@ -261,11 +261,11 @@ static void MpiMul(const Mpi *a, /* Trim leading zeros */ out->size = a->size + b->size; - MpiTrim(out); + mpiTrim(out); } -static void MpiMulDigit(const Mpi *a, +static void mpiMulDigit(const Mpi *a, MPI_TYPE b, Mpi *out) { @@ -288,11 +288,11 @@ static void MpiMulDigit(const Mpi *a, /* Trim leading zeros */ out->size = a->size + 1; - MpiTrim(out); + mpiTrim(out); } -static void MpiPow10(const Mpi *in, +static void mpiPow10(const Mpi *in, int exponent, Mpi *out, Mpi *tmp) @@ -309,14 +309,14 @@ static void MpiPow10(const Mpi *in, if (!(exponent & 0x1)) continue; - MpiMul(&tmp[current], &powLookup[i], &tmp[1 - current]); + mpiMul(&tmp[current], &powLookup[i], &tmp[1 - current]); current = 1 - current; } *out = tmp[current]; } -static void MpiLsh(const Mpi *in, +static void mpiLsh(const Mpi *in, int amount, Mpi *out) { @@ -356,13 +356,13 @@ static void MpiLsh(const Mpi *in, } /* Trim leading zeros and zero out lower blocks */ - MpiTrim(out); + mpiTrim(out); for (i = blocks; i; i--) out->data[i - 1] = 0; } -static void MpiRsh(const Mpi *in, +static void mpiRsh(const Mpi *in, int amount, Mpi *out) { @@ -404,11 +404,11 @@ static void MpiRsh(const Mpi *in, /* Trim leading zeros */ out->size = in->size - blocks; - MpiTrim(out); + mpiTrim(out); } -static MPI_TTYPE MpiGuess(const Mpi *a, +static MPI_TTYPE mpiGuess(const Mpi *a, const Mpi *b) { MPI_TTYPE tmp; @@ -418,7 +418,7 @@ static MPI_TTYPE MpiGuess(const Mpi *a, assert(a->size > 0 && b->size > 0); assert((a->size == b->size) || ((a->size != b->size) && a->size > 1)); - if (MpiCompare(a, b) < 0) + if (mpiCompare(a, b) < 0) return 0; tmp = a->data[a->size - 1]; @@ -429,7 +429,7 @@ static MPI_TTYPE MpiGuess(const Mpi *a, } -static void MpiDiv(const Mpi *a, +static void mpiDiv(const Mpi *a, const Mpi *b, Mpi *q, Mpi *r, @@ -443,7 +443,7 @@ static void MpiDiv(const Mpi *a, assert(b->size != 0); /* Handle case where a is less then b */ - if (MpiCompare(a, b) < 0) + if (mpiCompare(a, b) < 0) { *r = *a; q->size = 0; @@ -451,16 +451,16 @@ static void MpiDiv(const Mpi *a, } /* Normilize input to reduce tries */ - shift = MpiClz(b->data[b->size - 1]); - MpiLsh(a, shift, &tmp[0]); - MpiLsh(b, shift, &tmp[1]); + shift = mpiClz(b->data[b->size - 1]); + mpiLsh(a, shift, &tmp[0]); + mpiLsh(b, shift, &tmp[1]); /* Prepare first step of the division */ q->size = 0; r->size = 0; - while (MpiCompare(r, &tmp[1]) < 0) + while (mpiCompare(r, &tmp[1]) < 0) { - MpiLsh(r, MPI_BITS, r); + mpiLsh(r, MPI_BITS, r); r->data[0] = tmp[0].data[--tmp[0].size]; r->size += !r->size; } @@ -468,19 +468,19 @@ static void MpiDiv(const Mpi *a, while (1) { /* Make a guess and check */ - digit = MpiGuess(r, &tmp[1]); + digit = mpiGuess(r, &tmp[1]); while (digit > MPI_MASK) digit--; - MpiMulDigit(&tmp[1], digit, &tmp[2]); - while (MpiCompare(r, &tmp[2]) < 0) + mpiMulDigit(&tmp[1], digit, &tmp[2]); + while (mpiCompare(r, &tmp[2]) < 0) { --digit; - MpiSub(&tmp[2], &tmp[1], &tmp[2]); + mpiSub(&tmp[2], &tmp[1], &tmp[2]); } /* Store digit in quotient */ - MpiSub(r, &tmp[2], r); - MpiLsh(q, MPI_BITS, q); + mpiSub(r, &tmp[2], r); + mpiLsh(q, MPI_BITS, q); q->data[0] = digit; q->size += !q->size; @@ -488,12 +488,12 @@ static void MpiDiv(const Mpi *a, if (!tmp[0].size) break; - MpiLsh(r, MPI_BITS, r); + mpiLsh(r, MPI_BITS, r); r->data[0] = tmp[0].data[--tmp[0].size]; if (!r->size) r->size = 1; } /* Normilize remainder */ - MpiRsh(r, shift, r); + mpiRsh(r, shift, r); } diff --git a/unit/src/Unit.c b/unit/src/Unit.c index 654839d..dd7123a 100644 --- a/unit/src/Unit.c +++ b/unit/src/Unit.c @@ -13,7 +13,7 @@ typedef struct BH_Unit static BH_Unit *root = NULL; -static void BH_UnitCleanup(void) +static void cleanup(void) { BH_Unit *current; @@ -75,6 +75,6 @@ int BH_UnitRun(void) current = current->next; } - BH_UnitCleanup(); + cleanup(); return result; } |
