diff --git a/morphisms/Makefile b/code-size-benchmark/Makefile similarity index 52% rename from morphisms/Makefile rename to code-size-benchmark/Makefile index 884f9dc..02dc461 100644 --- a/morphisms/Makefile +++ b/code-size-benchmark/Makefile @@ -1,16 +1,22 @@ LIB_DIR=$(shell pwd)/lib -TARGETS=lib/libmorph_length-prefix.so lib/libmorph_posint.so +TARGETS=posint-dec-to-hex-generated.c posint-dec-to-hex-generated-gcc posint-dec-to-hex-generated-clang posint-dec-to-hex-optimal-gcc posint-dec-to-hex-optimal-clang all: $(TARGETS) lib/libmorph_%.so: src/%.c $(CC) -O3 -shared -o $@ -fPIC -Iinclude $< +posint-dec-to-hex-generated.c: + cargo run -- \ + "ℕ~<PosInt 10 BigEndian>~<Seq~<ValueTerminated '\\0'> <Digit 10>~Char~Ascii~x86.UInt8>" \ + "ℕ~<PosInt 16 BigEndian>~<Seq~<ValueTerminated '\\0'> <Digit 16>~Char~Ascii~x86.UInt8>" \ + ../morphisms/*.morphism-base >| $@ + posint-dec-to-hex-generated-gcc: posint-dec-to-hex-generated.c - gcc -g -Os -flto -o $@ -Iinclude $< src/length-prefix.c src/posint.c + gcc -g -Os -flto -o $@ -I../morphisms/include $< ../morphisms/src/length-prefix.c posint-dec-to-hex-generated-clang: posint-dec-to-hex-generated.c - clang -g -Os -flto -o $@ -Iinclude $< src/length-prefix.c src/posint.c + clang -g -Os -flto -o $@ -I../morphisms/include $< ../morphisms/src/length-prefix.c posint-dec-to-hex-optimal-gcc: posint-dec-to-hex-optimal.c gcc -g -Os -flto -o $@ $< @@ -22,10 +28,10 @@ code-size-benchmark: posint-dec-to-hex-generated-gcc \ posint-dec-to-hex-generated-clang \ posint-dec-to-hex-optimal-gcc \ posint-dec-to-hex-optimal-clang - INST_COUNT_GEN_GCC=$(shell gdb --batch -ex "file posint-dec-to-hex-generated-gcc" -ex "disassemble morph_posint_radix" | wc -l) - INST_COUNT_GEN_CLANG=$(shell gdb --batch -ex "file posint-dec-to-hex-generated-clang" -ex "disassemble morph_posint_radix" | wc -l) - INST_COUNT_OPT_GCC=$(shell gdb --batch -ex "file posint-dec-to-hex-optimal-gcc" -ex "disassemble morph_posint_radix" | wc -l) - INST_COUNT_OPT_CLANG=$(shell gdb --batch -ex "file posint-dec-to-hex-optimal-clang" -ex "disassemble posint_radix" | wc -l) + INST_COUNT_GEN_GCC=$(shell gdb --batch -ex "file posint-dec-to-hex-generated-gcc" -ex "disassemble main" | wc -l) + INST_COUNT_GEN_CLANG=$(shell gdb --batch -ex "file posint-dec-to-hex-generated-clang" -ex "disassemble main" | wc -l) + INST_COUNT_OPT_GCC=$(shell gdb --batch -ex "file posint-dec-to-hex-optimal-gcc" -ex "disassemble main" | wc -l) + INST_COUNT_OPT_CLANG=$(shell gdb --batch -ex "file posint-dec-to-hex-optimal-clang" -ex "disassemble main" | wc -l) clean: rm $(TARGETS) diff --git a/morphisms/posint-dec-to-hex-optimal.c b/code-size-benchmark/posint-dec-to-hex-optimal.c similarity index 100% rename from morphisms/posint-dec-to-hex-optimal.c rename to code-size-benchmark/posint-dec-to-hex-optimal.c diff --git a/morphisms/morphism-base/digit.morphism-base b/morphisms/digit.morphism-base similarity index 100% rename from morphisms/morphism-base/digit.morphism-base rename to morphisms/digit.morphism-base diff --git a/morphisms/morphism-base/length_prefix.morphism-base b/morphisms/length_prefix.morphism-base similarity index 100% rename from morphisms/morphism-base/length_prefix.morphism-base rename to morphisms/length_prefix.morphism-base diff --git a/morphisms/posint-dec-to-hex-generated.c b/morphisms/posint-dec-to-hex-generated.c deleted file mode 100644 index bdba861..0000000 --- a/morphisms/posint-dec-to-hex-generated.c +++ /dev/null @@ -1,64 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <morphisms/length-prefix.h> -#include <morphisms/posint.h> - -__attribute__((noinline)) -int morph_posint_radix( - uint8_t * bufA, - uint8_t * bufB -) { - // morph to - // ℕ ~ <PosInt 10 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ Char ~ Ascii] - { - char const * src = (void*) bufA; - struct LengthPrefixUInt8Array * dst = (void*) bufB; - morph_string_as_nullterm_to_length_prefix( src, dst ); - } - - // morph to - // ℕ ~ <PosInt 10 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ ℤ_10 ~ x86.UInt64] - { - struct LengthPrefixUInt8Array * src = (void*) bufB; - struct LengthPrefixUInt64Array * dst = (void*) bufA; - length_prefix_array_map_8_to_64( morph_digit_as_char_to_uint64, src, dst ); - } - // ℕ ~ <PosInt 16 LittleEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 16> ~ ℤ_16 ~ x86.UInt64] - { - uint64_t const src_radix = 10; - uint64_t const dst_radix = 16; - struct LengthPrefixUInt64Array * src = (void*) bufB; - struct LengthPrefixUInt64Array * dst = (void*) bufA; - morph_posint_radix_little( src_radix, dst_radix, src, dst ); - } - - // morph to - // ℕ ~ <PosInt 16 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 16> ~ Char ~ Ascii] - { - struct LengthPrefixUInt64Array * src = (void*) bufB; - struct LengthPrefixUInt8Array * dst = (void*) bufA; - - length_prefix_array_map_64_to_8( morph_digit_as_uint64_to_char, src, dst ); - } - - // morph to - // ℕ ~ <PosInt 16 BigEndian> ~ [~<ValueDelim '\0'> <Digit 16> ~ Char ~ Ascii] - { - struct LengthPrefixUInt8Array * src = (void*) bufA; - char * dst = (void*) bufB; - morph_string_as_length_prefix_to_nullterm( src, dst ); - } - - return 0; -} - -int main() { - uint8_t bufA[1024]; - uint8_t bufB[1024]; - - scanf("%s", bufA); - morph_posint_radix( bufA, bufB ); - printf("%s\n", bufB); - - return 0; -} diff --git a/morphisms/morphism-base/posint.morphism-base b/morphisms/posint.morphism-base similarity index 100% rename from morphisms/morphism-base/posint.morphism-base rename to morphisms/posint.morphism-base