diff options
author | arphaman <arphaman@gmail.com> | 2013-09-18 13:35:12 +0100 |
---|---|---|
committer | arphaman <arphaman@gmail.com> | 2013-09-18 13:35:12 +0100 |
commit | 8e83adfdc9dacf83d9bdee65bd23b9416ceededf (patch) | |
tree | 1d85425f68876c179b6f66adcda60c27c5faafe4 | |
parent | a0879b97593067e436bf5c5a3860c3da697a3148 (diff) | |
download | libflangrt-8e83adfdc9dacf83d9bdee65bd23b9416ceededf.tar.gz |
added support for selected_int_kind intrinsic
-rw-r--r-- | include/Core/Core.h | 3 | ||||
-rw-r--r-- | lib/Core/Core.cpp | 13 | ||||
-rw-r--r-- | test/Unit/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/Unit/ipow.cpp | 2 | ||||
-rw-r--r-- | test/Unit/selected_int_kind.cpp | 35 |
5 files changed, 53 insertions, 1 deletions
diff --git a/include/Core/Core.h b/include/Core/Core.h index c03cbd4..2693e41 100644 --- a/include/Core/Core.h +++ b/include/Core/Core.h @@ -11,7 +11,10 @@ #define LLVM_LIBFLANG_CORE_H #include "Libflang.h" +#include <stdint.h> LIBFLANG_ABI void libflang_stop(); +LIBFLANG_ABI int32_t libflang_selected_int_kind(int32_t Range); + #endif diff --git a/lib/Core/Core.cpp b/lib/Core/Core.cpp index 73d5c08..52aa280 100644 --- a/lib/Core/Core.cpp +++ b/lib/Core/Core.cpp @@ -4,3 +4,16 @@ LIBFLANG_ABI void libflang_stop() { exit(0); } + +LIBFLANG_ABI int32_t libflang_selected_int_kind(int32_t Range) { + if(Range <= 2) + return 1; + else if(Range <= 4) + return 2; + else if(Range <= 9) + return 4; + else if(Range <= 18) + return 8; + // NB: add Range <= 38 for Int16 + return -1; +} diff --git a/test/Unit/CMakeLists.txt b/test/Unit/CMakeLists.txt index a5b4a2c..0b648ef 100644 --- a/test/Unit/CMakeLists.txt +++ b/test/Unit/CMakeLists.txt @@ -1 +1,2 @@ add_libflang_test(ipow ipow.cpp) +add_libflang_test(selected_int_kind selected_int_kind.cpp) diff --git a/test/Unit/ipow.cpp b/test/Unit/ipow.cpp index 91cff22..b2dd985 100644 --- a/test/Unit/ipow.cpp +++ b/test/Unit/ipow.cpp @@ -11,7 +11,7 @@ #include <iostream> #include "Numerical/Integer.h" -bool testPowI4(int32_t x, int32_t y, int32_t expected) { +static bool testPowI4(int32_t x, int32_t y, int32_t expected) { x = libflang_pow_i4_i4(x, y); if(x != expected) std::cout << "Error in libflang_pow_i4_i4 - expected " << expected diff --git a/test/Unit/selected_int_kind.cpp b/test/Unit/selected_int_kind.cpp new file mode 100644 index 0000000..78b431b --- /dev/null +++ b/test/Unit/selected_int_kind.cpp @@ -0,0 +1,35 @@ +//===-- selected_int_kind.cpp - Test libflang_selected_int_kind -----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <assert.h> +#include <iostream> +#include "Core/Core.h" + +static bool test(int32_t x, int32_t expected) { + x = libflang_selected_int_kind(x); + if(x != expected) + std::cout << "Error in libflang_selected_int_kind - expected " << expected + << ", got " << x << std::endl; + return x != expected; +} + +int main() { + if(test(-2, 1)) + return 1; + if(test(1,1)) + return 1; + if(test(7,4)) + return 1; + if(test(13,8)) + return 1; + if(test(1000,-1)) + return 1; + return 0; +} + |