Debian Codegraph @

cvd_src/SSE2/faster_corner_9.cxx

raw symbols SCIP
1 #include <cvd/fast_corner.h>
2
3 #include <cvd/utility.h>
4 #include <list>
5 #include <vector>
6 using namespace CVD;
7 using namespace std;
8
9 #include <emmintrin.h>
10
11 #include "cvd_src/SSE2/faster_corner_utilities.h"
12 #include "cvd_src/fast/prototypes.h"
13
14 namespace CVD
15 {
16 #include "cvd_src/corner_9.h"
17
18 template <bool Aligned>
19 void faster_corner_detect_9(const BasicImage<byte>& I, std::vector<ImageRef>& corners, const int barrier)
20 {
21 const int row_stride = I.row_stride();
22 const int stride = 3 * row_stride;
23
24 const __m128i barriers = _mm_set1_epi8((byte)barrier);
25
26 int xend = I.size().x - 3;
27 xend -= (I.size().x - 3) % 16;
28
29 for(int y = 3; y < I.size().y - 3; y++)
30 {
31 for(int x = 3; x < 16; x++)
32 if(is_corner_9<Less>(&I[y][x], I.row_stride(), barrier) || is_corner_9<Greater>(&I[y][x], I.row_stride(), barrier))
33 corners.push_back(ImageRef(x, y));
34
35 for(int x = 16; x < xend; x += 16)
36 {
37 const byte* p = &I[y][x];
38 __m128i lo, hi;
39 {
40 const __m128i here = load_si128<Aligned>((const __m128i*)(p));
41 lo = _mm_subs_epu8(here, barriers);
42 hi = _mm_adds_epu8(barriers, here);
43 }
44 unsigned int ans_0, ans_8, possible;
45 {
46 __m128i top = load_si128<Aligned>((const __m128i*)(p - stride));
47 __m128i bottom = load_si128<Aligned>((const __m128i*)(p + stride));
48
49 CHECK_BARRIER(lo, hi, top, ans_0);
50 CHECK_BARRIER(lo, hi, bottom, ans_8);
51 possible = ans_0 | ans_8;
52 if(!possible)
53 continue;
54 }
55
56 unsigned int ans_15, ans_1;
57 {
58 __m128i a = _mm_loadu_si128((const __m128i*)(p - 1 - stride));
59 __m128i c = _mm_insert_epi16(_mm_srli_si128(a, 2), *(const unsigned short*)(p + 15 - stride), 7);
60 CHECK_BARRIER(lo, hi, a, ans_15);
61 CHECK_BARRIER(lo, hi, c, ans_1);
62 possible &= ans_8 | (ans_15 & ans_1);
63 if(!possible)
64 continue;
65 }
66
67 unsigned int ans_9, ans_7;
68 {
69 __m128i d = _mm_loadu_si128((const __m128i*)(p - 1 + stride));
70 __m128i f = _mm_insert_epi16(_mm_srli_si128(d, 2), *(const unsigned short*)(p + 15 + stride), 7);
71 CHECK_BARRIER(lo, hi, d, ans_9);
72 CHECK_BARRIER(lo, hi, f, ans_7);
73 possible &= ans_9 | (ans_0 & ans_1);
74 possible &= ans_7 | (ans_15 & ans_0);
75 if(!possible)
76 continue;
77 }
78
79 unsigned int ans_12, ans_4;
80 {
81 __m128i left = _mm_loadu_si128((const __m128i*)(p - 3));
82 __m128i right = _mm_loadu_si128((const __m128i*)(p + 3));
83 CHECK_BARRIER(lo, hi, left, ans_12);
84 CHECK_BARRIER(lo, hi, right, ans_4);
85 possible &= ans_12 | (ans_4 & (ans_1 | ans_7));
86 possible &= ans_4 | (ans_12 & (ans_9 | ans_15));
87 if(!possible)
88 continue;
89 }
90
91 unsigned int ans_14, ans_6;
92 {
93 __m128i ul = _mm_loadu_si128((const __m128i*)(p - 2 - 2 * row_stride));
94 __m128i lr = _mm_loadu_si128((const __m128i*)(p + 2 + 2 * row_stride));
95 CHECK_BARRIER(lo, hi, ul, ans_14);
96 CHECK_BARRIER(lo, hi, lr, ans_6);
97 {
98 const unsigned int ans_6_7 = ans_6 & ans_7;
99 possible &= ans_14 | (ans_6_7 & (ans_4 | (ans_8 & ans_9)));
100 possible &= ans_1 | (ans_6_7) | ans_12;
101 }
102 {
103 const unsigned int ans_14_15 = ans_14 & ans_15;
104 possible &= ans_6 | (ans_14_15 & (ans_12 | (ans_0 & ans_1)));
105 possible &= ans_9 | (ans_14_15) | ans_4;
106 }
107 if(!possible)
108 continue;
109 }
110
111 unsigned int ans_10, ans_2;
112 {
113 __m128i ll = _mm_loadu_si128((const __m128i*)(p - 2 + 2 * row_stride));
114 __m128i ur = _mm_loadu_si128((const __m128i*)(p + 2 - 2 * row_stride));
115 CHECK_BARRIER(lo, hi, ll, ans_10);
116 CHECK_BARRIER(lo, hi, ur, ans_2);
117 {
118 const unsigned int ans_1_2 = ans_1 & ans_2;
119 possible &= ans_10 | (ans_1_2 & ((ans_0 & ans_15) | ans_4));
120 possible &= ans_12 | (ans_1_2) | (ans_6 & ans_7);
121 }
122 {
123 const unsigned int ans_9_10 = ans_9 & ans_10;
124 possible &= ans_2 | (ans_9_10 & ((ans_7 & ans_8) | ans_12));
125 possible &= ans_4 | (ans_9_10) | (ans_14 & ans_15);
126 }
127 possible &= ans_8 | ans_14 | ans_2;
128 possible &= ans_0 | ans_10 | ans_6;
129 if(!possible)
130 continue;
131 }
132
133 unsigned int ans_13, ans_5;
134 {
135 __m128i g = _mm_loadu_si128((const __m128i*)(p - 3 - row_stride));
136 __m128i l = _mm_loadu_si128((const __m128i*)(p + 3 + row_stride));
137 CHECK_BARRIER(lo, hi, g, ans_13);
138 CHECK_BARRIER(lo, hi, l, ans_5);
139 const unsigned int ans_15_0 = ans_15 & ans_0;
140 const unsigned int ans_7_8 = ans_7 & ans_8;
141 {
142 const unsigned int ans_12_13 = ans_12 & ans_13;
143 possible &= ans_5 | (ans_12_13 & ans_14 & ((ans_15_0) | ans_10));
144 possible &= ans_7 | (ans_1 & ans_2) | (ans_12_13);
145 possible &= ans_2 | (ans_12_13) | (ans_7_8);
146 }
147 {
148 const unsigned int ans_4_5 = ans_4 & ans_5;
149 const unsigned int ans_9_10 = ans_9 & ans_10;
150 possible &= ans_13 | (ans_4_5 & ans_6 & ((ans_7_8) | ans_2));
151 possible &= ans_15 | (ans_4_5) | (ans_9_10);
152 possible &= ans_10 | (ans_4_5) | (ans_15_0);
153 possible &= ans_15 | (ans_9_10) | (ans_4_5);
154 }
155
156 possible &= ans_8 | (ans_13 & ans_14) | ans_2;
157 possible &= ans_0 | (ans_5 & ans_6) | ans_10;
158 if(!possible)
159 continue;
160 }
161
162 unsigned int ans_11, ans_3;
163 {
164 __m128i ii = _mm_loadu_si128((const __m128i*)(p - 3 + row_stride));
165 __m128i jj = _mm_loadu_si128((const __m128i*)(p + 3 - row_stride));
166 CHECK_BARRIER(lo, hi, ii, ans_11);
167 CHECK_BARRIER(lo, hi, jj, ans_3);
168 {
169 const unsigned int ans_2_3 = ans_2 & ans_3;
170 possible &= ans_11 | (ans_2_3 & ans_4 & ((ans_0 & ans_1) | (ans_5 & ans_6)));
171 possible &= ans_13 | (ans_7 & ans_8) | (ans_2_3);
172 possible &= ans_8 | (ans_2_3) | (ans_13 & ans_14);
173 }
174 {
175 const unsigned int ans_11_12 = ans_11 & ans_12;
176 possible &= ans_3 | (ans_10 & ans_11_12 & ((ans_8 & ans_9) | (ans_13 & ans_14)));
177 possible &= ans_1 | (ans_11_12) | (ans_6 & ans_7);
178 possible &= ans_6 | (ans_0 & ans_1) | (ans_11_12);
179 }
180 {
181 const unsigned int ans_3_4 = ans_3 & ans_4;
182 possible &= ans_9 | (ans_3_4) | (ans_14 & ans_15);
183 possible &= ans_14 | (ans_8 & ans_9) | (ans_3_4);
184 }
185 {
186 const unsigned int ans_10_11 = ans_10 & ans_11;
187 possible &= ans_5 | (ans_15 & ans_0) | (ans_10_11);
188 possible &= ans_0 | (ans_10_11) | (ans_5 & ans_6);
189 }
190 if(!possible)
191 continue;
192 }
193
194 possible |= (possible >> 16);
195
196 //if(possible & 0x0f) //Does this make it faster?
197 {
198 if(possible & (1 << 0))
199 corners.push_back(ImageRef(x + 0, y));
200 if(possible & (1 << 1))
201 corners.push_back(ImageRef(x + 1, y));
202 if(possible & (1 << 2))
203 corners.push_back(ImageRef(x + 2, y));
204 if(possible & (1 << 3))
205 corners.push_back(ImageRef(x + 3, y));
206 if(possible & (1 << 4))
207 corners.push_back(ImageRef(x + 4, y));
208 if(possible & (1 << 5))
209 corners.push_back(ImageRef(x + 5, y));
210 if(possible & (1 << 6))
211 corners.push_back(ImageRef(x + 6, y));
212 if(possible & (1 << 7))
213 corners.push_back(ImageRef(x + 7, y));
214 }
215 //if(possible & 0xf0) //Does this mak( , fast)r?
216 {
217 if(possible & (1 << 8))
218 corners.push_back(ImageRef(x + 8, y));
219 if(possible & (1 << 9))
220 corners.push_back(ImageRef(x + 9, y));
221 if(possible & (1 << 10))
222 corners.push_back(ImageRef(x + 10, y));
223 if(possible & (1 << 11))
224 corners.push_back(ImageRef(x + 11, y));
225 if(possible & (1 << 12))
226 corners.push_back(ImageRef(x + 12, y));
227 if(possible & (1 << 13))
228 corners.push_back(ImageRef(x + 13, y));
229 if(possible & (1 << 14))
230 corners.push_back(ImageRef(x + 14, y));
231 if(possible & (1 << 15))
232 corners.push_back(ImageRef(x + 15, y));
233 }
234 }
235
236 for(int x = xend; x < I.size().x - 3; x++)
237 if(is_corner_9<Less>(&I[y][x], I.row_stride(), barrier) || is_corner_9<Greater>(&I[y][x], I.row_stride(), barrier))
238 corners.push_back(ImageRef(x, y));
239 }
240 }
241
242 void fast_corner_detect_9(const BasicImage<byte>& I, std::vector<ImageRef>& corners, int barrier)
243 {
244 if(I.size().x < 22)
245 {
246 fast_corner_detect_plain_9(I, corners, barrier);
247 return;
248 }
249 else if(I.size().x < 22 || I.size().y < 7)
250 return;
251
252 if(is_aligned<16>(I[0]) && is_aligned<16>(I[1]))
253 faster_corner_detect_9<true>(I, corners, barrier);
254 else
255 faster_corner_detect_9<false>(I, corners, barrier);
256 }
257
258 }