move code size benchmark to separate directory

This commit is contained in:
Michael Sippel 2025-02-16 17:25:23 +01:00
parent cea1f36e63
commit 24e28e7bb5
Signed by: senvas
GPG key ID: F96CF119C34B64A6
6 changed files with 13 additions and 71 deletions

View file

@ -0,0 +1,39 @@
LIB_DIR=$(shell pwd)/lib
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 $@ -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 $@ -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 $@ $<
posint-dec-to-hex-optimal-clang: posint-dec-to-hex-optimal.c
clang -g -Os -flto -o $@ $<
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 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)
.PHONY: all clean

View file

@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdint.h>
__attribute__((noinline))
int morph_posint_radix( char * in, char * out ) {
uint64_t value = 0;
while( *in ) {
if( *in >= '0' && *in <= '9' ) {
value *= 10;
value += *in - '0';
}
else
return -1;
in++;
}
uint64_t v = value;
while( v ) {
out ++;
v /= 16;
}
*out-- = '\0';
while( value ) {
unsigned digit = value % 16;
if( digit < 10 ) {
*out-- = digit + '0';
} else if( digit < 16 ) {
*out-- = digit + 'a' - 10;
} else {
return -1;
}
value /= 16;
}
return 0;
}
int main() {
char bufA[1024];
char bufB[1024];
char * in = bufA;
char * out = bufB;
scanf("%s", in);
morph_posint_radix( in, out );
printf("%s\n", out);
return 0;
}