Ecb: unaligned integer load and store support

Zsb√°n Ambrus ambrus at math.bme.hu
Wed Sep 9 11:28:46 CEST 2015


Code for unaligned integer load and store.  This should eventually go
to libecb.  Be vary of the code, I haven't really tested it, it's
probably full of typos.  Also, no documentation yet.


struct ecb_array_u8_8 { uint8_t ecb_e[8]; };
union ecb_union_u64 { ecb_array_u8_8 ecb_a; uint64_t ecb_v; };
ecb_inline uint64_t ecb_load_u64(const void *ecb_p)
{
    union ecb_union_u64 ecb_u;
    ecb_u.ecb_a = *(const ecb_array_u8_8 *)ecb_p;
    return ecb_u.ecb_v;
}
ecb_inline void ecb_store_u64(void *ecb_p, uint64_t ecb_x)
{
    union ecb_union_u64 ecb_u;
    ecb_u.ecb_v = ecb_x;
    *(ecb_array_u8_8 *)ecb_p = ecb_u.ecb_a;
}
struct ecb_array_u8_4 { uint8_t ecb_e[4]; };
union ecb_union_u32 { ecb_array_u8_4 ecb_a; uint32_t ecb_v; };
ecb_inline uint32_t ecb_load_u32(const void *ecb_p)
{
    union ecb_union_u32 ecb_u;
    ecb_u.ecb_a = *(const ecb_array_u8_4 *)ecb_p;
    return ecb_u.ecb_v;
}
ecb_inline void ecb_store_u32(void *ecb_p, uint32_t ecb_x)
{
    union ecb_union_u32 ecb_u;
    ecb_u.ecb_v = ecb_x;
    *(ecb_array_u8_4 *)ecb_p = ecb_u.ecb_a;
}
struct ecb_array_u8_2 { uint8_t ecb_e[2]; };
union ecb_union_u16 { ecb_array_u8_2 ecb_a; uint16_t ecb_v; };
ecb_inline uint16_t ecb_load_u16(const void *ecb_p)
{
    union ecb_union_u16 ecb_u;
    ecb_u.ecb_a = *(const ecb_array_u8_2 *)ecb_p;
    return ecb_u.ecb_v;
}
ecb_inline void ecb_store_u16(void *ecb_p, uint16_t ecb_x)
{
    union ecb_union_u16 ecb_u;
    ecb_u.ecb_v = ecb_x;
    *(ecb_array_u8_2 *)ecb_p = ecb_u.ecb_a;
}


// -- Ambrus



More information about the libev mailing list