File: shift_by_unsigned_negated.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 (46 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (3)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Halide.h"

using namespace Halide;

template<typename T>
bool test(Func f, T f_expected, int width) {
    Buffer<uint32_t> actual = f.realize({width});
    for (int i = 0; i < actual.width(); i++) {
        if (actual(i) != f_expected(i)) {
            printf("r(%d) = %d, f_expected(%d) = %d\n",
                   i, actual(i), i, f_expected(i));
            return false;
        }
    }
    return true;
}

int main(int argc, char **argv) {
    Buffer<uint32_t> step(31);
    for (int i = 0; i < step.width(); i++) {
        step(i) = -i;
    }

    bool success = true;
    Var x;

    {
        Func f;
        f(x) = Expr(-1U) << -step(x);
        auto f_expected = [&](int x) {
            return -1U << x;
        };
        success &= test(f, f_expected, step.width());
    }
    {
        Func f;
        f(x) = Expr(-1U) >> -step(x);
        auto f_expected = [&](int x) {
            return -1U >> x;
        };
        success &= test(f, f_expected, step.width());
    }

    if (success) printf("Success!\n");
    return success ? 0 : -1;
}