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 flit_t unaligned_load_flit(flit_t *p)
{
    assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__);
    ptrdiff_t addr = (ptrdiff_t)p;
    ptrdiff_t ofs = addr & (sizeof(flit_t)-1);
    if (ofs == 0) return *p;
    flit_t *aligned = (flit_t *)(addr & -(sizeof(flit_t)));
    ptrdiff_t left = 8*ofs;
    ptrdiff_t right = 8*sizeof(flit_t)-left;
    return (aligned[0] >> left) | (aligned[1] << right);
}
static inline flit_t unaligned_load_flit ( flit_t * p ) { assert ( __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) ; ptrdiff_t addr = ( ptrdiff_t ) p ; ptrdiff_t ofs = addr & ( sizeof ( flit_t ) - 1 ) ; if ( ofs == 0 ) return * p ; flit_t * aligned = ( flit_t * ) ( addr & - ( sizeof ( flit_t ) ) ) ; ptrdiff_t left = 8 * ofs ; ptrdiff_t right = 8 * sizeof ( flit_t ) - left ; return ( aligned [ 0 ] >> left ) | ( aligned [ 1 ] << 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