1e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung//===- subzero/crosstest/test_bitmanip.cpp - Implementation for tests. ----===// 2e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// 3e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// The Subzero Code Generator 4e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// 5e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// This file is distributed under the University of Illinois Open Source 6e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// License. See LICENSE.TXT for details. 7e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// 8e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung//===----------------------------------------------------------------------===// 9e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// 10e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// This aims to test that all the bit manipulation intrinsics work, via 11e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// cross-testing. This calls wrappers (my_{ctlz,cttz,ctpop} around the 12e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung// intrinsics (llvm.{ctlz,cttz,ctpop}.*). 13e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung//===----------------------------------------------------------------------===// 14e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung 15e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung#include <stdint.h> 16e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung 17e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung#include <cstdlib> 18e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung 19e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung#include "test_bitmanip.h" 20e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung 21e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung#define X(inst, type) \ 22e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung type test_##inst(type a) { return my_##inst(a); } \ 23e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung type test_alloca_##inst(type a) { \ 24e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung const size_t buf_size = 8; \ 25e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung type buf[buf_size]; \ 26e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung for (size_t i = 0; i < buf_size; ++i) { \ 27e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung buf[i] = my_##inst(a); \ 28e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung } \ 29e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung type sum = 0; \ 30e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung for (size_t i = 0; i < buf_size; ++i) { \ 31e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung sum += buf[i]; \ 32e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung } \ 33e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung return sum; \ 34e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung } \ 35e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung type test_const_##inst(type ignored) { \ 36e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung return my_##inst(static_cast<type>(0x12340)); \ 37e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung } 38e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung 39e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan VoungFOR_ALL_BMI_OP_TYPES(X) 40e4da26f6de7afd0e0b25a7e5c6c8401b964dfa62Jan Voung#undef X 417fa813b31abd816623b02a205b0b1bda51e6bfc8Jan Voung 427fa813b31abd816623b02a205b0b1bda51e6bfc8Jan Voung#define X(type, builtin_name) \ 433b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung type test_bswap(type a) { return builtin_name(a); } \ 443b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung type test_bswap_alloca(type a) { \ 453b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung const size_t buf_size = 8; \ 463b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung type buf[buf_size]; \ 473b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung for (size_t i = 0; i < buf_size; ++i) { \ 483b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung buf[i] = builtin_name(a * i) + builtin_name(a + i); \ 493b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung } \ 503b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung type sum = 0; \ 513b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung for (size_t i = 0; i < buf_size; ++i) { \ 523b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung sum += buf[i]; \ 533b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung } \ 543b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung return sum; \ 553b43b8968fff7ec287967a2f549c404bfb89d898Jan Voung } 567fa813b31abd816623b02a205b0b1bda51e6bfc8Jan VoungBSWAP_TABLE 577fa813b31abd816623b02a205b0b1bda51e6bfc8Jan Voung#undef X 58