posint morph code size benchmark

This commit is contained in:
Michael Sippel 2025-02-03 17:05:19 +01:00
parent e500a24d2a
commit 23b2dcaf82
Signed by: senvas
GPG key ID: F96CF119C34B64A6
4 changed files with 149 additions and 57 deletions

View file

@ -0,0 +1,82 @@
#include <stdio.h>
#include <stdint.h>
#include <morphisms/length-prefix.h>
#include <morphisms/posint.h>
int main() {
uint8_t bufA[1024];
uint8_t bufB[1024];
scanf("%s", bufA);
// 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;
dst->len = src->len;
for( uint64_t i = 0; i < src->len; ++i )
morph_digit_as_char_to_uint64( &src->items[i], &dst->items[i] );
}
// morph to
// ~ <PosInt 10 LittleEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ _10 ~ x86.UInt64]
{
uint64_t const radix = 10;
struct LengthPrefixUInt64Array * src = (void*) bufA;
struct LengthPrefixUInt64Array * dst = (void*) bufB;
morph_posint_endianness( radix, src, dst );
}
// morph to
// ~ <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( src_radix, dst_radix, src, dst );
}
// morph to
// ~ <PosInt 16 LittleEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ _10 ~ x86.UInt64]
{
uint64_t const radix = 16;
struct LengthPrefixUInt64Array * src = (void*) bufA;
struct LengthPrefixUInt64Array * dst = (void*) bufB;
morph_posint_endianness( 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;
dst->len = src->len;
for( uint64_t i = 0; i < src->len; ++i )
morph_digit_as_uint64_to_char( &src->items[i], &dst->items[i] );
}
// 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 );
}
printf("%s\n", bufB);
return 0;
}