You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.9 KiB

/*
* Copyright 2014 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
/* This file should contain all exported functions of libckpool */
#ifndef CKPOOL_H
#define CKPOOL_H
#include "config.h"
#include <stdint.h>
#if HAVE_BYTESWAP_H
# include <byteswap.h>
#endif
#if HAVE_ENDIAN_H
# include <endian.h>
#elif HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif
#ifndef bswap_16
#define bswap_16 __builtin_bswap16
#define bswap_32 __builtin_bswap32
#define bswap_64 __builtin_bswap64
#endif
/* This assumes htobe32 is a macro in endian.h, and if it doesn't exist, then
* htobe64 also won't exist */
#ifndef htobe32
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define htole16(x) (x)
# define le16toh(x) (x)
# define htole32(x) (x)
# define htole64(x) (x)
# define le32toh(x) (x)
# define le64toh(x) (x)
# define be32toh(x) bswap_32(x)
# define be64toh(x) bswap_64(x)
# define htobe16(x) bswap_16(x)
# define htobe32(x) bswap_32(x)
# define htobe64(x) bswap_64(x)
# elif __BYTE_ORDER == __BIG_ENDIAN
# define htole16(x) bswap_16(x)
# define le16toh(x) bswap_16(x)
# define htole32(x) bswap_32(x)
# define le32toh(x) bswap_32(x)
# define le64toh(x) bswap_64(x)
# define htole64(x) bswap_64(x)
# define be32toh(x) (x)
# define be64toh(x) (x)
# define htobe16(x) (x)
# define htobe32(x) (x)
# define htobe64(x) (x)
# endif
#endif
#define unlikely(expr) (__builtin_expect(!!(expr), 0))
#define likely(expr) (__builtin_expect(!!(expr), 1))
#define __maybe_unused __attribute__((unused))
#define uninitialised_var(x) x = x
/* Typedefs are evil but we use this one so often... */
typedef unsigned char uchar;
typedef struct timeval tv_t;
typedef struct timespec ts_t;
static inline void swap_256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = src[7];
dest[1] = src[6];
dest[2] = src[5];
dest[3] = src[4];
dest[4] = src[3];
dest[5] = src[2];
dest[6] = src[1];
dest[7] = src[0];
}
static inline void bswap_256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = bswap_32(src[7]);
dest[1] = bswap_32(src[6]);
dest[2] = bswap_32(src[5]);
dest[3] = bswap_32(src[4]);
dest[4] = bswap_32(src[3]);
dest[5] = bswap_32(src[2]);
dest[6] = bswap_32(src[1]);
dest[7] = bswap_32(src[0]);
}
static inline void flip_32(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
int i;
for (i = 0; i < 8; i++)
dest[i] = bswap_32(src[i]);
}
static inline void flip_80(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
int i;
for (i = 0; i < 20; i++)
dest[i] = bswap_32(src[i]);
}
#endif /* CKPOOL_H */