Date: Mon, 8 Sep 2014 04:49:21 GMT From: John-Mark Gurney <jmg@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 1198734 for review Message-ID: <201409080449.s884nLTm020783@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@1198734?ac=10 Change 1198734 by jmg@jmg_carbon2 on 2014/08/14 19:42:12 put MacOSX compat stuff under ifdef __APPLE__ use enc/dec for reading/writing instead of hand rolled versions... assume that __APPLE__ is always on a non-strict alignment machine since I don't know how to check for this on MacOSX... update a comment.. Affected files ... .. //depot/projects/opencrypto/sys/opencrypto/gfmult.h#3 edit Differences ... ==== //depot/projects/opencrypto/sys/opencrypto/gfmult.h#3 (text+ko) ==== @@ -32,10 +32,10 @@ #ifndef _GFMULT_H_ #define _GFMULT_H_ -#if 0 +#ifdef __APPLE__ #define __aligned(x) __attribute__((__aligned__(x))) -#define be64toh(x) __builtin_bswap64(x) -#define htobe64(x) __builtin_bswap64(x) +#define be64dec(buf) __builtin_bswap64(*(uint64_t *)buf) +#define be64enc(buf, x) (*(uint64_t *)buf = __builtin_bswap64(x)) #else #include <sys/endian.h> #endif @@ -49,8 +49,8 @@ #define REQ_ALIGN (16 * 4) /* - * These are the values striped across cache lines. Note that the indexes - * are bit reversed to make accessing easier. + * The rows are striped across cache lines. Note that the indexes + * are bit reversed to make accesses quicker. */ struct gf128table { uint32_t a[16] __aligned(REQ_ALIGN); /* bits 0 - 31 */ @@ -83,38 +83,15 @@ #define GF128_EQ(a, b) ((((a).v[0] ^ (b).v[0]) | \ ((a).v[1] ^ (b).v[1])) == 0) -static inline uint64_t -gf128_getuint64_t(const uint8_t *buf) -{ -#ifdef __NO_STRICT_ALIGNMENT - return *(uint64_t *)buf; -#else - uint64_t tmp; - - bcopy(buf, &tmp, sizeof tmp); - return tmp; -#endif -} - -static inline void -gf128_putuint64_t(uint64_t val, uint8_t *buf) -{ -#ifdef __NO_STRICT_ALIGNMENT - *(uint64_t *)buf = val; -#else - bcopy(&val, buf, sizeof val); -#endif -} - static inline struct gf128 gf128_read(const uint8_t *buf) { struct gf128 r; - r.v[0] = be64toh(gf128_getuint64_t(buf)); + r.v[0] = be64dec(buf); buf += sizeof(uint64_t); - r.v[1] = be64toh(gf128_getuint64_t(buf)); + r.v[1] = be64dec(buf); return r; } @@ -124,10 +101,10 @@ { uint64_t tmp; - gf128_putuint64_t(htobe64(v.v[0]), buf); + be64enc(buf, v.v[0]); buf += sizeof tmp; - gf128_putuint64_t(htobe64(v.v[1]), buf); + be64enc(buf, v.v[1]); } static inline struct gf128 __pure /* XXX - __pure2 instead */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409080449.s884nLTm020783>