PERFORCE change 1198734 for review
John-Mark Gurney
jmg at FreeBSD.org
Mon Sep 8 04:49:33 UTC 2014
http://p4web.freebsd.org/@@1198734?ac=10
Change 1198734 by jmg at 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 */
More information about the p4-projects
mailing list