annotate src/libSAD/SFMT-alti.h @ 4874:43eb8388760d

Enable opening jump to file dialog from audtool.
author John Lindgren <john.lindgren@tds.net>
date Sun, 26 Apr 2009 13:15:34 -0400
parents 704607c1f858
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4232
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
1 /**
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
2 * @file SFMT-alti.h
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
3 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
4 * @brief SIMD oriented Fast Mersenne Twister(SFMT)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
5 * pseudorandom number generator
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
6 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
7 * @author Mutsuo Saito (Hiroshima University)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
8 * @author Makoto Matsumoto (Hiroshima University)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
9 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
10 * Copyright (C) 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
11 * University. All rights reserved.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
12 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
13 * The new BSD License is applied to this software.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
14 * see LICENSE.txt
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
15 */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
16
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
17 #ifndef SFMT_ALTI_H
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
18 #define SFMT_ALTI_H
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
19
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
20 inline static vector unsigned int vec_recursion(vector unsigned int a,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
21 vector unsigned int b,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
22 vector unsigned int c,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
23 vector unsigned int d)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
24 ALWAYSINLINE;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
25
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
26 /**
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
27 * This function represents the recursion formula in AltiVec and BIG ENDIAN.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
28 * @param a a 128-bit part of the interal state array
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
29 * @param b a 128-bit part of the interal state array
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
30 * @param c a 128-bit part of the interal state array
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
31 * @param d a 128-bit part of the interal state array
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
32 * @return output
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
33 */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
34 inline static vector unsigned int vec_recursion(vector unsigned int a,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
35 vector unsigned int b,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
36 vector unsigned int c,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
37 vector unsigned int d) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
38
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
39 const vector unsigned int sl1 = ALTI_SL1;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
40 const vector unsigned int sr1 = ALTI_SR1;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
41 #ifdef ONLY64
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
42 const vector unsigned int mask = ALTI_MSK64;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
43 const vector unsigned char perm_sl = ALTI_SL2_PERM64;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
44 const vector unsigned char perm_sr = ALTI_SR2_PERM64;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
45 #else
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
46 const vector unsigned int mask = ALTI_MSK;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
47 const vector unsigned char perm_sl = ALTI_SL2_PERM;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
48 const vector unsigned char perm_sr = ALTI_SR2_PERM;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
49 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
50 vector unsigned int v, w, x, y, z;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
51 x = vec_perm(a, (vector unsigned int)perm_sl, perm_sl);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
52 v = a;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
53 y = vec_sr(b, sr1);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
54 z = vec_perm(c, (vector unsigned int)perm_sr, perm_sr);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
55 w = vec_sl(d, sl1);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
56 z = vec_xor(z, w);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
57 y = vec_and(y, mask);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
58 v = vec_xor(v, x);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
59 z = vec_xor(z, y);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
60 z = vec_xor(z, v);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
61 return z;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
62 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
63
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
64 /**
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
65 * This function fills the internal state array with pseudorandom
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
66 * integers.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
67 */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
68 inline static void gen_rand_all(void) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
69 int i;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
70 vector unsigned int r, r1, r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
71
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
72 r1 = sfmt[N - 2].s;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
73 r2 = sfmt[N - 1].s;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
74 for (i = 0; i < N - POS1; i++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
75 r = vec_recursion(sfmt[i].s, sfmt[i + POS1].s, r1, r2);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
76 sfmt[i].s = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
77 r1 = r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
78 r2 = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
79 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
80 for (; i < N; i++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
81 r = vec_recursion(sfmt[i].s, sfmt[i + POS1 - N].s, r1, r2);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
82 sfmt[i].s = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
83 r1 = r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
84 r2 = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
85 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
86 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
87
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
88 /**
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
89 * This function fills the user-specified array with pseudorandom
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
90 * integers.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
91 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
92 * @param array an 128-bit array to be filled by pseudorandom numbers.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
93 * @param size number of 128-bit pesudorandom numbers to be generated.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
94 */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
95 inline static void gen_rand_array(w128_t *array, int size) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
96 int i, j;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
97 vector unsigned int r, r1, r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
98
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
99 r1 = sfmt[N - 2].s;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
100 r2 = sfmt[N - 1].s;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
101 for (i = 0; i < N - POS1; i++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
102 r = vec_recursion(sfmt[i].s, sfmt[i + POS1].s, r1, r2);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
103 array[i].s = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
104 r1 = r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
105 r2 = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
106 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
107 for (; i < N; i++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
108 r = vec_recursion(sfmt[i].s, array[i + POS1 - N].s, r1, r2);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
109 array[i].s = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
110 r1 = r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
111 r2 = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
112 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
113 /* main loop */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
114 for (; i < size - N; i++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
115 r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
116 array[i].s = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
117 r1 = r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
118 r2 = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
119 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
120 for (j = 0; j < 2 * N - size; j++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
121 sfmt[j].s = array[j + size - N].s;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
122 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
123 for (; i < size; i++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
124 r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
125 array[i].s = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
126 sfmt[j++].s = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
127 r1 = r2;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
128 r2 = r;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
129 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
130 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
131
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
132 #ifndef ONLY64
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
133 #if defined(__APPLE__)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
134 #define ALTI_SWAP (vector unsigned char) \
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
135 (4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
136 #else
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
137 #define ALTI_SWAP {4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
138 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
139 /**
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
140 * This function swaps high and low 32-bit of 64-bit integers in user
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
141 * specified array.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
142 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
143 * @param array an 128-bit array to be swaped.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
144 * @param size size of 128-bit array.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
145 */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
146 inline static void swap(w128_t *array, int size) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
147 int i;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
148 const vector unsigned char perm = ALTI_SWAP;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
149
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
150 for (i = 0; i < size; i++) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
151 array[i].s = vec_perm(array[i].s, (vector unsigned int)perm, perm);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
152 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
153 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
154 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
155
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
156 #endif