GCS  0.2.3
gu_vec16.h
1 // Copyright (C) 2013 Codership Oy <info@codership.com>
2 
9 #ifndef _gu_vec16_h_
10 #define _gu_vec16_h_
11 
12 #include "gu_macros.h"
13 #include "gu_byteswap.h"
14 
15 #include <string.h>
16 #include <stdint.h>
17 #include <stdbool.h> /* bool */
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* this type will generate SIMD instructions where possible: good for XORing */
24 typedef unsigned long gu_vec16__ __attribute__ ((vector_size (16)));
25 
26 typedef union gu_vec16
27 {
28  gu_vec16__ vec_;
29  uint64_t int_[2]; /* for equality we better use scalar type
30  * since we need scalar return */
31 } gu_vec16_t;
32 
33 static GU_FORCE_INLINE gu_vec16_t
34 gu_vec16_from_byte (unsigned char b)
35 {
36  gu_vec16_t ret;
37  memset (&ret, b, sizeof(ret));
38  return ret;
39 }
40 
41 static GU_FORCE_INLINE gu_vec16_t
42 gu_vec16_from_ptr (const void* ptr)
43 {
44  gu_vec16_t ret;
45  memcpy (&ret, ptr, sizeof(ret));
46  return ret;
47 }
48 
49 static GU_FORCE_INLINE gu_vec16_t
50 gu_vec16_xor (gu_vec16_t l, gu_vec16_t r)
51 {
52  gu_vec16_t ret;
53  ret.vec_ = (l.vec_ ^ r.vec_);
54  return ret;
55 }
56 
57 static GU_FORCE_INLINE bool
58 gu_vec16_neq (gu_vec16_t l, gu_vec16_t r)
59 {
60  return (l.int_[0] != r.int_[0] || l.int_[1] != r.int_[1]);
61 }
62 
63 static GU_FORCE_INLINE bool
64 gu_vec16_eq (gu_vec16_t l, gu_vec16_t r)
65 {
66  return !(gu_vec16_neq (l, r));
67 }
68 
69 static GU_FORCE_INLINE gu_vec16_t
70 gu_vec16_bswap (gu_vec16_t x)
71 {
72  gu_vec16_t ret;
73  ret.int_[0] = gu_bswap64 (x.int_[1]);
74  ret.int_[1] = gu_bswap64 (x.int_[0]);
75  return ret;
76 }
77 
78 #ifdef __cplusplus
79 }
80 
81 static GU_FORCE_INLINE gu_vec16_t
82 operator^ (const gu_vec16_t& l, const gu_vec16_t& r)
83 {
84  return (gu_vec16_xor (l, r));
85 }
86 
87 static GU_FORCE_INLINE bool
88 operator== (const gu_vec16_t& l, const gu_vec16_t& r)
89 {
90  return (gu_vec16_eq (l, r));
91 }
92 
93 #endif
94 
95 #endif /* _gu_vec16_h_ */
Definition: gu_vec16.h:26