當前位置: 首頁>>代碼示例>>C++>>正文


C++ __builtin_bswap64函數代碼示例

本文整理匯總了C++中__builtin_bswap64函數的典型用法代碼示例。如果您正苦於以下問題:C++ __builtin_bswap64函數的具體用法?C++ __builtin_bswap64怎麽用?C++ __builtin_bswap64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了__builtin_bswap64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: bswap128

static inline void bswap128(uint128_t *dst, const uint128_t *src)
{
	uint64_t tmp;

	tmp = __builtin_bswap64(src->ll[1]);
	dst->ll[1] = __builtin_bswap64(src->ll[0]);
	dst->ll[0] = tmp;
}
開發者ID:jkivilin,項目名稱:supercop-blockciphers,代碼行數:8,代碼來源:stream.c

示例2: main

int main(int argc, const char * argv[])
{

    // Dumps a pbzx to stdout. Can work as a filter if no argument is specified

    char buffer[1024];
    int fd = 0;

    if (argc < 2) { fd  = 0 ;}
    else { fd = open (argv[1], O_RDONLY);
           if (fd < 0) { perror (argv[1]); exit(5); }
         }


    read (fd, buffer, 4);
    if (strncmp(buffer, "pbzx", 4)) { fprintf(stderr, "Can't find pbzx magic\n"); exit(0);}

    // Now, if it IS a pbzx

    uint64_t length = 0, flags = 0;

    read (fd, &flags, sizeof (uint64_t));
    flags = __builtin_bswap64(flags);

    fprintf(stderr,"Flags: 0x%llx\n", flags);

    int i = 0;
    int off = 0;

    while (flags &   0x01000000) { // have more chunks
    i++;
    read (fd, &flags, sizeof (uint64_t));
    flags = __builtin_bswap64(flags);
    read (fd, &length, sizeof (uint64_t));
    length = __builtin_bswap64(length);

    fprintf(stderr,"Chunk #%d (flags: %llx, length: %lld bytes)\n",i, flags,length);
     
    // Let's ignore the fact I'm allocating based on user input, etc..
    char *buf = malloc (length);
    read (fd, buf, length);

   // We want the XZ header/footer if it's the payload, but prepare_payload doesn't have that, 
    // so just warn.
    

    if (strncmp(buf, "\xfd""7zXZ\0", 6))  { fprintf (stderr, "Warning: Can't find XZ header. This is likely not XZ data.\n"); }
    else // if we have the header, we had better have a footer, too
    if (strncmp(buf + length -2, "YZ", 2)) { fprintf (stderr, "Warning: Can't find XZ footer. This is bad.\n"); }

    write (1, buf, length);

    }

    return 0;
} 
開發者ID:iMostfa,項目名稱:iOS_OTA-Payload_Extractor,代碼行數:56,代碼來源:pbzx.c

示例3: vfoo64

static inline void
vfoo64 (unsigned long long* a)
{
  int i = 0;
  for (i = 0; i < N; ++i)
    a[i] = __builtin_bswap64 (a[i]);
}
開發者ID:0day-ci,項目名稱:gcc,代碼行數:7,代碼來源:vect-bswap64.c

示例4: GDB_ParseCommonThreadInfo

static int GDB_ParseCommonThreadInfo(char *out, GDBContext *ctx, int sig)
{
    u32 threadId = ctx->currentThreadId;
    ThreadContext regs;
    s64 dummy;
    u32 core;
    Result r = svcGetDebugThreadContext(&regs, ctx->debug, threadId, THREADCONTEXT_CONTROL_ALL);
    int n = sprintf(out, "T%02xthread:%x;", sig, threadId);

    if(R_FAILED(r))
        return n;

    r = svcGetDebugThreadParam(&dummy, &core, ctx->debug, ctx->currentThreadId, DBGTHREAD_PARAMETER_CPU_CREATOR); // Creator = "first ran, and running the thread"

    if(R_SUCCEEDED(r))
        n += sprintf(out + n, "core:%x;", core);

    for(u32 i = 0; i <= 12; i++)
        n += sprintf(out + n, "%x:%08x;", i, __builtin_bswap32(regs.cpu_registers.r[i]));

    n += sprintf(out + n, "d:%08x;e:%08x;f:%08x;19:%08x;",
        __builtin_bswap32(regs.cpu_registers.sp), __builtin_bswap32(regs.cpu_registers.lr), __builtin_bswap32(regs.cpu_registers.pc),
        __builtin_bswap32(regs.cpu_registers.cpsr));

    for(u32 i = 0; i < 16; i++)
    {
        u64 val;
        memcpy(&val, &regs.fpu_registers.d[i], 8);
        n += sprintf(out + n, "%x:%016llx;", 26 + i, __builtin_bswap64(val));
    }

    n += sprintf(out + n, "2a:%08x;2b:%08x;", __builtin_bswap32(regs.fpu_registers.fpscr), __builtin_bswap32(regs.fpu_registers.fpexc));

    return n;
}
開發者ID:TemplarsCreed,項目名稱:Luma3DS,代碼行數:35,代碼來源:debug.c

