byteorder.h

来自「vitual serial port driver」· C头文件 代码 · 共 46 行

H
46
字号
#ifndef _ASM_BYTEORDER_H
#define _ASM_BYTEORDER_H

#include <linux/types.h>

#define __constant_htons(x) \
	((__u16)( \
		(((__u16)(x) & (__u16)0x00ffU) << 8) | \
		(((__u16)(x) & (__u16)0xff00U) >> 8) ))

__inline __u16 swap16(__u16 x)
{
    __asm
    {
        mov  ax,x
        xchg al,ah
        mov  x,ax
    }
    return x;
}

__inline __u32 swap32(__u32 x)
{
    __asm
    {
        mov  eax,x
        bswap eax
        mov  x,eax
    }
    return x;
}

#define cpu_to_be16(x)  swap16((x))
#define cpu_to_le16(x)  ((__u16)(x))
#define cpu_to_be32(x)  swap32((x))
#define cpu_to_be32s(x) do { *(x) = swap32(*(x)); } while (0)
#define cpu_to_le32s(x)

#define be16_to_cpu(x)  swap16((x))
#define le16_to_cpu(x)  ((__u16)(x))
#define be32_to_cpus(x) do { *(x) = swap32(*(x)); } while (0)
#define le32_to_cpus(x)

#define htons(x)        cpu_to_be16((x))

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?