diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5746d2d --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (c) 2023 John Regan + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b2dea67 --- /dev/null +++ b/Makefile @@ -0,0 +1,117 @@ +.PHONY: all clean test + +CFLAGS = -fPIC -g -O0 -Wall -Wextra +LDFLAGS = + +all: utest-byte utest-short utest-word utest-quad \ + utest-byte-static utest-short-static utest-word-static utest-quad-static \ + utest-byte-single utest-short-single utest-word-single utest-quad-single \ + utest-coverage bigint.o + +test: utest-byte utest-short utest-word utest-quad utest-byte-single utest-short-single utest-word-single utest-quad-single utest-coverage + ./utest-byte >/dev/null 2>&1 || ./utest-byte + ./utest-short >/dev/null 2>&1 || ./utest-short + ./utest-word >/dev/null 2>&1 || ./utest-word + ./utest-quad >/dev/null 2>&1 || ./utest-quad + ./utest-byte-single >/dev/null 2>&1 || ./utest-byte-single + ./utest-short-single >/dev/null 2>&1 || ./utest-short-single + ./utest-word-single >/dev/null 2>&1 || ./utest-word-single + ./utest-quad-single >/dev/null 2>&1 || ./utest-quad-single + ./utest-byte-static >/dev/null 2>&1 || ./utest-byte-static + ./utest-short-static >/dev/null 2>&1 || ./utest-short-static + ./utest-word-static >/dev/null 2>&1 || ./utest-word-static + ./utest-quad-static >/dev/null 2>&1 || ./utest-quad-static + mkdir -p coverage + rm -f coverage/* + ./utest-coverage + gcovr --html-details --output coverage/index.html + rm -f *.gcda + rm -f *.gcno + +utest-byte: utest-byte.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-short: utest-short.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-word: utest-word.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-quad: utest-quad.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-byte-single: utest-byte-single.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-short-single: utest-short-single.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-word-single: utest-word-single.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-quad-single: utest-quad-single.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-byte-static: utest-byte-static.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-short-static: utest-short-static.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-word-static: utest-word-static.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-quad-static: utest-quad-static.o + $(CC) -o $@ $^ $(LDFLAGS) + +utest-coverage: utest-coverage.o + $(CC) -o $@ $^ $(LDFLAGS) --coverage + +utest-byte.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_WORD_WIDTH=1 -c -o $@ $< + +utest-short.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_WORD_WIDTH=2 -c -o $@ $< + +utest-word.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_WORD_WIDTH=4 -c -o $@ $< + +utest-quad.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_WORD_WIDTH=8 -c -o $@ $< + +utest-byte-single.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_SINGLE_WORD_ONLY -DBIGINT_WORD_WIDTH=1 -c -o $@ $< + +utest-short-single.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_SINGLE_WORD_ONLY -DBIGINT_WORD_WIDTH=2 -c -o $@ $< + +utest-word-single.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_SINGLE_WORD_ONLY -DBIGINT_WORD_WIDTH=4 -c -o $@ $< + +utest-quad-single.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_SINGLE_WORD_ONLY -DBIGINT_WORD_WIDTH=8 -c -o $@ $< + +utest-byte-static.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_NO_MALLOC -DBIGINT_WORD_WIDTH=1 -c -o $@ $< + +utest-short-static.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_NO_MALLOC -DBIGINT_WORD_WIDTH=2 -c -o $@ $< + +utest-word-static.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_NO_MALLOC -DBIGINT_WORD_WIDTH=4 -c -o $@ $< + +utest-quad-static.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) -DBIGINT_NO_MALLOC -DBIGINT_WORD_WIDTH=8 -c -o $@ $< + +utest-coverage.o: utest.c utest.h bigint.h + $(CC) $(CFLAGS) --coverage -c -o $@ $< + +bigint.o: bigint.h + $(CC) -DBIGINT_IMPLEMENTATION -std=c99 -pedantic $(CFLAGS) -c -o $@ $< + +clean: + rm -f *.o *.exe + rm -f utest-coverage + rm -f utest-byte utest-short utest-word utest-quad + rm -f utest-byte-single utest-short-single utest-word-single utest-quad-single + rm -f utest-byte-static utest-short-static utest-word-static utest-quad-static diff --git a/bigint.h b/bigint.h index eebb44f..1ac01cd 100644 --- a/bigint.h +++ b/bigint.h @@ -1,6 +1,21 @@ #ifndef BIGINTH #define BIGINTH +/* +Copyright (c) 2023 John Regan + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +*/ + #if !defined(BIGINT_API) #ifdef _WIN32 #define BIGINT_DLL_IMPORT __declspec(dllimport)