示例5: LLVMFuzzerTestOneInput

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  if (Size < 14) return 0;
  uint64_t x = 0;
  uint32_t y = 0;
  uint32_t z = 0;
  memcpy(&x, Data, sizeof(x));
  memcpy(&y, Data + Size / 2, sizeof(y));
  memcpy(&z, Data + Size - sizeof(z), sizeof(z));

  x = __builtin_bswap64(x);
  y = __builtin_bswap32(y);
  z = __builtin_bswap32(z);
  const bool k32bit = sizeof(void*) == 4;

  if ((k32bit || x == 0x46555A5A5A5A5546ULL) &&
      z == 0x4F4B &&
      y == 0x66757A7A &&
      true
      ) {
    if (Data[Size - 5] == 'z') {
      fprintf(stderr, "BINGO; Found the target\n");
      exit(1);
    }
  }
  return 0;
}
開發者ID:efcs,項目名稱:compiler-rt,代碼行數:26,代碼來源:SwapCmpTest.cpp

示例6: data_length

 size_t data_length() const noexcept {
   if (is_ext2())
       return __builtin_bswap64(*(uint64_t*) vla) & 0xffffffff;
   if (is_ext())
       return __builtin_bswap16(*(uint16_t*) vla);
   return payload();
 }
開發者ID:AnnikaH,項目名稱:IncludeOS,代碼行數:7,代碼來源:header.hpp

示例7: eightbyte_get_byte

uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index,
        const bool data_is_big_endian) {
    if(data_is_big_endian) {
        source = __builtin_bswap64(source);
    }
    return (source >> (EIGHTBYTE_BIT - ((byte_index + 1) * CHAR_BIT))) & 0xFF;
}
開發者ID:kal667,項目名稱:bitfield-c,代碼行數:7,代碼來源:8byte.c

示例8: ticket_get_title_id

Result ticket_get_title_id(u64* titleId, u8* ticket, size_t size) {
    if(ticket == NULL) {
        return R_APP_INVALID_ARGUMENT;
    }

    if(size < 4) {
        return R_APP_BAD_DATA;
    }

    u8 sigType = ticket[0x03];
    if(sigType >= NUM_SIG_TYPES) {
        return R_APP_BAD_DATA;
    }

    u32 offset = sigSizes[sigType] + 0x9C;
    if(offset + sizeof(u64) > size) {
        return R_APP_BAD_DATA;
    }

    if(titleId != NULL) {
        *titleId = __builtin_bswap64(*(u64*) &ticket[offset]);
    }

    return 0;
}
開發者ID:NinjaBoyLao,項目名稱:FBI,代碼行數:25,代碼來源:ticket.c

示例9: main

int
main (void)
{
  unsigned long long arr[N];
  unsigned long long expect[N];
  int i;

  for (i = 0; i < N; ++i)
    {
      arr[i] = i;
      expect[i] = __builtin_bswap64 (i);
      if (y) /* Avoid vectorisation.  */
        abort ();
    }

  vfoo64 (arr);

  for (i = 0; i < N; ++i)
    {
      if (arr[i] != expect[i])
        abort ();
    }

  return 0;
}
開發者ID:0day-ci,項目名稱:gcc,代碼行數:25,代碼來源:vect-bswap64.c

示例10: crypto_stream_xor

