diff --git a/src/Makefile b/src/Makefile index 596ad5a..025acfa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,11 +1,7 @@ -all: test-bitmap +all: %.o: %.c gcc -O0 -Wall -Wextra -pedantic -ggdb $< -o $@ -test-bitmap: test-bitmap.c bitmap.c - gcc -Wall -Wextra -pedantic -g -ggdb test-bitmap.c bitmap.c -o test-bitmap - clean: rm -f *.o - rm -f test-bitmap diff --git a/src/bitmap.c b/src/bitmap.c index 6753e79..ea79eac 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -20,14 +20,14 @@ int bitmap_compare(bitmap *a, bitmap *b) { uint16_t row = 0; - uint16_t bit = 0; + uint16_t diff = 0; size_t cnt = 0; for (row = 0; row < 16; row++) { - bit = 1 << 15; - while (bit) { - cnt += !!(((*a)[row] & bit) ^ ((*b)[row] & bit)); - bit >>= 1; + diff = (*a)[row] ^ (*b)[row]; + while (diff) { + cnt += (diff & 1); + diff >>= 1; } } diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..42a2f16 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,10 @@ +all: test-bitmap + +CFLAGS=-Wall -Wextra -O0 -g -ggdb -pedantic + +%.o: %.c + gcc $(CFLAGS) $< -o $@ + +SRC=../src/bitmap.c bitmap.c +test-bitmap: + gcc $(CFLAGS) $(SRC) -o $@ diff --git a/tests/bitmap.c b/tests/bitmap.c index 24a6097..3021ed3 100644 --- a/tests/bitmap.c +++ b/tests/bitmap.c @@ -1,5 +1,5 @@ -#include "main.h" -#include "bitmap.h" +#include "../src/main.h" +#include "../src/bitmap.h" int main(int argc, char **argv)