Halide  12.0.1
Halide compiler and libraries
FastIntegerDivide.h
Go to the documentation of this file.
1 #ifndef HALIDE_FAST_INTEGER_DIVIDE_H
2 #define HALIDE_FAST_INTEGER_DIVIDE_H
3 
4 #include "Buffer.h"
5 #include "Expr.h"
6 
7 namespace Halide {
8 
9 /** Integer division by small values can be done exactly as multiplies
10  * and shifts. This function does integer division for numerators of
11  * various integer types (8, 16, 32 bit signed and unsigned)
12  * numerators and uint8 denominators. The type of the result is the
13  * type of the numerator. The unsigned version is faster than the
14  * signed version, so cast the numerator to an unsigned int if you
15  * know it's positive.
16  *
17  * If your divisor is compile-time constant, Halide performs a
18  * slightly better optimization automatically, so there's no need to
19  * use this function (but it won't hurt).
20  *
21  * This function vectorizes well on arm, and well on x86 for 16 and 8
22  * bit vectors. For 32-bit vectors on x86 you're better off using
23  * native integer division.
24  *
25  * Also, this routine treats division by zero as division by
26  * 256. I.e. it interprets the uint8 divisor as a number from 1 to 256
27  * inclusive.
28  */
29 Expr fast_integer_divide(Expr numerator, Expr denominator);
30 
31 /** Use the fast integer division tables to implement a modulo
32  * operation via the Euclidean identity: a%b = a - (a/b)*b
33  */
34 Expr fast_integer_modulo(Expr numerator, Expr denominator);
35 
36 } // namespace Halide
37 
38 #endif
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Expr fast_integer_modulo(Expr numerator, Expr denominator)
Use the fast integer division tables to implement a modulo operation via the Euclidean identity: ab =...
Expr fast_integer_divide(Expr numerator, Expr denominator)
Integer division by small values can be done exactly as multiplies and shifts.
A fragment of Halide syntax.
Definition: Expr.h:256