int crypto_stream_xor(unsigned char *out, const unsigned char *in,
                      unsigned long long inlen, const unsigned char *n,
                      const unsigned char *k)
{
#define PTR_ALIGN(ptr, mask) ((void *)((((long)(ptr)) + (mask)) & ~((long)(mask))))
    const unsigned long align = 4096;
    char ctxbuf[sizeof(struct blowfish_ctx) + align];
    struct blowfish_ctx *ctx = PTR_ALIGN(ctxbuf, align - 1);
    uint64_t iv;
    uint64_t block;

    blowfish_init(ctx, k, CRYPTO_KEYBYTES);
    iv = __builtin_bswap64(*(uint64_t *)n); /* be => le */

    while (likely(inlen >= BLOCKSIZE)) {
        block = __builtin_bswap64(iv++); /* le => be */

        blowfish_enc_blk(ctx, out, &block);

        if (unlikely(in)) {
            *(uint64_t *)out ^= *(uint64_t *)in;
            in += BLOCKSIZE;
        }

        out += BLOCKSIZE;
        inlen -= BLOCKSIZE;
    }

    if (unlikely(inlen > 0)) {
        /* handle remaining bytes */
        unsigned int i;

        block = __builtin_bswap64(iv); /* le => be */

        blowfish_enc_blk(ctx, &block, &block);

        if (in) {
            for (i = 0; i < inlen; i++)
                out[i] = in[i] ^ ((uint8_t*)&block)[i];
        } else {
            for (i = 0; i < inlen; i++)
                out[i] = ((uint8_t*)&block)[i];
        }
    }

    return 0;
}
開發者ID:jkivilin,項目名稱:supercop-blockciphers,代碼行數:47,代碼來源:stream.c

示例11: swap64

static uint64_t swap64(uint64_t v)
{
#define IS_LITTLE_ENDIAN (*(uint16_t *)"\0\xff" >= 0x100)
    if(IS_LITTLE_ENDIAN) {
        v = __builtin_bswap64(v);
    }
    return v;
}
開發者ID:Zabrane,項目名稱:centidb,代碼行數:8,代碼來源:_centidb.c

示例12: foo64

uint64_t foo64 (uint64_t a)
{
  uint64_t b;

  b = __builtin_bswap64 (a);

  return b;
}
開發者ID:0day-ci,項目名稱:gcc,代碼行數:8,代碼來源:builtin-bswap-1.c

示例13: cpu_to_be_64

inline unsigned long long
cpu_to_be_64(unsigned long long val)
{
  if (is_big_endian()) {
    return val;
  } else {
    return __builtin_bswap64(val);
  }
}
開發者ID:abn,項目名稱:symboldb,代碼行數:9,代碼來源:endian.hpp

示例14: defined

template <> constexpr inline uint64_t bswap<uint64_t>(uint64_t x) noexcept
{
#if defined(HAVE___BUILTIN_BSWAP64)
    return __builtin_bswap64(x);
#else
    /// @todo create a fallback.
    static_assert(false, "Generic bswap64() not yet implemented.");
#endif
}
開發者ID:gvansickle,項目名稱:ucg,代碼行數:9,代碼來源:integer.hpp

示例15: sai_deserialize_ip6_mask

int sai_deserialize_ip6_mask(
        _In_ const char *buffer,
        _Out_ sai_ip6_t mask)
{
    uint64_t value;

    int res = sai_deserialize_uint64(buffer, &value);

    if (res < 0 || value > 128)
    {
        SAI_META_LOG_WARN("failed to deserialize '%.*s' as ip6 mask", MAX_CHARS_PRINT, buffer);
        return SAI_SERIALIZE_ERROR;
    }

    uint64_t high = 0xFFFFFFFFFFFFFFFFUL;
    uint64_t low  = 0xFFFFFFFFFFFFFFFFUL;

    if (value == 128)
    {
    }
    else if (value == 64)
    {
        low = 0;
    }
    else if (value == 0)
    {
        low = 0;
        high = 0;
    }
    else if (value > 64)
    {
        low = low << (128 - value);
    }
    else
    {
        high = high << (64 - value);
        low = 0;
    }

    *((uint64_t*)mask) = __builtin_bswap64(high);
    *((uint64_t*)mask + 1) = __builtin_bswap64(low);

    return res;
}
開發者ID:CentecNetworks,項目名稱:SAI,代碼行數:44,代碼來源:saiserialize.c


注:本文中的__builtin_bswap64函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。