gcc是否提供内置读取大端内存?(Does gcc provide builtin to read big endian memory?)
我需要从两个小端核(例如arm)读/写设备寄存器(在我的情况下是在大端地址空间中)。 我不想使用中间端转换例程(例如htonl)。 我的理解是现代核心具有指令,使用它们可以直接读取/写入大端存储器。
gcc是否为上述内容提供了自动生成正确汇编指令的内置函数?
I need to read/write device registers (which in my case are in big endian address space) from both little endian cores (e.g. arm). I do not want to use intermediate endian conversion routines (e.g. htonl). My understanding is that modern cores have instructions using which they can do reads/writes to big endian memory directly.
Does gcc offer any builtin for the above which automatically generates right assembly instruction(s)?
最满意答案
GCC 4.3.0提供内置功能:
内置函数:int32_t __builtin_bswap32(int32_t x),它返回逆转的顺序。 例如。 11223344将是0x44332211 内置函数:int64_t __builtin_bswap64(int64_t x)也类似于__builtin_bswap32,但它返回64位。请参阅内置的小心 。
There are built-in functions available from GCC 4.3.0:
Built-in Function: int32_t __builtin_bswap32 (int32_t x), it returns the order of byes reversed. for eg. 11223344 will be 0x44332211 Built-in Function: int64_t __builtin_bswap64 (int64_t x) is also similar to __builtin_bswap32, except that it returns 64 bits.Please refer to the Beware the builtins.
更多推荐
发布评论