[PATCH] D59403: [PowerPC] Add the support for __builtin_setrnd() in clang

Zhang Kang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 20:46:43 PDT 2019


ZhangKang updated this revision to Diff 190782.
ZhangKang added a comment.

Update the patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59403/new/

https://reviews.llvm.org/D59403

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


Index: clang/test/CodeGen/builtins-ppc.c
===================================================================
--- clang/test/CodeGen/builtins-ppc.c
+++ clang/test/CodeGen/builtins-ppc.c
@@ -14,3 +14,16 @@
   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);
+}
Index: clang/include/clang/Basic/BuiltinsPPC.def
===================================================================
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -475,6 +475,9 @@
 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: clang/docs/LanguageExtensions.rst
===================================================================
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -2376,6 +2376,30 @@
           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 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
 ==============================
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59403.190782.patch
Type: text/x-patch
Size: 2215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190315/4855880b/attachment.bin>


More information about the llvm-commits mailing list