]> granicus.if.org Git - clang/commitdiff
[PowerPC] Add the support for __builtin_setrnd() in clang
authorKang Zhang <shkzhang@cn.ibm.com>
Fri, 29 Mar 2019 09:11:52 +0000 (09:11 +0000)
committerKang Zhang <shkzhang@cn.ibm.com>
Fri, 29 Mar 2019 09:11:52 +0000 (09:11 +0000)
Summary:
PowerPC64/PowerPC64le supports the builtin function __builtin_setrnd to set the floating point rounding mode. This function will use the least significant two bits of integer argument to set the floating point rounding mode.
double __builtin_setrnd(int mode);
The effective values for mode are:
0 - round to nearest
1 - round to zero
2 - round to +infinity
3 - round to -infinity
Note that the mode argument will modulo 4, so if the int argument is greater than 3, it will only use the least significant two bits of the mode. Namely, builtin_setrnd(102)) is equal to builtin_setrnd(2).

Reviewed By: jsji

Differential Revision: https://reviews.llvm.org/D59403

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357242 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LanguageExtensions.rst
include/clang/Basic/BuiltinsPPC.def
test/CodeGen/builtins-ppc.c

index d4c40b29f80efffebefb31e1992535e879403cb9..d79d41227777cd3bcb197fbdd58206e4f9dae9c5 100644 (file)
@@ -2376,6 +2376,78 @@ Which compiles to (on X86-32):
           movl    %gs:(%eax), %eax
           ret
 
+PowerPC Language Extensions
+------------------------------
+
+Set the Floating Point Rounding Mode
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+PowerPC64/PowerPC64le supports the builtin function ``__builtin_setrnd`` to set
+the floating point rounding mode. This function will use the least significant
+two bits of integer argument to set the floating point rounding mode.
+
+.. code-block:: c++
+
+  double __builtin_setrnd(int mode);
+
+The effective values for mode are:
+
+    - 0 - round to nearest
+    - 1 - round to zero
+    - 2 - round to +infinity
+    - 3 - round to -infinity
+
+Note that the mode argument will modulo 4, so if the int argument is greater 
+than 3, it will only use the least significant two bits of the mode. 
+Namely, ``__builtin_setrnd(102))`` is equal to ``__builtin_setrnd(2)``.
+
+PowerPC Language Extensions
+------------------------------
+
+Set the Floating Point Rounding Mode
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+PowerPC64/PowerPC64le supports the builtin function ``__builtin_setrnd`` to set
+the floating point rounding mode. This function will use the least significant
+two bits of integer argument to set the floating point rounding mode.
+
+.. code-block:: c++
+
+  double __builtin_setrnd(int mode);
+
+The effective values for mode are:
+
+    - 0 - round to nearest
+    - 1 - round to zero
+    - 2 - round to +infinity
+    - 3 - round to -infinity
+
+Note that the mode argument will modulo 4, so if the integer argument is greater
+than 3, it will only use the least significant two bits of the mode. 
+Namely, ``__builtin_setrnd(102))`` is equal to ``__builtin_setrnd(2)``.
+
+PowerPC Language Extensions
+------------------------------
+
+Set the Floating Point Rounding Mode
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+PowerPC64/PowerPC64le supports the builtin function ``__builtin_setrnd`` to set
+the floating point rounding mode. This function will use the least significant
+two bits of integer argument to set the floating point rounding mode.
+
+.. code-block:: c++
+
+  double __builtin_setrnd(int mode);
+
+The effective values for mode are:
+
+    - 0 - round to nearest
+    - 1 - round to zero
+    - 2 - round to +infinity
+    - 3 - round to -infinity
+
+Note that the mode argument will modulo 4, so if the integer argument is greater
+than 3, it will only use the least significant two bits of the mode. 
+Namely, ``__builtin_setrnd(102))`` is equal to ``__builtin_setrnd(2)``.
+
 Extensions for Static Analysis
 ==============================
 
index e55fa04a3b6cc15a17d78ea519aeee8d6f40f09c..9292458462ac4eee1b4e3a4c13f128cc30ff19d7 100644 (file)
@@ -475,6 +475,9 @@ BUILTIN(__builtin_bpermd, "SLLiSLLiSLLi", "")
 BUILTIN(__builtin_unpack_vector_int128, "ULLiV1LLLii", "")
 BUILTIN(__builtin_pack_vector_int128, "V1LLLiULLiULLi", "")
 
+// Set the floating point rounding mode
+BUILTIN(__builtin_setrnd, "di", "")
+
 // FIXME: Obviously incomplete.
 
 #undef BUILTIN
index 1f17787ad9c874269f9a80f28c0d7aa74c3b034d..1ff1b811c1a0f06e0bce03a75c47c6d94305761c 100644 (file)
@@ -14,3 +14,16 @@ long long test_builtin_ppc_get_timebase() {
   return __builtin_ppc_get_timebase();
 }
 
+void test_builtin_ppc_setrnd() {
+  volatile double res;
+  volatile int x = 100;
+  
+  // CHECK: call double @llvm.ppc.setrnd(i32 2)
+  res = __builtin_setrnd(2);
+
+  // CHECK: call double @llvm.ppc.setrnd(i32 100)
+  res = __builtin_setrnd(100);
+
+  // CHECK: call double @llvm.ppc.setrnd(i32 %2)
+  res = __builtin_setrnd(x);
+}