  | 
  
    P4C
    
   The P4 Compiler 
   | 
 
 
 
 
Loading...
Searching...
No Matches
 
 
 
 
   17#ifndef ___constant_swab16 
   18#define ___constant_swab16(x) ((uint16_t)(             \ 
   19    (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) |          \ 
   20    (((uint16_t)(x) & (uint16_t)0xff00U) >> 8))) 
   23#ifndef ___constant_swab32 
   24#define ___constant_swab32(x) ((uint32_t)(             \ 
   25    (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) |        \ 
   26    (((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) |        \ 
   27    (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >>  8) |        \ 
   28    (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) 
   31#ifndef ___constant_swab64 
   32#define ___constant_swab64(x) ((uint64_t)(             \ 
   33    (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) |   \ 
   34    (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) |   \ 
   35    (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) |   \ 
   36    (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) <<  8) |   \ 
   37    (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >>  8) |   \ 
   38    (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) |   \ 
   39    (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) |   \ 
   40    (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56))) 
   43#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 
   44#ifndef __constant_htonll 
   45#define __constant_htonll(x) (___constant_swab64((x))) 
   48#ifndef __constant_ntohll 
   49#define __constant_ntohll(x) (___constant_swab64((x))) 
   52#define __constant_htonl(x) (___constant_swab32((x))) 
   53#define __constant_ntohl(x) (___constant_swab32(x)) 
   54#define __constant_htons(x) (___constant_swab16((x))) 
   55#define __constant_ntohs(x) ___constant_swab16((x)) 
   57#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 
   58# warning "I never tested BIG_ENDIAN machine!" 
   59#define __constant_htonll(x) (x) 
   60#define __constant_ntohll(X) (x) 
   61#define __constant_htonl(x) (x) 
   62#define __constant_ntohl(x) (x) 
   63#define __constant_htons(x) (x) 
   64#define __constant_ntohs(x) (x) 
   67# error "Fix your compiler's __BYTE_ORDER__?!" 
   71#define htonl(d) __constant_htonl(d) 
   73#define htons(d) __constant_htons(d) 
   75#define htonll(d) __constant_htonll(d) 
   77#define ntohl(d) __constant_ntohl(d) 
   79#define ntohs(d) __constant_ntohs(d) 
   81#define ntohll(d) __constant_ntohll(d) 
   83#define load_byte(data, b) (*(((uint8_t*)(data)) + (b))) 
   84#define load_half(data, b) __constant_ntohs(*(uint16_t *)((uint8_t*)(data) + (b))) 
   85#define load_word(data, b) __constant_ntohl(*(uint32_t *)((uint8_t*)(data) + (b))) 
   86#define load_dword(data, b) __constant_ntohll(*(uint64_t *)((uint8_t*)(data) + (b)))