File: bound_small_allocations.cpp

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (29 lines) | stat: -rw-r--r-- 847 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "Halide.h"
#include <stdio.h>

using namespace Halide;
Expr calc(Expr a) {
    Expr prod = cast<int64_t>(a) * cast<int64_t>(a);
    Expr scaled = (prod + (1 << 30)) >> 31;
    Expr clamped = clamp(scaled, Int(32).min(), Int(32).max());
    return cast<int32_t>(clamped);
}

int main(int argc, char **argv) {
    Var x, y;
    Func f, g, h;

    // Construct a series of operations that will trigger a signed_integer_overflow
    // during simplification
    f(x, y) = calc(max(x + (1 << 28), -(1 << 29) + (1 << 28)));
    g(x, y) = calc(f(x, y)) + f(x, y) / 4 + (1 << 30);
    h(x, y) = calc(g(x, y)) + g(x, y) / 4 + (1 << 30);
    h.vectorize(x, 8).compute_root();

    Buffer<int32_t> imf = h.realize({32, 32});

    // No verification of output: just want to verify no compile-time assertion

    printf("Success!\n");
    return 0;
}