# source:trunk/lib/multiplex.hpp

Last change on this file was 3341, checked in by cameron, 6 years ago

Multiplex/demultiplex routines

File size: 1.8 KB
Line
1#ifndef MULTIPLEX_HPP
2#define MULTIPLEX_HPP
3
4/*=============================================================================
5        Copyright (C) 2013, Robert D. Cameron
7=============================================================================*/
8
9// Multiplex/demultiplex 3-to-2/2-to-3 with the followiing encodings.
10// (y, z) = (1, 1) => a
11// (y, z) = (1, 0) => b
12// (y, z) = (0, 1) => c
13static IDISA_ALWAYS_INLINE
14void multiplex3to2(BitBlock a, BitBlock b, BitBlock c, BitBlock & y, BitBlock & z) {
15        y = simd_or(a, b);
16        z = simd_or(a, c);
17}
18
19static IDISA_ALWAYS_INLINE
20void demultiplex2to3(BitBlock y, BitBlock z, BitBlock & a, BitBlock & b, BitBlock & c) {
21        a = simd_and(y, z);
22        b = simd_andc(y, z);
23        c = simd_andc(z, y);
24}
25
26// Multiplex/demultiplex 7-to-3/3-to-7 with the followiing encodings.
27// (x, y, z) = (1, 1, 1) ==> a
28// (x, y, z) = (1, 1, 0) ==> b
29// (x, y, z) = (1, 0, 1) ==> c
30// (x, y, z) = (1, 0, 0) ==> d
31// (x, y, z) = (0, 1, 1) ==> e
32// (x, y, z) = (0, 1, 0) ==> f
33// (x, y, z) = (0, 0, 1) ==> g
34static IDISA_ALWAYS_INLINE
35void multiplex7to3(BitBlock a, BitBlock b, BitBlock c, BitBlock d, BitBlock e, BitBlock f, BitBlock g,
36                                   BitBlock & x, BitBlock & y, BitBlock & z) {
37        x = simd_or(simd_or(a, b), simd_or(c, d));
38        y = simd_or(simd_or(a, b), simd_or(e, f));
39        z = simd_or(simd_or(a, c), simd_or(e, g));
40}
41
42static IDISA_ALWAYS_INLINE
43void demultiplex3to7(BitBlock x, BitBlock y, BitBlock z,
44                                         BitBlock & a, BitBlock & b, BitBlock & c, BitBlock & d, BitBlock & e, BitBlock & f, BitBlock & g) {
45        a = simd_and(x, simd_and(y, z));
46        b = simd_and(x, simd_andc(y, z));
47        c = simd_and(x, simd_andc(z, y));
48        d = simd_andc(x, simd_or(y, z));
49        e = simd_and(y, simd_andc(z, x));
50        f = simd_andc(y, simd_or(x, z));
51        g = simd_andc(z, simd_or(x, y));
52}
53
54
55
56#endif // MULTIPLEX_HPP
57
58
Note: See TracBrowser for help on using the repository browser.