blob: 181286e492d88ede1c02e110dee74695899024b1 [file] [log] [blame]
Jan Vounge4da26f2014-07-15 17:52:39 -07001//===- subzero/crosstest/test_bitmanip.cpp - Implementation for tests. ----===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This aims to test that all the bit manipulation intrinsics work, via
11// cross-testing. This calls wrappers (my_{ctlz,cttz,ctpop} around the
12// intrinsics (llvm.{ctlz,cttz,ctpop}.*).
13//===----------------------------------------------------------------------===//
14
15#include <stdint.h>
16
17#include <cstdlib>
18
19#include "test_bitmanip.h"
20
21#define X(inst, type) \
22 type test_##inst(type a) { return my_##inst(a); } \
23 type test_alloca_##inst(type a) { \
24 const size_t buf_size = 8; \
25 type buf[buf_size]; \
26 for (size_t i = 0; i < buf_size; ++i) { \
27 buf[i] = my_##inst(a); \
28 } \
29 type sum = 0; \
30 for (size_t i = 0; i < buf_size; ++i) { \
31 sum += buf[i]; \
32 } \
33 return sum; \
34 } \
35 type test_const_##inst(type ignored) { \
36 return my_##inst(static_cast<type>(0x12340)); \
37 }
38
39FOR_ALL_BMI_OP_TYPES(X)
40#undef X
Jan Voung7fa813b2014-07-18 13:01:08 -070041
42#define X(type, builtin_name) \
Jan Voung3b43b892014-09-24 13:32:39 -070043 type test_bswap(type a) { return builtin_name(a); } \
44 type test_bswap_alloca(type a) { \
45 const size_t buf_size = 8; \
46 type buf[buf_size]; \
47 for (size_t i = 0; i < buf_size; ++i) { \
48 buf[i] = builtin_name(a * i) + builtin_name(a + i); \
49 } \
50 type sum = 0; \
51 for (size_t i = 0; i < buf_size; ++i) { \
52 sum += buf[i]; \
53 } \
54 return sum; \
55 }
Jan Voung7fa813b2014-07-18 13:01:08 -070056BSWAP_TABLE
57#undef X