sw/lib/mpi/mpi_internal.h
// avoid unaligned memory access for little endian RISC-V
avoid unaligned memory access for little endian RISC-V
avoid unaligned memory access for little endian RISC - V
static inline void unaligned_store_flit(flit_t *p, flit_t f)
{
    assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__);
    ptrdiff_t addr = (ptrdiff_t)p;
    ptrdiff_t ofs = addr & (sizeof(flit_t)-1);
    if (ofs == 0) {
        *p = f;
    } else {
        flit_t *aligned = (flit_t *)(addr & -(sizeof(flit_t)));
        ptrdiff_t left = 8*ofs;
        ptrdiff_t right = 8*sizeof(flit_t)-left;
        aligned[0] = ((aligned[0] << right) >> right) | (f << left);
        aligned[1] = ((aligned[1] >> left) << left) | (f >> right);
    }
}
static inline void unaligned_store_flit ( flit_t * p , flit_t f ) { assert ( __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) ; ptrdiff_t addr = ( ptrdiff_t ) p ; ptrdiff_t ofs = addr & ( sizeof ( flit_t ) - 1 ) ; if ( ofs == 0 ) { * p = f ; } else { flit_t * aligned = ( flit_t * ) ( addr & - ( sizeof ( flit_t ) ) ) ; ptrdiff_t left = 8 * ofs ; ptrdiff_t right = 8 * sizeof ( flit_t ) - left ; aligned [ 0 ] = ( ( aligned [ 0 ] << right ) >> right ) | ( f << left ) ; aligned [ 1 ] = ( ( aligned [ 1 ] >> left ) << left ) | ( f >> right ) ; } }
avoid unaligned memory access for little endian RISC-V
avoid unaligned memory access for little endian RISC - V
// 0 1 2 3 4 5 6 7  8 9 a b c d e f //   left |      flit      | right