
Table-based division by small integer constants Florent de Dinechin, Laurent-Stéphane Didier To cite this version: Florent de Dinechin, Laurent-Stéphane Didier. Table-based division by small integer constants. 8th International Symposium on Applied Reconfigurable Computing (ARC), Mar 2012, Hong Kong, Hong Kong SAR China. pp.53-63, 10.1007/978-3-642-28365-9_5. ensl-00642145 HAL Id: ensl-00642145 https://hal-ens-lyon.archives-ouvertes.fr/ensl-00642145 Submitted on 17 Nov 2011 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Table-based division by small integer constants Florent de Dinechin, Laurent-St´ephane Didier LIP, Universit´ede Lyon (ENS-Lyon/CNRS/INRIA/UCBL) 46, all´ee d’Italie, 69364 Lyon Cedex 07 {Florent.de.Dinechin}@ens-lyon.fr LIP6, Universit´ePierre etMarie Curie (UPMC, CNRS) 4 place Jussieu, 75252 Paris Cedex 05 {Laurent-Stephane.Didier}@upmc.fr Abstract. Computing cores to be implemented on FPGAs may involve divisions by small integer constants in fixed or floating point. This article presents a family of architectures addressing this need. They are derived from a simple recurrence whose body can be implemented very efficiently as a look-up table that matches the hardware resources of the target FPGA. For instance, division of a 32-bit integer by the constant 3 may be implemented by a combinatorial circuit of 48 LUT6 on a Virtex- 5. Other options are studied, including iterative implementations, and architectures based on embedded memory blocks. This technique also computes the remainder. An efficient implementation of the correctly rounded division of a floating-point constant by such a small integer is also presented. 1 Introduction When porting applications to FPGAs, arithmetic operations should be opti- mized in an application-specific way whenever possible. This is the goal of the FloPoCo project [1]. This article considers division by a small integer constant, and demonstrates operators for it that are more efficient than approaches based on standard division [2] or on multiplication by the inverse [3, 4]. Division by a small integer constant is an operation that occurs often enough to justify investigating a specific operator for it. This work, for instance, was motivated by the Jacobi stencil algorithm, whose core computes the average of 3 values: this involves a division by 3. Small integer constants are quite common in such situations. Division by 5 also occurs in decimal / binary conversions. The proposed approach could also be used to interleave memory banks in numbers that are not powers of two: if we have d memory banks, an address A must be translated to address A/d in bank A mod d. Division by a constant in a hardware context has actually been studied quite extensively [3, 5, 4], with good surveys in [6, 7]. There are two main families of techniques: those based on additions and subtractions, and those based on multiplication by the inverse. In this article we introduce a technique that is, to our knowledge, new, although it is in essence a straightforward adaptation of the paper-and-pencil division algorithm in the case of small divisors. The reason why this technique is not mentioned in the literature is probably that the core of its iteration itself computes a (smaller) division: it doesn’t reduce to either additions, or multiplications. However, it is very well suited to FPGAs, whose logic is based on look-up tables (LUTs): they may implement such complex operations very efficiently, provided the size in bits of the input numbers matches the number of inputs to the hardware LUTs. Let us introduce this technique with the help of usual decimal arithmetic. Suppose we want to divide an arbitrary number, say 776, by 3. Figure 1 describes the paper-and-pencil algorithm in this case. We first computes the Euclidean division of 7 by 3. This 7 7 6 3 gives the first digit of the quotient, here 2, and the re- mainder is 1. We now have to divide 176 by 3. In the 1 7 2 5 8 second iteration, we divide 17 by 3: the second quotient 2 6 digit is 5, and the remainder is 2. The third iteration divides 26 by 3: the third quotient digit is 8 and the 2 remainder is 2, and this is also the remainder of the di- vision of 776 by 3. Fig. 1. Division by 3 in decimal The key observation is that in this example, the iteration body consists in the Euclidean division of a 2-digit decimal number by 3. The first of these two digits is a remainder from previous iteration: its value is 0, 1 or 2. We may therefore implement this iteration with a look-up table that, for each value from 00 to 29, gives the quotient and the remainder of its division by 3. This small look-up table will allow us to divide by 3 numbers of arbitrary size. In Section 2 we adapt this radix-10 algorithm to a radix that is a power of two, then chose this radix so that the look-up table matches well the fine structure of the target FPGA. We study the case of floating-point inputs in Section 3: it is possible to ensure correct rounding to the nearest for free. Section 4 provides a few results and comparisons. 2 Euclidean division of an integer by a small constant 2.1 Notations Let d be the constant divisor, and let α be a small integer. We will use the representation of x in radix β = 2α, which may also be considered as breaking down the binary decomposition of x into k chunks of α bits (see Figure 3): k−1 −αi α x = xi.2 where xi ∈ {0,..., 2 − 1} Xi=0 2 In all this section, we assume that d is not a multiple of 2, as division by 2 resumes to a constant shift which is for free in FPGAs. 2.2 Algorithm The following algorithm computes the quotient q and the remainder r0 of the high radix euclidean division of x by the constant d. At each step of this algorithm, α the partial dividend yi, the partial remainder ri and one radix-2 digit of the quotient are computed. Algorithm 1 LUT-based computation of x/d 1: procedure ConstantDiv(x, d) 2: rk ← 0 3: for i = k − 1 down to 0 do α 4: yi ← xi +2 ri+1 (this + is a concatenation) 5: (qi,ri) ← (⌊yi/d⌋, yi mod d) (read from a table) 6: end for k −αi 7: return q = Pi=0 qi.2 , r0 8: end procedure Theorem 1. Algorithm 1 computes the Euclidean division of x by d. It outputs k −αi the quotient q = i=0 qi.2 and the remainder r0 so that x = q × d + r0. The radix-2α representationP of the quotient q is also a binary representation, each iteration producing α bits of this quotient. α The proof of this theorem is in appendix. The line yi ← xi +2 ri+1 is simply the concatenation of a remainder and a radix-2α digit. Let us define γ as the size in bits of the largest possible remainder: γ = ⌈log2(d − 1)⌉ – this is also the size of d as d is not a power of two. Then, yi is of size α + γ bits. The second α line of the loop body, (qi,ri) ← (⌊yi/d⌋, yi mod d), computes a radix-2 digit and a remainder: it may be implemented as a look-up table with α + γ bits of input and α + γ bits of output (Fig. 2). Here, α is a parameter which may be chosen to match the target FPGA architecture, as we show below. The algorithm computes α bits of the quotient in one iteration: the larger α, the fewer iterations are needed for a given input number size n. The iteration may be implemented sequentially as depicted on Fig. 2, al- though in all the following we will focus on the fully unrolled architecture de- picted on Fig. 3, which enables high-throughput pipelined implementations. It should be noted that, for a given d, the architecture grows linearly with the input size n, where general division or multiplication architectures grow quadratically. 3 xi α ri+1 ri γ LUT γ α reset qi clk α Fig. 2. LUT-based squential division by a constant of a radix-2 digit extended by a remainder. 4 4 4 4 x3 x2 x1 x0 r3 r2 r1 = r4 =0 LUT 2LUT 2LUT 2 LUT 2 r0 r 4 q3 4 q2 4 q1 4 q0 Fig. 3. LUT-based division by 3 of a 16-bit number written in radix 24 (α = 4, γ = 2) 2.3 Memory structures in current FPGAs Current FPGAs offer two main memory structures. The first is the 4- to 6- input LUT used in the logic fabric. In the following we note LUTk a k-bit input, 1-bit output LUT. In each FPGA family, there are restrictions on LUT utilization. Let us review recent FPGAs with the motivation to build k-input, k-output LUTs.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages12 Page
-
File Size-