1 | %----------------------------------------------------------------------------- |
---|
2 | % |
---|
3 | % asplos094-cameron.tex |
---|
4 | % Robert D. Cameron and Dan Lin |
---|
5 | % |
---|
6 | % Based on sigplanconf-template.tex (2005-02-15), by Paul C. Anagnostopoulos |
---|
7 | % |
---|
8 | %----------------------------------------------------------------------------- |
---|
9 | \input epsf |
---|
10 | |
---|
11 | %\documentclass[preprint,natbib,10pt]{sigplanconf} |
---|
12 | %\documentclass[natbib,10pt]{sigplanconf} |
---|
13 | \documentclass[10pt]{sigplanconf} |
---|
14 | |
---|
15 | \usepackage{amsmath} |
---|
16 | \usepackage{graphicx} |
---|
17 | |
---|
18 | \begin{document} |
---|
19 | |
---|
20 | \conferenceinfo{ASPLOS'09,} {March 7--11, 2009, Washington, DC, USA.} |
---|
21 | \CopyrightYear{2009} |
---|
22 | \copyrightdata{978-1-60558-215-3/09/03} |
---|
23 | |
---|
24 | |
---|
25 | \titlebanner{banner above paper title} % These are ignored unless |
---|
26 | \preprintfooter{short description of paper} % 'preprint' option specified. |
---|
27 | |
---|
28 | \title{Architectural Support for SWAR Text Processing with Parallel Bit |
---|
29 | Streams: The Inductive Doubling Principle} |
---|
30 | %\subtitle{Subtitle Text, if any} |
---|
31 | |
---|
32 | \authorinfo{Robert D. Cameron \and Dan Lin} |
---|
33 | {School of Computing Science, Simon Fraser University} |
---|
34 | {\{cameron, lindanl\}@cs.sfu.ca} |
---|
35 | |
---|
36 | |
---|
37 | \maketitle |
---|
38 | |
---|
39 | \begin{abstract} |
---|
40 | Parallel bit stream algorithms exploit the SWAR (SIMD within a |
---|
41 | register) capabilities of commodity |
---|
42 | processors in high-performance text processing applications such as |
---|
43 | UTF-8 to UTF-16 transcoding, XML parsing, string search and regular expression |
---|
44 | matching. Direct architectural support for these algorithms in future SIMD |
---|
45 | instruction sets could further increase performance as well as simplifying the |
---|
46 | programming task. A set of simple SWAR instruction set extensions are proposed |
---|
47 | for this purpose based on the principle of systematic support for inductive |
---|
48 | doubling as an algorithmic technique. These extensions are shown to |
---|
49 | significantly reduce instruction count in core parallel bit stream algorithms, |
---|
50 | often providing a 3X or better improvement. The extensions are also shown to be useful |
---|
51 | for SIMD programming in other application areas, including providing a |
---|
52 | systematic treatment for horizontal operations. An implementation model for |
---|
53 | these extensions |
---|
54 | involves relatively simple circuitry added to the operand fetch components |
---|
55 | in a pipelined processor. |
---|
56 | \end{abstract} |
---|
57 | |
---|
58 | \category{CR-number}{subcategory}{third-level} |
---|
59 | |
---|
60 | \terms |
---|
61 | term1, term2 |
---|
62 | |
---|
63 | \keywords |
---|
64 | keyword1, keyword2 |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | \section{Introduction} |
---|
69 | |
---|
70 | In the landscape of parallel computing research, finding ways to |
---|
71 | exploit intrachip (multicore) and intraregister (SWAR) parallelism |
---|
72 | for text processing and other non-numeric applications is particularly |
---|
73 | challenging. Indeed, in documenting this landscape, a widely cited Berkeley |
---|
74 | study \cite{Landscape} identifies the finite-state machine algorithms associated |
---|
75 | with text processing to be the hardest of the thirteen ``dwarves'' |
---|
76 | to parallelize, concluding that nothing seems to help. Indeed, |
---|
77 | the study even speculates that applications in this area may simply be |
---|
78 | ``embarrasingly sequential,'' easy to tackle for traditional |
---|
79 | sequential processing approaches suitable for uniprocessors, |
---|
80 | but perhaps fundamentally unsuited to parallel methods. |
---|
81 | |
---|
82 | One approach that shows some promise, however, is the |
---|
83 | method of parallel bit streams, recently applied to |
---|
84 | UTF-8 to UTF-16 transcoding \cite{PPoPP08}, XML parsing \cite{CASCON08} |
---|
85 | and amino acid sequencing\cite{Green}. |
---|
86 | In this method, byte-oriented character data is first transposed to eight |
---|
87 | parallel bit streams, one for each bit position within the character code |
---|
88 | units (bytes). Loading bit stream data into 128-bit SIMD registers, |
---|
89 | then, allows data from 128 consecutive code units to be represented and |
---|
90 | processed at once. Bitwise logic and shift operations, bit scans, |
---|
91 | population counts and other bit-based operations are then used to carry |
---|
92 | out the work. |
---|
93 | |
---|
94 | The cited study of UTF-8 to UTF-16 transcoding reports a 3X to 25X |
---|
95 | speed-up in using parallel bit stream techniques on SIMD-capable uniprocessors |
---|
96 | employing the SSE or Altivec instruction sets. A full implementation |
---|
97 | for each of these platforms is documented using literate programming techniques |
---|
98 | and available as an open source code base \cite{u8u16}. |
---|
99 | Although this transcoding task represents but a single text processing kernel, |
---|
100 | it is widely cited as a critical bottleneck in XML parsing, accounting for 30\% or more |
---|
101 | of processing time\cite{NicolaJohn03, Perkins05, Psaila06}. The example is also interesting in that |
---|
102 | it illustrates a text processing task that can largely |
---|
103 | be carried out using SIMD operations even though |
---|
104 | UTF-8 character sequences are variable length. Indeed, one weakness of the |
---|
105 | actual implementation is that it reverts to byte-at-a-time processing |
---|
106 | at block boundaries, employing a block shortening strategy to |
---|
107 | reduce block lengths to as low as 125 bytes from 128. |
---|
108 | With more capable SIMD instruction set architectures providing |
---|
109 | better facilities for multiregister shifts and larger register |
---|
110 | files, a solution employing SIMD techniques for virtually all |
---|
111 | of the main work would maintain better data alignment, avoid |
---|
112 | problems of register pressure and be easier to parallelize across |
---|
113 | multiple cores. It should also naturally scale to 256-bit SIMD technology |
---|
114 | such as the expected AVX technology of Intel. |
---|
115 | |
---|
116 | The report addressing the broader problem of XML parsing is perhaps more |
---|
117 | interesting, demonstrating the utility of parallel bit stream techniques |
---|
118 | in delivering performance benefits through a significant portion of the |
---|
119 | web technology stack. In an XML statistics gathering application, |
---|
120 | including the implementation of XML well-formedness checking, an |
---|
121 | overall 3X to 10X performance improvement is achieved in using |
---|
122 | the parallel bit stream methods in comparison with a similarly |
---|
123 | coded application using such well known parsers as Expat and Xerces. |
---|
124 | Although still a work in progress, the parser has functional |
---|
125 | coverage of XML and related specifications comparable to, but somewhat |
---|
126 | beyond Expat. The study also identifies promising further |
---|
127 | work in extending the parallel bit stream methods to parallel |
---|
128 | hash value computation and parallel regular expression matching |
---|
129 | for the purpose of validating XML datatype declarations in |
---|
130 | accord with XML Schema. |
---|
131 | |
---|
132 | Given these promising initial results in the application of |
---|
133 | parallel bit stream methods, what role might architectural support play in |
---|
134 | further enhancing this route to parallelization of text processing? |
---|
135 | This paper addresses this question through presentation and |
---|
136 | analysis of a constructive proposal: a set of SIMD instruction set |
---|
137 | features based on the principle of systematic support for |
---|
138 | inductive doubling algorithms. Inductive doubling refers |
---|
139 | to a general property of certain kinds of algorithm that |
---|
140 | systematically double the values of field widths or other |
---|
141 | data attributes with each iteration. In essence, the goal |
---|
142 | of the proposed features is to support such algorithms |
---|
143 | with specific facilities to transition between successive power-of-2 field |
---|
144 | widths. These transitions are quite frequent in several critical |
---|
145 | algorithms for parallel bit streams. These transitions also |
---|
146 | occur in other applications as well. In related work, |
---|
147 | efficient automatic interleaving based on power-of-2 strides has been |
---|
148 | reported quite useful for a number of SIMD kernels \cite{Nuzman}. |
---|
149 | The specific features presented herein will be referred to |
---|
150 | as IDISA: inductive doubling instruction set architecture. |
---|
151 | |
---|
152 | The remainder of this paper is organized as follows. |
---|
153 | The second section of this paper introduces IDISA and the |
---|
154 | SIMD notation used throughout this paper. The third |
---|
155 | section moves on to discuss an evaluation methodology |
---|
156 | for IDISA in comparison to two reference architectures |
---|
157 | motivated by the SSE and Altivec instruction sets. |
---|
158 | The fourth section provides a short first example of |
---|
159 | the inductive doubling principle in action through |
---|
160 | the case of population count. Sections 5 through 7 |
---|
161 | then address the application of IDISA to core |
---|
162 | algorithms in text processing with parallel bit |
---|
163 | streams. |
---|
164 | The eighth section then considers the potential role of |
---|
165 | IDISA in supporting applications beyond parallel bit streams. |
---|
166 | Section 9 addresses IDISA implementation while |
---|
167 | Section 10 concludes the paper with a summary of |
---|
168 | results and directions for further work. |
---|
169 | |
---|
170 | |
---|
171 | \section{Inductive Doubling Architecture} |
---|
172 | |
---|
173 | This section presents an idealized model for a single-instruction |
---|
174 | multiple-data (SIMD) instruction set architecture designed |
---|
175 | specifically to support inductive doubling algorithms in the |
---|
176 | domain of parallel bit stream programming. The architecture is idealized |
---|
177 | in the sense that we concentrate on only the necessary features |
---|
178 | for our purpose, without enumerating the additional |
---|
179 | operations that would be required for |
---|
180 | SIMD applications in other domains. The goal is to focus |
---|
181 | on the principles of inductive doubling support in a way |
---|
182 | that can accommodate a variety of realizations as other |
---|
183 | design constraints are brought to bear on the overall instruction set |
---|
184 | design. First we introduce a simple model and notation for |
---|
185 | SIMD operations in general and then present the four key |
---|
186 | features of an idealized architecture in support of parallel |
---|
187 | bit stream programming. |
---|
188 | |
---|
189 | The idealized architecture supports typical SIMD integer |
---|
190 | operations common to existing commodity architectures such as SSE |
---|
191 | and Altivec. The architecture is defined to support SIMD |
---|
192 | operations on registers of size $N=2^K$ bits, for some integer $K$. |
---|
193 | Typical values of $K$ for commodity processors include $K=6$ for |
---|
194 | the 64-bit registers of Intel MMX and Sun VIS technology, $K=7$ for |
---|
195 | the 128-bit registers of SSE and Altivec technology and $K=8$ for |
---|
196 | the upcoming Intel AVX technology. The registers may be |
---|
197 | partitioned into $N/n$ fields of width $n=2^k$ bits for some values |
---|
198 | of $k \leq K$. Typical values of $k$ used on commodity processors |
---|
199 | include $k = 3$ for SIMD operations on 8-bit fields (bytes), |
---|
200 | $k = 4$ for operations on 16-bit fields and $k = 5$ for operations |
---|
201 | on 32-bit fields. Whenever a register $r$ is partitioned into $n$-bit |
---|
202 | fields, the fields are indexed $r_n[0]$ through $r_n[N/n-1]$. |
---|
203 | Field $r_n[i]$ consists of bits $i \times n$ through $(i+1) \times n -1$ of |
---|
204 | register $r$, using big-endian numbering. |
---|
205 | |
---|
206 | Let \verb:simd<n>: represent the class of SIMD operations defined |
---|
207 | on fields of size $n$ using C++ template syntax. Given a |
---|
208 | binary function $F_n$ on $n$-bit fields, we denote the SIMD |
---|
209 | version of this operation as \verb#simd<n>::F#. Given two |
---|
210 | SIMD registers \verb:a: and \verb:b: holding values $a$ and $b$, |
---|
211 | respectively, the operation \verb#r=simd<n>::F(a,b)# stores |
---|
212 | the value $r$ in the register \verb:r: as determined by |
---|
213 | the simultaneous calculation of individual field values in |
---|
214 | accord with the following equation. |
---|
215 | \[ r_i = F_n(a_i, b_i) \] |
---|
216 | |
---|
217 | For example, addition(\verb:add:), subtraction (\verb:sub:) and shift left |
---|
218 | logical (\verb:sll:) may be defined as binary functions on $n$-bit unsigned |
---|
219 | integers as follows. |
---|
220 | %\singlespace |
---|
221 | \begin{eqnarray} |
---|
222 | \mbox{add}_n(a,b) & = & (a+b) \bmod 2^n \\ |
---|
223 | \mbox{sub}_n(a,b) & = & (a-b+2^n) \bmod 2^n \\ |
---|
224 | \mbox{sll}_n(a,b) & = & a \times 2^{b \bmod n} \bmod 2^n |
---|
225 | \end{eqnarray} |
---|
226 | %\doublespace |
---|
227 | The SSE and Altivec instruction sets support |
---|
228 | each of the addition and subtraction operations in SIMD form |
---|
229 | for 8, 16 and 32-bit fields, while the SSE set also includes |
---|
230 | the 64-bit forms. For example, \verb#simd<8>::add# in our |
---|
231 | nomenclature is provided by the operation \verb:paddb: |
---|
232 | on SSE and the operation \verb:vaddubm: on Altivec. |
---|
233 | The equivalents of \verb#simd<8>::sll#, \verb#simd<16>::sll#, and |
---|
234 | \verb#simd<32>::sll# are avilable on Altivec; the SSE facilities are |
---|
235 | more constrained, requiring that all field shifts by the same amount. |
---|
236 | |
---|
237 | Given these definitions and notation, we now present |
---|
238 | the four key elements of an inductive doubling architecture. |
---|
239 | The first is a definition of a core set of binary functions |
---|
240 | on $n$-bit fields for all field widths $n=2^k$ for $0 \leq k \leq K$. |
---|
241 | The second is a set of {\em half-operand modifiers} that allow |
---|
242 | the inductive processing of fields of size $2n$ in terms of |
---|
243 | combinations of $n$-bit values selected from the fields. |
---|
244 | The third is the definition of packing operations that compress |
---|
245 | two consecutive registers of $n$-bit values into a single |
---|
246 | register of $n/2$-bit values. The fourth is the definition |
---|
247 | of merging operations that produce a set of $2n$ bit fields |
---|
248 | by concatenating corresponding $n$-bit fields from two |
---|
249 | parallel registers. Each of these features is described below. |
---|
250 | |
---|
251 | For the purpose of direct and efficient support for inductive |
---|
252 | doubling algorithms on bit streams, the provision of |
---|
253 | a core set of operations at field widths of 2 and 4 as |
---|
254 | well as the more traditional field witdhs of 8, 16 and 32 |
---|
255 | is critical for elegant and efficient expression of the |
---|
256 | algorithms. In essence, inductive doubling algorithms |
---|
257 | work by establishing some base property at either single |
---|
258 | or 2-bit fields. Each iteration of the algorithm then |
---|
259 | goes on to establish the property for the power-of-2 |
---|
260 | field width. In order for this inductive step to be |
---|
261 | most conveniently and efficiently expressed, the |
---|
262 | core operations needed for the step should be available |
---|
263 | at each field width. In the case of work with parallel |
---|
264 | bit streams, the operations \verb:add:, \verb:sub:, |
---|
265 | \verb:sll:, \verb:srl: (shift right logical), and \verb:rotl: |
---|
266 | (rotate left) comprise the core. In other domains, |
---|
267 | additional operations may be usefully included in the |
---|
268 | core depending on the work that needs to be performed |
---|
269 | at each inductive doubling level. |
---|
270 | |
---|
271 | Note that the definition of field widths $n=2^k$ for $0 \leq k \leq K$ |
---|
272 | also includes fields of width 1. These are included for |
---|
273 | logical consistency, but are easily implemented by mapping |
---|
274 | directly to appropriate bitwise logic operations, which |
---|
275 | we assume are also available. For example, |
---|
276 | \verb#simd<1>::add# is equivalent to \verb:simd_xor:, the |
---|
277 | bitwise exclusive-or operation on SIMD registers. |
---|
278 | |
---|
279 | The second key facility of the inductive doubling architecture |
---|
280 | is the potential application of half-operand modifiers to |
---|
281 | the fields of either or both of the operands of a SIMD |
---|
282 | operation. These modifiers select either the |
---|
283 | low $n/2$ |
---|
284 | bits of each $n$-bit field (modifier ``\verb:l:'') or the |
---|
285 | high $n/2$ bits (modifier ``\verb:h:''). When required, |
---|
286 | the modifier ``\verb:x:'' means that the full $n$ bits |
---|
287 | should be used, unmodified. The semantics of these |
---|
288 | modifiers are given by the following equations. |
---|
289 | %\singlespace |
---|
290 | \begin{eqnarray} |
---|
291 | l(r_n) & = & r_n \bmod 2^{n/2} \\ |
---|
292 | h(r_n) & = & r_n / 2^{n/2} \\ |
---|
293 | x(r_n) & = & r_n |
---|
294 | \end{eqnarray} |
---|
295 | %\doublespace |
---|
296 | In our notation, the half-operand modifiers are |
---|
297 | specified as optional template (compile-time) parameters |
---|
298 | for each of the binary functions. Thus, |
---|
299 | \verb#simd<4>::add<h,l>(a,b)# is an operation which adds |
---|
300 | the 2-bit quantity found in the high 2-bits of each 4-bit field |
---|
301 | of its first operand (\verb:a:) |
---|
302 | together with the corresponding 2-bit quantity found in the |
---|
303 | low 2-bits of its second operand (\verb:b:). |
---|
304 | In general, the purpose of the half-operand modifiers |
---|
305 | in support of inductive doubling is to allow the processing |
---|
306 | of $n$-bit fields to easily expressed in terms of |
---|
307 | combination of the results determined by processing |
---|
308 | $n/2$ bit fields. |
---|
309 | |
---|
310 | The third facility of the inductive doubling architecture |
---|
311 | is a set of pack operations at each field width $n=2^k$ for $1 \leq k \leq K$. |
---|
312 | The field values of \verb#r=simd<n>::pack(a,b)# are |
---|
313 | defined by the following equations. |
---|
314 | %\singlespace |
---|
315 | \begin{eqnarray} |
---|
316 | r_{n/2}[i] & = & \mbox{conv}(a_n[i], n/2), \textrm{for } i < N/n \\ |
---|
317 | r_{n/2}[i] & = & \mbox{conv}(b_n[i - N/n], n/2), \textrm{for } i \geq N/n |
---|
318 | \end{eqnarray} |
---|
319 | %\doublespace |
---|
320 | Here conv is a function which performs conversion of an $n$-bit |
---|
321 | value to an $n/2$ bit value by signed saturation (although |
---|
322 | conversion by unsigned saturation would also suit our purpose). |
---|
323 | |
---|
324 | Half-operand modifiers may also be used with the pack |
---|
325 | operations. Thus packing with conversion by masking off all |
---|
326 | but the low $n/2$ bits of each field may be |
---|
327 | be performed using the operation \verb#simd<n>::pack<l,l># |
---|
328 | |
---|
329 | |
---|
330 | The final facility of the inductive doubling architecture is |
---|
331 | a set of merging operations \verb#simd<n>::mergeh# and |
---|
332 | \verb#simd<n>::mergel# that produce $2n$-bit fields |
---|
333 | by concatenating corresponding $n$-bit fields from the |
---|
334 | operand registers. The respective |
---|
335 | operations \verb#r=simd<n>::mergeh(a,b)# and |
---|
336 | \verb#s=simd<n>::mergel(a,b)# |
---|
337 | are defined by the following equations. |
---|
338 | %\singlespace |
---|
339 | \begin{eqnarray} |
---|
340 | r_{2n}[i] & = & a[i] \times 2^n + b[i] \\ |
---|
341 | s_{2n}[i] & = & a[i+N/(2n)] \times 2^n + b[i+N/(2n)] |
---|
342 | \end{eqnarray} |
---|
343 | %\doublespace |
---|
344 | Both SSE and Altivec provide versions of pack and merge operations |
---|
345 | for certain field widths. The pack operations are provided |
---|
346 | with operands having 16-bit or 32-bit fields on each platform, although |
---|
347 | with some variation in how conversion is carried out. |
---|
348 | The merge operations are provided at 8-bit, 16-bit and 32-bit |
---|
349 | field widths on both architectures and also at the 64-bit level |
---|
350 | on SSE. |
---|
351 | |
---|
352 | This completes the description of IDISA. As described, many of the |
---|
353 | features are already available with the SIMD facilities of |
---|
354 | existing commodity processors. The extensions enumerated |
---|
355 | here are relatively straightforward. The innovation |
---|
356 | is to specifically tackle the design of facilities to |
---|
357 | offer systematic support for transitions between power-of-2 field widths. |
---|
358 | As we shall show in the remainder of this paper, these facilities |
---|
359 | can dramatically reduce instruction count in core parallel bit |
---|
360 | stream algorithms, with a factor of 3 reduction being typical. |
---|
361 | |
---|
362 | \section{Evaluation Methodology} |
---|
363 | |
---|
364 | IDISA represents a set of instruction set features that |
---|
365 | could potentially be added to any SWAR processor. The goal |
---|
366 | in this paper is to evaluate these features independent |
---|
367 | of artifacts that may be due to any particular realization, |
---|
368 | while still considering realistic models based on existing |
---|
369 | commodity instruction set architectures. For the purpose |
---|
370 | of IDISA evaluation, then, we define two reference architectures. |
---|
371 | For concreteness, IDISA and the two reference architectures will |
---|
372 | each be considered as 128-bit processors employing the |
---|
373 | three-register SWAR model defined in the previous |
---|
374 | section. |
---|
375 | |
---|
376 | Reference architecture A (RefA) consists of a limited register |
---|
377 | processor providing a set of core binary operations defined |
---|
378 | for 8, 16, 32 and 64 bit fields. The core binary operations |
---|
379 | will be assumed to be those defined by the SSE instruction |
---|
380 | set for 16-bit fields. In addition, we assume that |
---|
381 | shift immediate operations for each field width exist, |
---|
382 | e.g., \verb#simd<8>::srli<1>(x)# for a right logical |
---|
383 | shift of each 8-bit field by 1. We also assume that |
---|
384 | a constant load operation \verb#simd::const<n>(c)# |
---|
385 | loads the constant value $c$ into each $n$ bit field. |
---|
386 | |
---|
387 | Reference architecture B (RefB) consists of a register-rich |
---|
388 | processor incorporating all the operations of reference |
---|
389 | architecture A as well as the following additional facilities |
---|
390 | inspired by the Altivec instruction set. |
---|
391 | For each of the 8, 16, 32 and 64 bit widths, a binary rotate left |
---|
392 | logical instruction \verb#simd<n>::rotl(a,b)# rotates each field |
---|
393 | of $a$ by the rotation count in the corresponding field of $b$. |
---|
394 | A three-register \verb#simd<1>::if(a,b,c)# bitwise logical |
---|
395 | operator implements the logic $a \wedge b \vee \neg a \wedge c$, patterned |
---|
396 | after the Altivec \verb:vec_sel: operation. Finally, |
---|
397 | a \verb#simd<8>::permute(a,b,c)# selects an arbitrary |
---|
398 | permutation of bytes from the concatenation of $a$ and $b$ based |
---|
399 | on the set of indices in $c$. |
---|
400 | |
---|
401 | Two versions of IDISA are assessed against these reference |
---|
402 | architectures as follows. IDISA-A has all the facilities |
---|
403 | of RefA extended with half-operand modifiers and all core |
---|
404 | operations at field widths of 2, 4 and 128. IDISA-B is |
---|
405 | similarly defined and extended based on RefB. Algorithms |
---|
406 | for both RefA and IDISA-A are assessed assuming that |
---|
407 | any required constants must be loaded as needed; this |
---|
408 | reflects the limited register assumption. On the other, |
---|
409 | assessment for both RefB and IDISA-B will make the |
---|
410 | assumption that sufficiently many registers exist that |
---|
411 | constants can be kept preloaded. |
---|
412 | |
---|
413 | In each case, the processors are assumed to be |
---|
414 | pipelined processors with a throughput of one SWAR instruction |
---|
415 | each processor cycle for straight-line code free of memory |
---|
416 | access. Such processors are certainly feasible with a |
---|
417 | suitable investment in circuitry, although practical designs |
---|
418 | may make sacrifices to achieve close to optimal throughput |
---|
419 | with less circuitry. However, the assumption makes for |
---|
420 | straightforward performance evaluation based on instruction |
---|
421 | count for straight-line computational kernels. Furthermore, |
---|
422 | the assumption also eliminates artifacts due to possibly different |
---|
423 | latencies in reference and IDISA architectures. Because |
---|
424 | the same assumption is made for reference and IDISA |
---|
425 | architectures, determination of the additional circuit |
---|
426 | complexity due to IDISA features is unaffected by the |
---|
427 | assumption. |
---|
428 | |
---|
429 | In the remainder of this paper, then, IDISA-A and IDISA-B |
---|
430 | models are evaluated against their respective reference |
---|
431 | architectures on straight-line computational kernels |
---|
432 | used in parallel bit stream processing and other applications. |
---|
433 | As XML and other sequential text processing applications |
---|
434 | tend to use memory in an efficient streaming model, the |
---|
435 | applications tend to be compute-bound rather than IO-bound. |
---|
436 | Thus, the focus on computational kernels addresses the |
---|
437 | primary concern for performance improvement of these applications. |
---|
438 | |
---|
439 | The additional circuity complexity to realize IDISA-A and |
---|
440 | IDISA-B designs over their reference models will be |
---|
441 | addressed in the penultimate section. That discussion |
---|
442 | will focus primarily on the complexity of implementing |
---|
443 | half-operand modifier logic, but will also address |
---|
444 | the extension of the core operations to operate on |
---|
445 | 2-bit, 4-bit and 128-bit fields, as well. |
---|
446 | |
---|
447 | \section{Population Count} |
---|
448 | |
---|
449 | \begin{figure}[h] |
---|
450 | \begin{center}\small |
---|
451 | \begin{verbatim} |
---|
452 | c = (x & 0x55555555) + ((x >> 1) & 0x55555555); |
---|
453 | c = (c & 0x33333333) + ((c >> 2) & 0x33333333); |
---|
454 | c = (c & 0x0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F); |
---|
455 | c = (c & 0x00FF00FF) + ((c >> 8) & 0x00FF00FF); |
---|
456 | c = (c & 0x0000FFFF) + ((c >>16) & 0x0000FFFF); |
---|
457 | \end{verbatim} |
---|
458 | \end{center} |
---|
459 | \caption{Population Count Reference Algorithm} |
---|
460 | \label{HD-pop} |
---|
461 | \end{figure} |
---|
462 | |
---|
463 | \begin{figure} |
---|
464 | \begin{center}\small |
---|
465 | \begin{verbatim} |
---|
466 | c = simd<2>::add<h,l>(x, x); |
---|
467 | c = simd<4>::add<h,l>(c, c); |
---|
468 | c = simd<8>::add<h,l>(c, c); |
---|
469 | c = simd<16>::add<h,l>(c, c); |
---|
470 | c = simd<32>::add<h,l>(c, c); |
---|
471 | \end{verbatim} |
---|
472 | \end{center} |
---|
473 | \caption{IDISA Population Count} |
---|
474 | \label{inductivepopcount} |
---|
475 | \end{figure} |
---|
476 | |
---|
477 | As an initial example to illustrate the principle of inductive doubling |
---|
478 | in practice, consider the problem of {\em population count}: determining |
---|
479 | the number of one bits within a particular bit field. It is important |
---|
480 | enough for such operations as calculating Hamming distance to be included |
---|
481 | as a built-in instruction |
---|
482 | on some processors. For example, the SPU of the Cell Broadband Engine |
---|
483 | has a SIMD population count instruction \verb:si_cntb: for simultaneously |
---|
484 | determining the |
---|
485 | number of 1 bits within each byte of a 16-byte register. |
---|
486 | In text processing with parallel bit streams, population count has direct |
---|
487 | application to keeping track of line numbers for error reporting, for example. |
---|
488 | Given a bit block identifying the positions of newline characters within |
---|
489 | a block of characters being processed, the population count of the |
---|
490 | bit block can be used to efficiently and conveniently be used to update |
---|
491 | the line number upon completion of block processing. |
---|
492 | |
---|
493 | Figure \ref{HD-pop} presents a traditional divide-and-conquer |
---|
494 | implementation for a 32-bit integer {\tt x} adapted from |
---|
495 | Warren \cite{HackersDelight}, while |
---|
496 | Figure \ref{inductivepopcount} shows the corresponding IDISA |
---|
497 | implementation for a vector of 32-bit fields. Each implementation employs |
---|
498 | five steps of inductive doubling to produce population counts |
---|
499 | within 32 bit fields. The traditional implementation employs |
---|
500 | explicit masking and shifting operations, while these |
---|
501 | operations are implicit within the semantics of the inductive |
---|
502 | doubling instructions shown in Figure \ref{inductivepopcount}. |
---|
503 | In each implementation, the first step determines the |
---|
504 | the population counts within 2-bit fields |
---|
505 | by adding the high bit of each such field to the low bit |
---|
506 | to produce a set of 2-bit counts in {\tt c}. |
---|
507 | In the second step, the counts within 4-bit fields of {\tt c} are determined |
---|
508 | by adding the counts of the corresponding high and low 2-bit subfields. |
---|
509 | Continuing in this fashion, |
---|
510 | the final population counts within 32-bit fields are determined in five steps. |
---|
511 | |
---|
512 | With the substitution of longer mask constants replicated for four |
---|
513 | 32-bit fields, the implementation of Figure \ref{HD-pop} can be |
---|
514 | directly adapted to SWAR processing using 128-bit registers. |
---|
515 | Each binary operator is replaced by a corresponding binary |
---|
516 | SWAR operation. Without the IDISA features, a |
---|
517 | straightforward RefA implementation of population count for |
---|
518 | 32-bit fields thus employs 10 operations to load or generate |
---|
519 | mask constants, 10 bitwise-and operations, 5 shifts and 5 adds for a |
---|
520 | total of 30 operations to complete the task. Employing |
---|
521 | optimization identified by Warren, this can be reduced to |
---|
522 | 20 operations, 5 of which are required to generate mask constants. |
---|
523 | At the cost of register pressure, it is possible that these constants |
---|
524 | could be kept preloaded in long vector processing. In accord |
---|
525 | with our evaluation model, the RefB cost is thus 15 operations. |
---|
526 | As the IDISA implementation requires no constants at all, |
---|
527 | both the IDISA-A and IDISA-B cost is 5 operations. |
---|
528 | At our assumed one CPU cycle per instruction model, IDISA-A |
---|
529 | offers a 4X improvement over RefA, while IDISA-B offers a 3X |
---|
530 | improvement over its comparator. |
---|
531 | |
---|
532 | The pattern illustrated by population count is typical. |
---|
533 | An inductive doubling algorithm of $n$ steps typically applies |
---|
534 | mask or shift operations at each step for each of the |
---|
535 | two operands being combined in the step. If there is |
---|
536 | one such operation for each operand, and the combination |
---|
537 | can be implemented in a single SWAR operation, then a total |
---|
538 | of $3n$ operations are the required in a RefB implementation, |
---|
539 | and possibly $4n$ for a RefA implementation including the |
---|
540 | cost of loading masks. IDISA-A and IDISA-B implementations |
---|
541 | typically eliminate the explicit mask and shift operations |
---|
542 | through appropriate half-operand modifiers, reducing the |
---|
543 | total instruction count to $n$. Thus a 3X to 4X improvement |
---|
544 | obtains in these cases. |
---|
545 | |
---|
546 | \section{Transposition to Parallel Bit Streams} |
---|
547 | |
---|
548 | In this section, we consider the first major |
---|
549 | application of IDISA: transposition of byte stream data to parallel bit stream |
---|
550 | form. Of course, this operation is critical to the |
---|
551 | method of parallel bit streams and all applications |
---|
552 | of the method can benefit from a highly efficient |
---|
553 | transposition process. Before considering how |
---|
554 | the IDISA supports this |
---|
555 | transposition process, however, we first consider |
---|
556 | algorithms on existing architectures. Two algorithms |
---|
557 | are presented; the best of these requires 72 |
---|
558 | SWAR operations under the RefB model to perform |
---|
559 | transposition of eight serial registers of byte stream data into |
---|
560 | eight parallel registers of bit stream data. |
---|
561 | |
---|
562 | We then go on to show how the transposition problem |
---|
563 | can be solved using IDISA-A or IDISA-B |
---|
564 | with a mere 24 three-register SIMD operations. We also show |
---|
565 | that this is optimal for any three-register instruction set model. |
---|
566 | |
---|
567 | \begin{figure}[tbh] |
---|
568 | \begin{center} |
---|
569 | \includegraphics[width=90mm, trim= 50 50 0 50]{S2P_IO.pdf} |
---|
570 | \caption{Input/Output Model for Serial to Parallel Transposition} |
---|
571 | \label{s2p-spec} |
---|
572 | \end{center} |
---|
573 | |
---|
574 | \end{figure} |
---|
575 | Figure \ref{s2p-spec} illustrates the input-output requirements of |
---|
576 | the transposition problem. We assume that inputs and |
---|
577 | outputs are each SWAR registers of size $N=2^K$ bits. |
---|
578 | The input consists of $N$ bytes of serial byte data, |
---|
579 | stored consecutively in eight SIMD registers each holding |
---|
580 | $N/8$ bytes. The output consists of eight parallel |
---|
581 | registers, one each for the eight individual bit positions |
---|
582 | within a byte. Upon completion of the transposition process, |
---|
583 | each output register is to hold the $N$ bits corresponding |
---|
584 | to the selected bit position in the sequence of $N$ input |
---|
585 | bytes. |
---|
586 | |
---|
587 | \subsection{Bit Gathering Algorithm} |
---|
588 | |
---|
589 | \begin{figure}[tbh] |
---|
590 | \begin{center} |
---|
591 | \includegraphics[width=100mm, trim= 50 100 0 0]{S2P.pdf} |
---|
592 | \caption{Serial to Parallel Transposition Using Bit-Gathering} |
---|
593 | \label{gather} |
---|
594 | \end{center} |
---|
595 | \end{figure} |
---|
596 | One straightforward algorithm for implementing the transposition process |
---|
597 | takes advantage of SWAR bit gathering operations that exist |
---|
598 | on some architectures. This operation gathers one bit per byte |
---|
599 | from a particular position within each byte of a SIMD register. |
---|
600 | For example, the {\tt pmovmskb} operation of the Intel MMX and |
---|
601 | SSE instruction sets forms an 8-bit (MMX) or 16-bit (SSE) mask |
---|
602 | consisting of the high bit of each byte. Similarly, the |
---|
603 | {\tt \verb:si_gbb:} operation of the synergistic processing units of the |
---|
604 | Cell Broadband Engine gathers together the low bit of each byte |
---|
605 | from the SIMD register. Figure \ref{gather} illustrates the |
---|
606 | bit gathering process. |
---|
607 | |
---|
608 | For each bit stream of output, the bit gather algorithm requires |
---|
609 | one gather operation for each of the 8 input registers, |
---|
610 | giving 64 bit gather operations in all. In addition, for seven |
---|
611 | of the eight bit positions, it is necessary to shift the bits |
---|
612 | of each input register into the conventional position for |
---|
613 | gathering. A total of 56 shift operations are required for this |
---|
614 | task. Finally, the result of each bit gather operation must |
---|
615 | be properly inserted into the output stream. If the first |
---|
616 | gather operation for a stream can be used to also initialize |
---|
617 | the output register, there will then need to be 7 insert |
---|
618 | operations for the results of the remaining gather operations |
---|
619 | for this stream, making 56 insert operations in all. |
---|
620 | The insert step may be more complex than a single operation |
---|
621 | in some cases, but we use one operation per insert as a lower bound. |
---|
622 | Thus, the bit gather algorithm requires |
---|
623 | at least 176 operations to perform the transposition task. |
---|
624 | |
---|
625 | \subsection{BytePack Algorithm} |
---|
626 | |
---|
627 | A much more efficient transposition algorithm on commodity |
---|
628 | SWAR architectures involves three |
---|
629 | stages of binary division transformation. This is similar |
---|
630 | to the three stage bit matrix inversion described by |
---|
631 | Warren \cite{HackersDelight}, although modified to use SWAR operations. |
---|
632 | In each stage, input streams are divided into two half-length output streams. |
---|
633 | The first stage separates the bits at even numbered positions from those |
---|
634 | at odd number positions. The two output streams from the first |
---|
635 | stage are then further divided in the second stage. |
---|
636 | The stream comprising even numbered bits from the original byte stream |
---|
637 | divides into one stream consisting of bits from positions 0 and 4 of each |
---|
638 | byte in the original stream and a second stream consisting of bits |
---|
639 | from positions 2 and 6 of each original byte. The stream of bits from |
---|
640 | odd positions is similarly divided into streams for bits from each of the |
---|
641 | positions 1 and 5 and bits from positions 2 and 6. |
---|
642 | Finally, each of the four streams resulting from the second stage are |
---|
643 | divided into the desired individual bit streams in the third stage. |
---|
644 | |
---|
645 | % \begin{figure}[tbh] |
---|
646 | % \begin{center}\small |
---|
647 | % \begin{verbatim} |
---|
648 | % s0h = simd<16>::srli<8>(s0); |
---|
649 | % s0l = simd_and(s0, simd<16>::const(0x00FF)); |
---|
650 | % s1h = simd<16>::srli<8>(s1); |
---|
651 | % s1l = simd_and(s1, simd<16>::const(0x00FF)); |
---|
652 | % t0 = simd<16>::pack(s0h, s1h); |
---|
653 | % t1 = simd<16>::pack(s0l, s1l); |
---|
654 | % t0_l1 = simd<16>::slli<1>(t0); |
---|
655 | % t0_r1 = simd<16>::srli<1>(t1); |
---|
656 | % mask = simd<8>::const(0xAA); |
---|
657 | % p0 = simd_or(simd_and(t0, mask), simd_andc(t1_r1, mask)); |
---|
658 | % p1 = simd_or(simd_and(t0_l1, mask), simd_andc(t1, mask)); |
---|
659 | % \end{verbatim} |
---|
660 | % \end{center} |
---|
661 | % \caption{Basic Stage 1 Transposition Step in the BytePack Algorithm} |
---|
662 | % \label{s2pstep} |
---|
663 | % \end{figure} |
---|
664 | % |
---|
665 | |
---|
666 | \begin{figure}[tbh] |
---|
667 | \begin{center}\small |
---|
668 | \begin{verbatim} |
---|
669 | even = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30}; |
---|
670 | odd = {1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31}; |
---|
671 | mask = simd<8>::const(0xAA); |
---|
672 | t0 = simd<8>::permute(s0, s1, even); |
---|
673 | t1 = simd<8>::permute(s0, s1, odd); |
---|
674 | p0 = simd_if(mask, t0, simd<16>::srli<1>(t1)); |
---|
675 | p1 = simd_if(mask, simd<16>::slli<1>(t0), t1); |
---|
676 | \end{verbatim} |
---|
677 | \end{center} |
---|
678 | \caption{RefB Transposition Step in BytePack Stage 1} |
---|
679 | \label{s2pstep} |
---|
680 | \end{figure} |
---|
681 | |
---|
682 | The binary division transformations are accomplished in each stage |
---|
683 | using byte packing, shifting and masking. In each stage, a |
---|
684 | transposition step combines each pair of serial input registers to |
---|
685 | produce a pair of parallel output registers. |
---|
686 | Figure \ref{s2pstep} shows a stage 1 transposition step in a |
---|
687 | Ref B implementation. Using the permute facility, the even |
---|
688 | and odd bytes, respectively, from two serial input registers |
---|
689 | \verb:s0: and \verb:s1: are packed into temporary registers |
---|
690 | \verb:t0: and \verb:t1:. The even and odd bits are then |
---|
691 | separated into two parallel output registers \verb:p0: and \verb:p1: |
---|
692 | by selecting alternating bits using a mask. This step is applied |
---|
693 | four times in stage 1; stages 2 and 3 also consist of four applications |
---|
694 | of a similar step with different shift and mask constants. |
---|
695 | Overall, 6 operations per step are required, yielding a total |
---|
696 | of 72 operations to transpose 128 bytes to parallel bit stream |
---|
697 | form in the RefB implementation. |
---|
698 | |
---|
699 | In a RefA implementation, byte packing may also be achieved |
---|
700 | by the \verb#simd<16>::pack# with 4 additional operations to |
---|
701 | prepare operands. Essentially, the RefB implementation |
---|
702 | uses single permuite instructions to implement the equivalent of |
---|
703 | \verb#simd<16>::pack<h,h>(s0, s1)# and \verb#simd<16>::pack<l,l>(s0, s1)#. |
---|
704 | The RefA implementation also requires 3 logic operations to implement |
---|
705 | each \verb#simd_if#. |
---|
706 | Assuming that mask loads are only need once per 128 bytes, |
---|
707 | a total of 148 operations are required in the RefB implementation. |
---|
708 | |
---|
709 | \subsection{Inductive Halving Algorithm} |
---|
710 | |
---|
711 | Using IDISA, it is possible to design |
---|
712 | a transposition algorithm that is both easier to understand and requires |
---|
713 | many fewer operations than the the bytepack algorithm described above. |
---|
714 | We call it the inductive halving algorithm for serial to parallel |
---|
715 | transposition, because it proceeds by reducing byte streams to |
---|
716 | two sets of nybble streams in a first stage, dividing the nybble |
---|
717 | streams into streams of bitpairs in a second stage and finally |
---|
718 | dividing the bitpair streams into bit streams in the third stage. |
---|
719 | |
---|
720 | \begin{figure}[tbh] |
---|
721 | \small |
---|
722 | \begin{verbatim} |
---|
723 | p0 = simd<8>::pack<h,h>(s0, s1); |
---|
724 | p1 = simd<8>::pack<l,l>(s0, s1); |
---|
725 | \end{verbatim} |
---|
726 | \caption{Stage 1 Transposition Step in the Inductive Halving Algorithm} |
---|
727 | \label{halvingstep} |
---|
728 | \end{figure} |
---|
729 | |
---|
730 | Figure \ref{halvingstep} shows one step in stage 1 of the inductive |
---|
731 | halving algorithm, comprising just two IDISA-A operations. |
---|
732 | The \verb#simd<8>::pack<h,h># operation extracts the high nybble of each byte |
---|
733 | from the input registers, while the \verb#simd<8>::pack<l,l># operation extracts |
---|
734 | the low nybble of each byte. As in the bytepack algorithm, this step is |
---|
735 | applied 4 times in stage 1, for a total of 8 operations. |
---|
736 | |
---|
737 | Stage 2 of the inductive halving algorithm reduces nybble streams |
---|
738 | to streams of bit pairs. The basic step in this algorithm consists |
---|
739 | of one \verb#simd<4>::pack<h,h># operation to extract the high pair |
---|
740 | of each nybble and one \verb#simd<4>::pack<l,l># operation to extract the |
---|
741 | low pair of each nybble. Four applications of this step complete stage 2. |
---|
742 | |
---|
743 | Stage 3 similarly uses four applications of a step that uses a |
---|
744 | \verb#simd<2>::pack<h,h># operation to extract the high bit of |
---|
745 | each pair and a \verb#simd<2>::pack<l,l># to extract the low bit of |
---|
746 | each pair. The complete algorithm to transform eight serial |
---|
747 | byte registers s0 through s7 into the eight parallel bit stream |
---|
748 | registers bit0 through bit7 is shown in Figure \ref{halvingalgorithm}. |
---|
749 | Under either IDISA-A or IDISA-B models, a mere 24 operations per 128 |
---|
750 | input bytes is required. |
---|
751 | |
---|
752 | \begin{figure}[tbh] |
---|
753 | \small |
---|
754 | \begin{verbatim} |
---|
755 | hnybble0 = simd<8>::pack<h,h>(s0, s1); |
---|
756 | lnybble0 = simd<8>::pack<l,l>(s0, s1); |
---|
757 | hnybble1 = simd<8>::pack<h,h>(s2, s3); |
---|
758 | lnybble1 = simd<8>::pack<l,l>(s2, s3); |
---|
759 | hnybble2 = simd<8>::pack<h,h>(s4, s5); |
---|
760 | lnybble2 = simd<8>::pack<l,l>(s4, s5); |
---|
761 | hnybble3 = simd<8>::pack<h,h>(s6, s7); |
---|
762 | lnybble3 = simd<8>::pack<l,l>(s6, s7); |
---|
763 | hh_pair0 = simd<4>::pack<h,h>(hnybble0, hnybble1); |
---|
764 | hl_pair0 = simd<4>::pack<l,l>(hnybble0, hnybble1); |
---|
765 | lh_pair0 = simd<4>::pack<h,h>(lnybble0, lnybble1); |
---|
766 | ll_pair0 = simd<4>::pack<l,l>(lnybble0, lnybble1); |
---|
767 | hh_pair1 = simd<4>::pack<h,h>(hnybble2, hnybble3); |
---|
768 | hl_pair1 = simd<4>::pack<l,l>(hnybble2, hnybble3); |
---|
769 | lh_pair1 = simd<4>::pack<h,h>(lnybble2, lnybble3); |
---|
770 | ll_pair1 = simd<4>::pack<l,l>(lnybble2, lnybble3); |
---|
771 | bit0 = simd<2>::pack<h,h>(hh_pair0, hh_pair1); |
---|
772 | bit1 = simd<2>::pack<l,l>(hh_pair0, hh_pair1); |
---|
773 | bit2 = simd<2>::pack<h,h>(hl_pair0, hl_pair1); |
---|
774 | bit3 = simd<2>::pack<l,l>(hl_pair0, hl_pair1); |
---|
775 | bit4 = simd<2>::pack<h,h>(lh_pair0, lh_pair1); |
---|
776 | bit5 = simd<2>::pack<l,l>(lh_pair0, lh_pair1); |
---|
777 | bit6 = simd<2>::pack<h,h>(ll_pair0, ll_pair1); |
---|
778 | bit7 = simd<2>::pack<l,l>(ll_pair0, ll_pair1); |
---|
779 | \end{verbatim} |
---|
780 | \caption{Complete Inductive Halving Algorithm} |
---|
781 | \label{halvingalgorithm} |
---|
782 | \end{figure} |
---|
783 | |
---|
784 | \subsection{Optimality of the Inductive Halving Algorithm} |
---|
785 | |
---|
786 | Here we show that the inductive halving algorithm presented in |
---|
787 | the previous subsection is optimal in the following sense: |
---|
788 | no other algorithm on any 3-register SIMD architecture can use |
---|
789 | fewer than 24 operations to transform eight serial registers |
---|
790 | of byte stream data into eight parallel registers of bit stream data. |
---|
791 | By 3-register SIMD architecture, we refer to any architecture |
---|
792 | that uses SIMD instructions consistent with our overall model of |
---|
793 | binary operations using two input register operands to produce |
---|
794 | one output register value. |
---|
795 | |
---|
796 | Observe that the $N$ data bits from each input register must be |
---|
797 | distributed $N/8$ each to the 8 output registers by virtue of |
---|
798 | the problem definition. Each output register can effectively |
---|
799 | be given a 3-bit address; the partitioning problem can be viewed |
---|
800 | as moving data to the correct address. However, each |
---|
801 | operation can move results into at most one register. |
---|
802 | At most this can result in the assignment of one correct address |
---|
803 | bit for each of the $N$ input bits. As all $8N$ input bits |
---|
804 | need to be moved to a register with a correct 3-bit address, |
---|
805 | a minimum of 24 operations is required. |
---|
806 | |
---|
807 | \subsection{End-to-End Significance} |
---|
808 | |
---|
809 | In a study of several XML technologies applied to |
---|
810 | the problem of GML to SVG transformation, the parabix |
---|
811 | implementation (parallel bit streams for XML) was |
---|
812 | found to the fastest with a cost of approximately |
---|
813 | 15 CPU cycles per input byte \cite{Herdy}. Within parabix, |
---|
814 | transposition to parallel bit stream form requires |
---|
815 | approximately 1.1 cycles per byte \cite{CASCON08}. |
---|
816 | All other things being equal, a 3X speed-up of transposition |
---|
817 | alone would improve end-to-end performance in a |
---|
818 | complete XML processing application by more than 4\%. |
---|
819 | |
---|
820 | |
---|
821 | \section{Parallel to Serial Conversion} |
---|
822 | |
---|
823 | Parallel bit stream applications may apply string editing |
---|
824 | operations in bit space to substitute, delete or insert |
---|
825 | parallel sets of bits at particular positions. In such cases, |
---|
826 | the inverse transform that converts a set of parallel bit |
---|
827 | streams back into byte space is needed. In the example of |
---|
828 | UTF-8 to UTF-16 transcoding, the inverse transform is |
---|
829 | actually used twice for each application of the forward |
---|
830 | transform, to separately compute the high and low byte |
---|
831 | streams of each UTF-16 code unit. Those two byte streams |
---|
832 | are subsequentely merged to form the final result. |
---|
833 | |
---|
834 | Algorithms for performing the inverse transform mirror those |
---|
835 | of the forward transform, employing SIMD merge operations |
---|
836 | in place of pack operations. The best algorithm known |
---|
837 | to us on the commodity SIMD architectures takes advantage |
---|
838 | of versions of the \verb#simd<8>::mergeh# and \verb#simd<8>::mergel# |
---|
839 | operations that are available with each of the SSE and Altivec instruction |
---|
840 | sets. To perform the full inverse transform of 8 parallel |
---|
841 | registers of bit stream data into 8 serial registers of byte stream data, |
---|
842 | a RefA implementation requires 120 operations, while a RefB |
---|
843 | implementation reduces this to 72. |
---|
844 | |
---|
845 | \begin{figure}[tbh] |
---|
846 | \begin{center}\small |
---|
847 | \begin{verbatim} |
---|
848 | bit01_r0 = simd<1>::mergeh(bit0, bit1); |
---|
849 | bit01_r1 = simd<1>::mergel(bit0, bit1); |
---|
850 | bit23_r0 = simd<1>::mergeh(bit2, bit3); |
---|
851 | bit23_r1 = simd<1>::mergel(bit2, bit3); |
---|
852 | bit45_r0 = simd<1>::mergeh(bit4, bit5); |
---|
853 | bit45_r1 = simd<1>::mergel(bit4, bit5); |
---|
854 | bit67_r0 = simd<1>::mergeh(bit6, bit7); |
---|
855 | bit67_r1 = simd<1>::mergel(bit6, bit7); |
---|
856 | bit0123_r0 = simd<2>::mergeh(bit01_r0, bit23_r0); |
---|
857 | bit0123_r1 = simd<2>::mergel(bit01_r0, bit23_r0); |
---|
858 | bit0123_r2 = simd<2>::mergeh(bit01_r1, bit23_r1); |
---|
859 | bit0123_r3 = simd<2>::mergel(bit01_r1, bit23_r1); |
---|
860 | bit4567_r0 = simd<2>::mergeh(bit45_r0, bit67_r0); |
---|
861 | bit4567_r1 = simd<2>::mergel(bit45_r0, bit67_r0); |
---|
862 | bit4567_r2 = simd<2>::mergeh(bit45_r1, bit67_r1); |
---|
863 | bit4567_r3 = simd<2>::mergel(bit45_r1, bit67_r1); |
---|
864 | s0 = simd<4>::mergeh(bit0123_r0, bit4567_r0); |
---|
865 | s1 = simd<4>::mergel(bit0123_r0, bit4567_r0); |
---|
866 | s2 = simd<4>::mergeh(bit0123_r1, bit4567_r1); |
---|
867 | s3 = simd<4>::mergel(bit0123_r1, bit4567_r1); |
---|
868 | s4 = simd<4>::mergeh(bit0123_r2, bit4567_r2); |
---|
869 | s5 = simd<4>::mergel(bit0123_r2, bit4567_r2); |
---|
870 | s6 = simd<4>::mergeh(bit0123_r3, bit4567_r3); |
---|
871 | s7 = simd<4>::mergel(bit0123_r3, bit4567_r3); |
---|
872 | \end{verbatim} |
---|
873 | \end{center} |
---|
874 | \label{p2s-inductive} |
---|
875 | \caption{Parallel to Serial Transposition by Inductive Doubling} |
---|
876 | \end{figure} |
---|
877 | |
---|
878 | An algorithm employing only 24 operations using IDISA-A/B is relatively |
---|
879 | straightforward.. In stage 1, parallel registers for individual bit streams |
---|
880 | are first merged with bit-level interleaving |
---|
881 | using \verb#simd<1>::mergeh# and \verb#simd<8>::mergel# |
---|
882 | operations. For each of the four pairs of consecutive |
---|
883 | even/odd bit streams (bit0/bit1, bit2/bit3, bit4/bit5, bit6/bit7), |
---|
884 | two consecutive registers of bitpair data are produced. |
---|
885 | In stage 2, \verb#simd<2>::mergeh# and \verb#simd<2>::mergel# |
---|
886 | are then applied to merge to bitpair streams to produce streams |
---|
887 | of nybbles for the high and low nybble of each byte. Finally, |
---|
888 | the nybble streams are merged in stage 3 to produce the |
---|
889 | desired byte stream data. The full inductive doubling |
---|
890 | algorithm for parallel to serial transposition is shown in Figure |
---|
891 | \ref{p2s-inductive}. |
---|
892 | |
---|
893 | This algorithm is again optimal, requiring the fewest operations |
---|
894 | of any possible algorithm using any 3-register instruction set |
---|
895 | model. The proof directly follows that for the serial to parallel |
---|
896 | transposition. |
---|
897 | |
---|
898 | The existence of high-performance algorithms for transformation of |
---|
899 | character data between byte stream and parallel bit stream form |
---|
900 | in both directions makes it possible to consider applying these |
---|
901 | transformations multiple times during text processing applications. |
---|
902 | Just as the time domain and frequency domain each have their |
---|
903 | use in signal processing applications, the byte stream form and |
---|
904 | parallel bit stream form can then each be used at will in |
---|
905 | character stream applications. |
---|
906 | |
---|
907 | |
---|
908 | |
---|
909 | \section{Parallel Bit Deletion} |
---|
910 | |
---|
911 | \begin{figure*}[tbh] |
---|
912 | \begin{center} |
---|
913 | \begin{tabular}{|c||c|c|c|c|c|c|c|c|} |
---|
914 | \hline |
---|
915 | \verb:delmask: & \verb:1001: & \verb:1100: & \verb:0100: & \verb:1111: & \verb:0111: & \verb:0010: & \verb:0011: & \verb:0010: \\ \hline |
---|
916 | \verb:bits: & \verb:0bc0: & \verb:00gh: & \verb:i0kl: & \verb:0000: & \verb:q000: & \verb:uv0x: & \verb:yz00: & \verb:CD0F: \\ \hline |
---|
917 | \verb:rslt_8: & \multicolumn{2}{c|}{\tt 00bcgh00} & \multicolumn{2}{c|}{\tt 0ikl0000} & \multicolumn{2}{c|}{\tt 000quvx0} & \multicolumn{2}{c|}{\tt 00yzCDF0} \\ \hline |
---|
918 | \verb:cts_4: & 2 & 2 & 1 & 4 & 3 & 1 & 2 & 1 \\ \hline |
---|
919 | \verb:rj: & \multicolumn{2}{c|}{6} & \multicolumn{2}{c|}{XX} & \multicolumn{2}{c|}{7} & \multicolumn{2}{c|}{XX} \\ \hline |
---|
920 | \verb:lj: & \multicolumn{2}{c|}{XX} & \multicolumn{2}{c|}{1} & \multicolumn{2}{c|}{XX} & \multicolumn{2}{c|}{2} \\ \hline |
---|
921 | \verb:rot_8: & \multicolumn{2}{c|}{6} & \multicolumn{2}{c|}{1} & \multicolumn{2}{c|}{7} & \multicolumn{2}{c|}{2} \\ \hline |
---|
922 | \verb:rslt_16: & \multicolumn{4}{c|}{\tt 0000bcghikl00000} & \multicolumn{4}{c|}{\tt 0000quvxyzCDF000} \\ \hline |
---|
923 | \end{tabular} |
---|
924 | \end{center} |
---|
925 | \label{centraldelstep} |
---|
926 | \caption{Example $8 \rightarrow 16$ Step in Deletion by Central Result Induction} |
---|
927 | \end{figure*} |
---|
928 | |
---|
929 | Parallel bit deletion is an important operation that allows string |
---|
930 | editing operations to be carried out while in parallel bit stream |
---|
931 | form. It is also fundamental to UTF-8 to UTF-16 transcoding |
---|
932 | using parallel bit streams, allowing the excess code unit |
---|
933 | positions for UTF-8 two-, three- and four-byte sequences to |
---|
934 | be deleted once the sixteen parallel bit streams of UTF-16 have |
---|
935 | been computed \cite{PPoPP08}. |
---|
936 | |
---|
937 | Parallel bit deletion is specified using a deletion mask. |
---|
938 | A deletion mask is defined as a bit stream consisting of 1s at positions identifying bits |
---|
939 | to be deleted and 0s at positions identifying bits to be retained. |
---|
940 | For example, consider an 8-bit deletion mask \verb:10100010: and two corresponding 8-element parallel |
---|
941 | bit streams \verb:abcdefgh: and \verb:ABCDEFGH:. Parallel deletion of elements from both bit streams in |
---|
942 | accordance with the mask yields two five element streams, i.e., \verb:bdefh: and \verb:BDEFH:. |
---|
943 | |
---|
944 | Bit deletion may be performed using |
---|
945 | the parallel-prefix compress algorithm documented by |
---|
946 | Warren and attributed to Steele \cite{HackersDelight}. This algorithm uses |
---|
947 | only logic and shifts with a constant parameter to carry |
---|
948 | out the deletion process. However, it requires $k^2$ |
---|
949 | preprocessing steps for a final field width parameter |
---|
950 | of size $2^k$, as well as 4 operations per deletion step |
---|
951 | per stream. Using the inductive doubling instruction set architecture |
---|
952 | it is possible to carry out bit deletion much more efficiently. |
---|
953 | |
---|
954 | Deletion within fixed size fields or registers may produce results that are either |
---|
955 | left justified or right-justified. For example, a five-element stream \verb:bdefh: within an |
---|
956 | eight-element field may be represented as either \verb:bdefhxxx: or \verb:xxxbdefh:, with don't |
---|
957 | care positions marked `\verb:x:'. Concatenating an adjacent right-justified result with a |
---|
958 | left-justified result produces an important intermediate form known as a |
---|
959 | {\em central deletion result}. For example, \verb:xxbd: and \verb:efhx: may be respective |
---|
960 | right-justified and left-justified results from the application of the |
---|
961 | 4-bit deletion masks \verb:1010: and \verb:0010: to the two consecutive 4-element |
---|
962 | stream segments \verb:abcd: and \verb:efgh:. Concatenation of \verb:xxbd: and \verb:efhx: produces |
---|
963 | the central result \verb:xxbdefhx:, which may easily be converted to a either a |
---|
964 | left or a right justified 8-element result by an appropriate shift operation. |
---|
965 | |
---|
966 | |
---|
967 | The observation about how two $n$-bit central deletion results can |
---|
968 | combine to yield a $2n$ central deletion result provides the basis |
---|
969 | for an inductive doubling algorithm. Figure \ref{centraldelstep} |
---|
970 | illustrates the inductive process for the transition from 8-bit central |
---|
971 | deletion results to 16-bit central deletion results. The top row shows |
---|
972 | the original deletion mask, while the second row shows the original |
---|
973 | bit stream to which deletions are to be applied, with deleted bits zeroed out. |
---|
974 | The third row shows the central result for each 8-bit field as the |
---|
975 | result of the previous inductive step. |
---|
976 | |
---|
977 | To perform the $8 \rightarrow 16$ central deletion step, we first form |
---|
978 | the population counts of 4-bit fields of the original deletion mask as |
---|
979 | shown in row 4 of Figure \ref{centraldelstep}. Note that in right-justifying |
---|
980 | an 8-bit central result, we perform a right shift by the population count |
---|
981 | of the low half of the field. Similarly, |
---|
982 | left-justification requires a left-shift by the population count in the |
---|
983 | high half of the field. |
---|
984 | |
---|
985 | The left and right shifts can be performed simultaneously using a rotate |
---|
986 | left instruction. Right justification by shifting an $n$ bit field |
---|
987 | $i$ positions to the right is equivalent to a left rotate of $n-i$ |
---|
988 | positions. These rotation amounts are computed by the operation |
---|
989 | \verb#rj=simd<8>::sub<x,l>(simd<8>::const(8), cts_4)# as shown in row 5, |
---|
990 | except that don't care fields (which won't be subsequently used) |
---|
991 | are marked \verb:XX:. |
---|
992 | |
---|
993 | The left shift amounts are calculated by \verb#lj=simd<8>::srli<4>(cts_4)# |
---|
994 | as shown in row 6, and are combined with the right shift amounts |
---|
995 | by the selection operation \verb#rot_8=simd_if(simd<16>::const(0xFF00), rj, lj)# |
---|
996 | as shown in row 7. Using these computed values, the inductive step |
---|
997 | is completed by application of the operation \verb#rslt_16=simd<8>::rotl(rslt_8, rot_8)# |
---|
998 | as shown in row 8. |
---|
999 | |
---|
1000 | At each inductive doubling level, it requires 4 operations to compute the |
---|
1001 | required deletion infomation and one operation per bit stream to perform deletion. |
---|
1002 | Note that, if deletion is to be applied to a set of eight parallel bit streams, |
---|
1003 | the computed deletion information is used for each stream without recomputation, |
---|
1004 | thus requiring 12 operations per inductive level. |
---|
1005 | |
---|
1006 | In comparison to the parallel-prefix compress method, the method of central |
---|
1007 | deletion results using the inductive doubling architecture has far fewer operations. |
---|
1008 | The total preprocessing cost is $4k$ for $k$ steps of deletion by central result |
---|
1009 | induction versus $4k^2$ for the parallel-prefix method. Using the computed |
---|
1010 | deletion operation, only a single SIMD rotate operation per bit stream |
---|
1011 | per level is needed, in comparison with 4 operations per level for parallel-prefix |
---|
1012 | compress. |
---|
1013 | |
---|
1014 | |
---|
1015 | |
---|
1016 | \section{Beyond Parallel Bit Streams} |
---|
1017 | |
---|
1018 | It can be argued that text processing with parallel bit |
---|
1019 | streams by itself is not sufficiently important to justify |
---|
1020 | the circuit complexity of IDISA. In this section, then |
---|
1021 | we move on to consider further applications that may |
---|
1022 | benefit from IDISA features. These include additional |
---|
1023 | basic inductive doubling |
---|
1024 | algorithms such as parity, and least power-of-2 ceiling. |
---|
1025 | Further applications for narrow field widths are discussed |
---|
1026 | as well, such as packed DNA representations using 2-bit |
---|
1027 | field widths and packed decimal representations using 4-bit |
---|
1028 | field widths. Most significantly, however, we show that IDISA offers |
---|
1029 | a fully general solution to the problem of supporting |
---|
1030 | {\em horizontal} SWAR operations. |
---|
1031 | |
---|
1032 | \subsection{Inductive Doubling with Logic Operations} |
---|
1033 | |
---|
1034 | \begin{figure} |
---|
1035 | \begin{center}\small |
---|
1036 | \begin{verbatim} |
---|
1037 | y = x ^ (x >> 1); |
---|
1038 | y = y ^ (y >> 2); |
---|
1039 | y = y ^ (y >> 4); |
---|
1040 | y = y ^ (y >> 8); |
---|
1041 | y = y ^ (y >>16); |
---|
1042 | y = y & 1; |
---|
1043 | \end{verbatim} |
---|
1044 | \end{center} |
---|
1045 | \caption{Parity Reference Algorithm} |
---|
1046 | \label{HD-parity} |
---|
1047 | \end{figure} |
---|
1048 | |
---|
1049 | \begin{figure} |
---|
1050 | \begin{center}\small |
---|
1051 | \begin{verbatim} |
---|
1052 | x = x - 1; |
---|
1053 | x = x | (x >> 1); |
---|
1054 | x = x | (x >> 2); |
---|
1055 | x = x | (x >> 4); |
---|
1056 | x = x | (x >> 8); |
---|
1057 | x = x | (x >>16); |
---|
1058 | x = x + 1; |
---|
1059 | \end{verbatim} |
---|
1060 | \end{center} |
---|
1061 | \caption{Power-of-2 Ceiling Reference Algorithm} |
---|
1062 | \label{HD-clp2} |
---|
1063 | \end{figure} |
---|
1064 | |
---|
1065 | \begin{figure} |
---|
1066 | \begin{center}\small |
---|
1067 | \begin{verbatim} |
---|
1068 | y = simd<2>::xor<h,l>(x, x); |
---|
1069 | y = simd<4>::xor<h,l>(y, y); |
---|
1070 | y = simd<8>::xor<h,l>(y, y); |
---|
1071 | y = simd<16>::xor<h,l>(y, y); |
---|
1072 | y = simd<32>::xor<h,l>(y, y); |
---|
1073 | \end{verbatim} |
---|
1074 | \end{center} |
---|
1075 | \caption{IDISA Parity Implementation} |
---|
1076 | \label{ID-parity} |
---|
1077 | \end{figure} |
---|
1078 | |
---|
1079 | \begin{figure} |
---|
1080 | \begin{center}\small |
---|
1081 | \begin{verbatim} |
---|
1082 | x = simd<32>::sub(x, simd<32>::const(1)); |
---|
1083 | x = simd<2>::or<x, h>(x, x); |
---|
1084 | x = simd<4>::or<x, h>(x, x); |
---|
1085 | x = simd<8>::or<x, h>(x, x); |
---|
1086 | x = simd<16>::or<x, h>(x, x); |
---|
1087 | x = simd<32>::or<x, h>(x, x); |
---|
1088 | x = simd<32>::add(x, simd<32>::const(1)); |
---|
1089 | \end{verbatim} |
---|
1090 | \end{center} |
---|
1091 | \caption{IDISA Power-of-2 Ceiling Implementation} |
---|
1092 | \label{ID-clp2} |
---|
1093 | \end{figure} |
---|
1094 | |
---|
1095 | Figures \ref{HD-parity} and \ref{HD-clp2} show Warren's |
---|
1096 | code for two further inductive doubling examples using |
---|
1097 | logical operators as the combining feature. In the |
---|
1098 | first of these, the ``exclusive or'' operation is applied |
---|
1099 | to all bits in a 32-bit value to determine parity. |
---|
1100 | Parity has important applications for error-correcting |
---|
1101 | codes such as the various Hamming codes for detecting |
---|
1102 | and correcting numbers of bit errors dependent on the |
---|
1103 | number of parity bits added. Warren's version uses |
---|
1104 | 11 operations for parity of a single 32-bit value; |
---|
1105 | a straightforward SWAR adaptation also uses 11 operations |
---|
1106 | for the parity of a set of 32-bit fields. |
---|
1107 | |
---|
1108 | Figure \ref{ID-parity} shows the IDISA parity implementation |
---|
1109 | with only 5 operations required. This represents slightly |
---|
1110 | more than a 2X improvement. The improvement is less than |
---|
1111 | 3X seen in other cases because one of the operands need |
---|
1112 | not be modified before applying the exclusive-or operation. |
---|
1113 | |
---|
1114 | Using the ``or'' logical operation, Figure \ref{HD-clp2} shows Warren's |
---|
1115 | code for the least power-of-2 ceiling of a 32-bit value. The |
---|
1116 | technique is to employ inductive doubling to fill in one bits at |
---|
1117 | all bit positions after the first one bit in the original value to |
---|
1118 | first produce a value of the form $2^n-1$. This is then incremented |
---|
1119 | to determine the power of 2 ceiling. This function and |
---|
1120 | its straightforward adaptation for SWAR application on a |
---|
1121 | set of 32-bit fields requires 12 operations. The |
---|
1122 | corresponding IDISA implementation of Figure \ref{ID-clp2} |
---|
1123 | requires 7 operations, just under a 2X improvement. |
---|
1124 | |
---|
1125 | \subsection{Packed DNA Representation} |
---|
1126 | |
---|
1127 | DNA sequences are often represented as strings consisting |
---|
1128 | of the four nucleotide codes A, C, G and T. Internally, |
---|
1129 | these sequences are frequently represented in internal |
---|
1130 | form as packed sequences of 2-bit values. The IDISA |
---|
1131 | \verb#simd<8>:pack# and \verb#simd<4>:pack# operations |
---|
1132 | allow these packed representations to be quickly computed |
---|
1133 | from byte-oriented string values by two steps of inductive |
---|
1134 | halving. Similarly, conversion back to string form |
---|
1135 | can use two steps of inductive merging. Without direct |
---|
1136 | support for these pack and merge operations, the SWAR |
---|
1137 | implementations of these conversions require the cost |
---|
1138 | of explicit masking and shifting in combination with |
---|
1139 | the 16-bit to 8-bit packing and 8-bit to 16-bit |
---|
1140 | merging operations supported by existing SWAR facilities |
---|
1141 | on commodity processors. |
---|
1142 | |
---|
1143 | \subsection{Bit Reverse} |
---|
1144 | |
---|
1145 | Include or omit? |
---|
1146 | |
---|
1147 | \subsection{String/Decimal/Integer Conversion} |
---|
1148 | \begin{figure} |
---|
1149 | \begin{center}\small |
---|
1150 | \begin{verbatim} |
---|
1151 | b=(d & 0x0F0F0F0F) + 10 * ((d >> 4) & 0x0F0F0F0F); |
---|
1152 | b=(d & 0x00FF00FF) + 100 * ((d >> 8) & 0x00FF00FF); |
---|
1153 | b=(d & 0x0000FFFF) + 10000 * (d >> 16); |
---|
1154 | \end{verbatim} |
---|
1155 | \end{center} |
---|
1156 | \caption{BCD to Integer Reference Algorithm} |
---|
1157 | \label{BCD2int} |
---|
1158 | \end{figure} |
---|
1159 | |
---|
1160 | \begin{figure} |
---|
1161 | \begin{center}\small |
---|
1162 | \begin{verbatim} |
---|
1163 | t1=simd<8>:const(10); |
---|
1164 | t2=simd<16>:const(100); |
---|
1165 | t3=simd<32>:const(10000); |
---|
1166 | b=simd<8>::add<x,l>(simd<8>::mult<h,x>(d,t1), d); |
---|
1167 | b=simd<16>::add<x,l>(simd<16>::mult<h,x>(b,t2), b); |
---|
1168 | b=simd<32>::add<x,l>(simd<32>::mult<h,x>(b,t3), b); |
---|
1169 | \end{verbatim} |
---|
1170 | \end{center} |
---|
1171 | \caption{IDISA Parity Implementation} |
---|
1172 | \label{ID-BCD2int} |
---|
1173 | \end{figure} |
---|
1174 | |
---|
1175 | Just as DNA sequences represent an important use case for |
---|
1176 | SWAR operations on 2-bit fields, packed sequences of |
---|
1177 | decimal or hexadecimal digits represent a common use case |
---|
1178 | for 4-bit fields. These representations can be used |
---|
1179 | both as an intermediate form in numeric string to integer |
---|
1180 | conversion and as a direct representation for |
---|
1181 | packed binary coded decimal. |
---|
1182 | |
---|
1183 | Figure \ref{BCD2int} shows a three-step inductive |
---|
1184 | doubling implementation for conversion of 32-bit packed BCD |
---|
1185 | values to integer form. The 32-bit value consists |
---|
1186 | of 8 4-bit decimal digits. Pairs of digits are |
---|
1187 | first combined by multiplying the higher digit |
---|
1188 | of the pair by 10 and adding. Pairs of these |
---|
1189 | two-digit results are then further combined by |
---|
1190 | multiplying the value of the higher of the two-digit |
---|
1191 | results by 100 and adding. The final step is |
---|
1192 | to combine four-digit results by multiplying the |
---|
1193 | higher one by 10000 and adding. Overall, 20 |
---|
1194 | operations are required for this implementation |
---|
1195 | as well as the corresponding SWAR implementation |
---|
1196 | for sets of 32-bit fields. Preloading of 6 constants |
---|
1197 | into registers for repeated use can reduce the number of |
---|
1198 | operations to 14 at the cost of significant register |
---|
1199 | pressure. |
---|
1200 | |
---|
1201 | The IDISA implementation of this algorithm is shown |
---|
1202 | in Figure \ref{ID-BCD2int}. This implementation |
---|
1203 | shows an interesting variation in the use of |
---|
1204 | half-operand modifiers, with only one operand |
---|
1205 | of each of the addition and multiplication operations |
---|
1206 | modified at each level. Overall, this implementation |
---|
1207 | requires 9 operations, or 6 operations with 3 |
---|
1208 | preloaded constants. This represents more than a 2X |
---|
1209 | reduction in instruction count as well as a 2X reduction |
---|
1210 | in register pressure. |
---|
1211 | |
---|
1212 | |
---|
1213 | |
---|
1214 | |
---|
1215 | \subsection{Systematic Support for Horizontal SIMD Operations} |
---|
1216 | |
---|
1217 | In SIMD parlance, {\em horizontal} operations are |
---|
1218 | operations which combine values from two or more fields |
---|
1219 | of the same register, in contrast to the normal |
---|
1220 | {\em vertical} operations which combine corresponding |
---|
1221 | fields of different registers. Horizontal operations |
---|
1222 | can be found that combine two (e.g., \verb:haddpd: on SSE3), |
---|
1223 | four (e.g, \verb:si_orx: on SPU), eight (e.g, \verb:psadbw: on SSE) |
---|
1224 | or sixteen values (e.g., \verb:vcmpequb: on Altivec). Some |
---|
1225 | horizontal operations have a vertical component as well. |
---|
1226 | For example, \verb:psadbw: first forms the absolute value of |
---|
1227 | the difference of eight corresponding byte fields before |
---|
1228 | performing horizontal add of the eight values, while |
---|
1229 | \verb:vsum4ubs: on Altivec performs horizontal add of sets of |
---|
1230 | four unsigned 8-bit fields within one register |
---|
1231 | and then combines the result horizontally with |
---|
1232 | corresponding 32-bit fields of a second registers. |
---|
1233 | |
---|
1234 | The space of potential horizontal operations thus has |
---|
1235 | many dimensions, including not only the particular |
---|
1236 | combining operation and the operand field width, but |
---|
1237 | also the number of fields being combined, whether a |
---|
1238 | vertical combination is applied and whether it is applied |
---|
1239 | before or after the horizontal operation and what the |
---|
1240 | nature of the vertical combining operation is. |
---|
1241 | Within this space, commodity SIMD architectures tend |
---|
1242 | to support only a very few combinations, without any |
---|
1243 | particular attempt at systematic support for horizontal |
---|
1244 | operations in general. |
---|
1245 | |
---|
1246 | In contrast to this {\em ad hoc} support on commodity |
---|
1247 | processors, IDISA offers a completely systematic treatment |
---|
1248 | of horizontal operations without any special features beyond |
---|
1249 | the inductive doubling features already described. |
---|
1250 | In the simplest case, any vertical operation |
---|
1251 | \verb#simd<n>::F# on $n$-bit fields gives rise to |
---|
1252 | an immediate horizontal operation |
---|
1253 | \verb#simd<n>::F<h,l>(r, r)# for combining adjacent |
---|
1254 | pairs of $n/2$ bit fields. |
---|
1255 | For example, \verb#simd<16>::add<h,l># adds values |
---|
1256 | in adjacent 8 bit fields to produce 16 bit results, |
---|
1257 | while \verb#simd<32>::min<h,l># can produce the |
---|
1258 | minimum value of adjacent 16-bit fields. |
---|
1259 | Thus any binary horizontal operation can be implemented |
---|
1260 | in a single IDISA instruction making use of the \verb:<h,l>: |
---|
1261 | operand modifier combination. |
---|
1262 | |
---|
1263 | Horizontal combinations of four adjacent fields can also be |
---|
1264 | realized in a general way through two steps of inductive |
---|
1265 | doubling. For example, consider the or-across operation \verb:si_orx: |
---|
1266 | of the SPU, that performs a logical or operation |
---|
1267 | on four 32-bit fields. This four field combination |
---|
1268 | can easily be implemented with the following two operations. |
---|
1269 | %\begin{singlespace} |
---|
1270 | \begin{verbatim} |
---|
1271 | t = simd<64>::or<h,l>(x, x) |
---|
1272 | t = simd<128>::or<h,l>(t, t) |
---|
1273 | \end{verbatim} |
---|
1274 | %\end{singlespace} |
---|
1275 | |
---|
1276 | In general, systematic support for horizontal |
---|
1277 | combinations of sets of $2^h$ adjacent fields may |
---|
1278 | be realized through $h$ inductive double steps |
---|
1279 | in a similar fashion. |
---|
1280 | Thus, IDISA esssentially offers systematic support |
---|
1281 | for horizontal operations entirely through the |
---|
1282 | use of \verb:<h,l>: half-operand modifier |
---|
1283 | combinations. |
---|
1284 | |
---|
1285 | Systematic support for general horizontal operations |
---|
1286 | under IDISA also creates opportunity for a design tradeoff: |
---|
1287 | offsetting the circuit complexity of half-operand |
---|
1288 | modifiers with potential elimination of dedicated |
---|
1289 | logic for some {/ad hoc} horizontal SIMD operations. |
---|
1290 | Even if legacy support for these operations is required, |
---|
1291 | it may be possible to provide that support through |
---|
1292 | software or firmware rather than a full hardware |
---|
1293 | implementation. Evaluation of these possibilities |
---|
1294 | in the context of particular architectures is a potential |
---|
1295 | area for further work. |
---|
1296 | |
---|
1297 | |
---|
1298 | \section{Implementation} |
---|
1299 | |
---|
1300 | IDISA may be implemented as a software |
---|
1301 | abstraction on top of existing SWAR architectures or |
---|
1302 | directly in hardware. In this section, we briefly |
---|
1303 | discuss implementation of IDISA libraries before |
---|
1304 | moving on to consider hardware design. Although |
---|
1305 | a full realization of IDISA in hardware is beyond our |
---|
1306 | current capabilities, our goal is to develop a sufficiently |
---|
1307 | detailed design to assess the costs of IDISA implementation |
---|
1308 | in terms of the incremental complexity over the RefA |
---|
1309 | and RefB architectures. The cost factors we consider, then, |
---|
1310 | are the implementation of the half-operand modifiers, and |
---|
1311 | the extension of core operations to the 2-bit, 4-bit and |
---|
1312 | 128-bit field widths. In each case, we also discuss |
---|
1313 | design tradeoffs. |
---|
1314 | |
---|
1315 | \subsection{IDISA Libraries} |
---|
1316 | |
---|
1317 | Implementation of IDISA instructions using template |
---|
1318 | and macro libraries has been useful in developing |
---|
1319 | and assessing the correctness of many of the algorithms |
---|
1320 | presented here. Although these implementations do not |
---|
1321 | deliver the performance benefits associated with |
---|
1322 | direct hardware implementation of IDISA, they |
---|
1323 | have been quite useful in providing a practical means |
---|
1324 | for portable implementation of parallel bit stream |
---|
1325 | algorithms on multiple SWAR architectures. However, |
---|
1326 | one additional facility has also proven necessary for |
---|
1327 | portability of parallel bit stream algorithms across |
---|
1328 | big-endian and little-endian architectures: the |
---|
1329 | notion of shift-forward and shift-back operations. |
---|
1330 | In essence, shift forward means shift to the left |
---|
1331 | on little-endian systems and shift to the right on |
---|
1332 | big-endian systems, while shift back has the reverse |
---|
1333 | interpretation. Although this concept is unrelated to |
---|
1334 | inductive doubling, its inclusion with the IDISA |
---|
1335 | libraries has provided a suitable basis for portable |
---|
1336 | SIMD implementations of parallel bit stream algorithms. |
---|
1337 | Beyond this, the IDISA libraries have the additional |
---|
1338 | benefit of allowing the implementation |
---|
1339 | of inductive doubling algorithms at a higher level |
---|
1340 | abstraction, without need for programmer coding of |
---|
1341 | the underlying shift and mask operations. |
---|
1342 | |
---|
1343 | \subsection{IDISA Model} |
---|
1344 | \begin{figure}[tbh] |
---|
1345 | \begin{center} |
---|
1346 | \includegraphics[width=90mm, trim= 50 350 0 50]{IDISA.pdf} |
---|
1347 | \caption{IDISA Block Diagram} |
---|
1348 | \label{pipeline-model} |
---|
1349 | \end{center} |
---|
1350 | \end{figure} |
---|
1351 | |
---|
1352 | Figure \ref{pipeline-model} shows a block diagram |
---|
1353 | for a pipelined SIMD processor implementing IDISA. |
---|
1354 | The SIMD Register File (SRF) provides a file of $R = 2^A$ |
---|
1355 | registers each of width $N = 2^K$ bits. |
---|
1356 | IDISA instructions identified by the Instruction Fetch |
---|
1357 | Unit (IFU) are forwarded for decoding to the SIMD |
---|
1358 | Instruction Decode Unit (SIDU). This unit decodes |
---|
1359 | the instruction to produce |
---|
1360 | signals identifying the source and destination |
---|
1361 | operand registers, the half-operand modifiers, the |
---|
1362 | field width specification and the SIMD operation |
---|
1363 | to be applied. |
---|
1364 | |
---|
1365 | The SIDU supplies the source register information and the half-operand |
---|
1366 | modifier information to the SIMD Operand Fetch Unit (SOFU). |
---|
1367 | For each source operand, the SIDU provides an $A$-bit register |
---|
1368 | address and two 1-bit signals $h$ and $l$ indicating the value |
---|
1369 | of the decoded half-operand modifiers for this operand. |
---|
1370 | Only one of these values may be 1; both are 0 if |
---|
1371 | no modifier is specified. |
---|
1372 | The SIDU also supplies decoded field width signals $w_k$ |
---|
1373 | for each field width $2^k$ to both the SOFU and to the |
---|
1374 | SIMD Instruction Execute Unit (SIEU). Only one of the |
---|
1375 | field width signals has the value 1. |
---|
1376 | The SIDU also supplies decoded SIMD opcode information to SIEU and |
---|
1377 | a decoded $A$-bit register address for the destination register to |
---|
1378 | the SIMD Result Write Back Unit (SRWBU). |
---|
1379 | |
---|
1380 | The SOFU is the key component of the IDISA model that |
---|
1381 | differs from that found in a traditional SWAR |
---|
1382 | processor. For each of the two $A$-bit source |
---|
1383 | register addresses, SOFU is first responsible for |
---|
1384 | fetching the raw operand values from the SRF. |
---|
1385 | Then, before supplying operand values to the |
---|
1386 | SIEU, the SOFU applies the half-operand modification |
---|
1387 | logic as specified by the $h$, $l$, and field-width |
---|
1388 | signals. The possibly modified operand values are then |
---|
1389 | provided to the SIEU for carrying out the SIMD operations. |
---|
1390 | A detailed model of SOFU logic is described in the following |
---|
1391 | subsection. |
---|
1392 | |
---|
1393 | The SIEU differs from similar execution units in |
---|
1394 | current commodity processors primarily by providing |
---|
1395 | SIMD operations at each field width |
---|
1396 | $n=2^k$ for $0 \leq k \leq K$. This involves |
---|
1397 | additional circuitry for field widths not supported |
---|
1398 | in existing processors. In our evaluation model, |
---|
1399 | IDISA-A adds support for 2-bit, 4-bit and 128-bit |
---|
1400 | field widths in comparison with the RefA architecture, |
---|
1401 | while IDISA-B similarly extends RefB. |
---|
1402 | |
---|
1403 | When execution of the SWAR instruction is |
---|
1404 | completed, the result value is then provided |
---|
1405 | to the SRWBU to update the value stored in the |
---|
1406 | SRF at the address specified by the $A$-bit |
---|
1407 | destination operand. |
---|
1408 | |
---|
1409 | \subsection{Operand Fetch Unit Logic} |
---|
1410 | |
---|
1411 | The SOFU is responsible for implementing the half-operand |
---|
1412 | modification logic for each of up to two input operands fetched |
---|
1413 | from SRF. For each operand, this logic is implemented |
---|
1414 | using the decoded half-operand modifiers signals $h$ and $l$, |
---|
1415 | the decoded field width signals $w_k$ and the 128-bit operand |
---|
1416 | value $r$ fetched from SRF to produce a modified 128-bit operand |
---|
1417 | value $s$ following the requirements of equations (4), (5) and |
---|
1418 | (6) above. Those equations must be applied for each possible |
---|
1419 | modifier and each field width to determine the possible values $s[i]$ |
---|
1420 | for each bit position $i$. For example, consider bit |
---|
1421 | position 41, whose binary 7-bit address is $0101001$. |
---|
1422 | Considering the address bits left to right, each 1 bit |
---|
1423 | corresponds to a field width for which this bit lies in the |
---|
1424 | lower $n/2$ bits (widths 2, 16, 64), while each 0 bit corresponds to a field |
---|
1425 | width for which this bit lies in the high $n/2$ bits. |
---|
1426 | In response to the half-operand modifier signal $h$, |
---|
1427 | this bit may receive a value from the corresponding field |
---|
1428 | of width 2, 16 or 64 whose address bit is 0, namely $r[40]$, |
---|
1429 | $r[33]$ or $r[9]$. Otherwise, this bit receives the value $r[41]$, |
---|
1430 | in the case of no half-operand modifier, or a low half-operand modifier |
---|
1431 | in conjunction with a field width signal $w_2$, $w_{16}$ or $w_{64}$. |
---|
1432 | The overall logic for determining this bit value is thus given as follows. |
---|
1433 | \begin{eqnarray*} |
---|
1434 | s[41] & = & h \wedge (w_2 \wedge r[40] \vee w_{16} \wedge r[33] \vee w_{64} \wedge r[9]) \\ |
---|
1435 | & & \vee \neg h \wedge (\neg l \vee w_2 \vee w_{16} \vee w_{64}) \wedge r[41] |
---|
1436 | \end{eqnarray*} |
---|
1437 | |
---|
1438 | Similar logic is determined for each of the 128 bit positions. |
---|
1439 | For each of the 7 field widths, 64 bits are in the low $n/2$ bits, |
---|
1440 | resulting in 448 2-input and gates for the $w_k \wedge r[i]$ terms. |
---|
1441 | For 120 of the bit positions, or gates are needed to combine these |
---|
1442 | terms; $441 -120 = 321$ 2-input or gates are required. Another |
---|
1443 | 127 2-input and gates combine these values with the $h$ signal. |
---|
1444 | In the case of a low-half-operand modifier, the or-gates combining $w_k$ |
---|
1445 | signals can share circuitry. For each bit position $i=2^k+j$ one |
---|
1446 | additional or gate is required beyond that for position $j$. |
---|
1447 | Thus 127 2-input or gates are required. Another 256 2-input and gates |
---|
1448 | are required for combination with the $\neg h$ and $r[i]$ terms. The terms for |
---|
1449 | the low and high half-operand modifiers are then combined with an |
---|
1450 | additional 127 2-input or gates. Thus, the circuity complexity |
---|
1451 | for the combinational logic implementation of half-operand |
---|
1452 | modifiers within the SOFU is 1279 2-input gates per operand, |
---|
1453 | or 2558 gates in total. |
---|
1454 | |
---|
1455 | The gate-level complexity of half-operand modifiers as described is nontrivial, |
---|
1456 | but modest. However, one possible design tradeoff is to |
---|
1457 | differentiate the two operands, permitting a high half-operand |
---|
1458 | modifier to be used only with the first operand and a low-modifier |
---|
1459 | to be used only with the second operand. This would exclude |
---|
1460 | \verb#<h,h># and \verb#<l,l># modifier combinations and also |
---|
1461 | certain combinations for noncommutative core operations. |
---|
1462 | The principal |
---|
1463 | consequence for the applications considered here would be with |
---|
1464 | respect to the pack operations in forward transposition, but it |
---|
1465 | may be possible to address this through SIEU circuitry. |
---|
1466 | If this approach were to be taken, the gate complexity of |
---|
1467 | half-operand modification would be reduced by slightly more than half. |
---|
1468 | |
---|
1469 | \subsection{2-Bit and 4-Bit Field Widths} |
---|
1470 | |
---|
1471 | Beyond the half-operand modifiers, extension of core SWAR |
---|
1472 | operations to 2-bit and 4-bit field widths is critical to |
---|
1473 | inductive doubling support. The principal operations |
---|
1474 | that need to be supported in this way are addition, pack, merge |
---|
1475 | merge, and rotate. |
---|
1476 | |
---|
1477 | Addition for 4-bit fields in a 128-bit SWAR processor may be implemented |
---|
1478 | as a modification to that for 8-bit fields by incorporating logic to |
---|
1479 | disable carry propagation at the 16 midfield boundaries. For 2-bit |
---|
1480 | fields, disabling carry propagation at 32 additional boundaries suffices, |
---|
1481 | although it may be simpler to directly implement the simple logic |
---|
1482 | of 2-bit adders. |
---|
1483 | |
---|
1484 | Pack and merge require bit selection logic for each field width. |
---|
1485 | A straightforward implementation model for each operation |
---|
1486 | uses 128 2-input and gates to select the desired bits from the |
---|
1487 | operand registers and another 128 2-input or gates to feed |
---|
1488 | these results into the destination register. |
---|
1489 | |
---|
1490 | Rotation for 2-bit fields involves simple logic for selecting |
---|
1491 | between the 2 bits of each field of the operand being |
---|
1492 | rotated on the basis of the low bit of each field of the |
---|
1493 | rotation count. Rotation for 4-bit fields is more complex, |
---|
1494 | but can also be based on 1-of-4 selection circuitry |
---|
1495 | involving the low 2 bits of the rotation count fields. |
---|
1496 | |
---|
1497 | \subsection{128-Bit Field Widths} |
---|
1498 | |
---|
1499 | For completeness, the IDISA model requires core operations |
---|
1500 | to be implemented at the full register width, as well |
---|
1501 | as power-of-2 partitions. This may be problematic for |
---|
1502 | operations such as addition due to the inherent delays |
---|
1503 | in 128-bit carry propagation. However, the primary |
---|
1504 | role of 128 bit operations in inductive doubling |
---|
1505 | is to combine two 64-bit fields using \verb#<h,l># |
---|
1506 | operand combinations. In view of this, it may be |
---|
1507 | reasonable to define hardware support for such |
---|
1508 | combinations to be based on 64-bit logic, with support |
---|
1509 | for 128-bit logic implemented through firmware or software. |
---|
1510 | |
---|
1511 | \subsection{Final Notes and Further Tradeoffs} |
---|
1512 | |
---|
1513 | In order to present IDISA as a concept for design extension of |
---|
1514 | any SWAR architecture, our discussion of gate-level implementation |
---|
1515 | is necessarily abstract. Additional circuitry is sure to be |
---|
1516 | required, for example, in implementation of SIDU. However, |
---|
1517 | in context of the 128-bit reference architectures studied, |
---|
1518 | our analysis suggests realistic IDISA implementation well |
---|
1519 | within a 10,000 gate budget. |
---|
1520 | |
---|
1521 | However, the additional circuitry required may be offset |
---|
1522 | by elimination of special-purpose instructions found in |
---|
1523 | existing processors that could instead be implemented through efficient |
---|
1524 | IDISA sequences. These include examples such as population |
---|
1525 | count, count leading and/or trailing zeroes and parity. |
---|
1526 | They also include specialized horizontal SIMD operations. |
---|
1527 | Thus, design tradeoffs can be made with the potential of |
---|
1528 | reducing the chip area devoted to special purpose instructions |
---|
1529 | in favor of more general IDISA features. |
---|
1530 | |
---|
1531 | \section{Conclusions} |
---|
1532 | |
---|
1533 | In considering the architectural support for |
---|
1534 | SIMD text processing using the method of parallel bit streams, |
---|
1535 | this paper has presented the principle of inductive doubling |
---|
1536 | and a realization of that principle in the form of |
---|
1537 | IDISA, a modified SWAR instruction set architecture. |
---|
1538 | IDISA offers support for SWAR operations at all power-of-2 |
---|
1539 | field widths, including 2-bit and 4-bit widths, in particular, |
---|
1540 | as well as half-operand modifiers and pack and merge operations |
---|
1541 | to support efficient transition between successive power-of-two |
---|
1542 | field widths. The principle innovation is the notion of |
---|
1543 | half-operand modifiers that eliminate the cost associated |
---|
1544 | with the explicit mask and shift operations required for |
---|
1545 | such transitions. |
---|
1546 | |
---|
1547 | Several algorithms key to parallel bit stream methods |
---|
1548 | have been examined and shown to benefit from dramatic |
---|
1549 | reductions in instruction count compared to the best |
---|
1550 | known algorithms on reference architectures. This |
---|
1551 | includes both a reference architecture modeled on |
---|
1552 | the SWAR capabilities of the SSE family as well as |
---|
1553 | an architecture incorporating the powerful permute |
---|
1554 | or shuffle capabilities found in Altivec or Cell BE processors. |
---|
1555 | In the case of transposition algorithms to and from parallel bit stream |
---|
1556 | form, the architecture has been shown to make possible |
---|
1557 | straightforward inductive doubling algorithms with the |
---|
1558 | lowest total number of operations that can be achieved by |
---|
1559 | any possible 3-register SWAR architecture. |
---|
1560 | |
---|
1561 | Applications of IDISA in other areas have also been |
---|
1562 | examined. The support for 2-bit and 4-bit field widths |
---|
1563 | in SWAR processing is beneficial for packed DNA representations |
---|
1564 | and packed decimal representations respectively. Additional |
---|
1565 | inductive doubling examples are presented and the phenomenon |
---|
1566 | of power-of-2 transitions discussed more broadly. |
---|
1567 | Most significantly, IDISA supports a fully general approach |
---|
1568 | to horizontal SWAR operations, offering a considerable |
---|
1569 | improvement over the {\em ad hoc} sets of special-purpose |
---|
1570 | horizontal operations found in existing SWAR instruction sets. |
---|
1571 | |
---|
1572 | An IDISA implementation model has been presented employing |
---|
1573 | a customized operand fetch unit to implement the half-operand |
---|
1574 | modifier logic. Gate-level implementation of this unit |
---|
1575 | and operations at the 2-bit and 4-bit field widths have |
---|
1576 | been analyzed and found to be quite reasonable within |
---|
1577 | a 10,000 gate bound. Design tradeoffs to reduce the cost |
---|
1578 | have also been discussed, possibly even leading to a |
---|
1579 | net complexity reduction through elimination of instructions |
---|
1580 | that implement special-case versions of inductive doubling. |
---|
1581 | |
---|
1582 | Future research may consider the extension of inductive doubling |
---|
1583 | support in further ways. For example, it may be possible |
---|
1584 | to develop a pipelined architecture supporting two or three |
---|
1585 | steps of inductive doubling in a single operation. |
---|
1586 | |
---|
1587 | %\appendix |
---|
1588 | %\section{Appendix Title} |
---|
1589 | % |
---|
1590 | %This is the text of the appendix, if you need one. |
---|
1591 | |
---|
1592 | \acks |
---|
1593 | |
---|
1594 | This research was supported by a Discovery Grant from the |
---|
1595 | Natural Sciences and Engineering Research Council of Canada. |
---|
1596 | |
---|
1597 | %\bibliographystyle{plainnat} |
---|
1598 | \bibliographystyle{plain} |
---|
1599 | \bibliography{asplos094-cameron} |
---|
1600 | %\begin{thebibliography}{} |
---|
1601 | |
---|
1602 | %\bibitem{smith02} |
---|
1603 | %Smith, P. Q. reference text |
---|
1604 | |
---|
1605 | %\end{thebibliography} |
---|
1606 | |
---|
1607 | |
---|
1608 | \end{document} |
---|