Skip to content

Commit e5ac385

Browse files
committedMar 29, 2019
[PowerPC] Add the support for __builtin_setrnd() in clang
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 llvm-svn: 357242
1 parent 05f78b3 commit e5ac385

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
 

‎clang/docs/LanguageExtensions.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,78 @@ Which compiles to (on X86-32):
23762376
movl %gs:(%eax), %eax
23772377
ret
23782378
2379+
PowerPC Language Extensions
2380+
------------------------------
2381+
2382+
Set the Floating Point Rounding Mode
2383+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2384+
PowerPC64/PowerPC64le supports the builtin function ``__builtin_setrnd`` to set
2385+
the floating point rounding mode. This function will use the least significant
2386+
two bits of integer argument to set the floating point rounding mode.
2387+
2388+
.. code-block:: c++
2389+
2390+
double __builtin_setrnd(int mode);
2391+
2392+
The effective values for mode are:
2393+
2394+
- 0 - round to nearest
2395+
- 1 - round to zero
2396+
- 2 - round to +infinity
2397+
- 3 - round to -infinity
2398+
2399+
Note that the mode argument will modulo 4, so if the int argument is greater
2400+
than 3, it will only use the least significant two bits of the mode.
2401+
Namely, ``__builtin_setrnd(102))`` is equal to ``__builtin_setrnd(2)``.
2402+
2403+
PowerPC Language Extensions
2404+
------------------------------
2405+
2406+
Set the Floating Point Rounding Mode
2407+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2408+
PowerPC64/PowerPC64le supports the builtin function ``__builtin_setrnd`` to set
2409+
the floating point rounding mode. This function will use the least significant
2410+
two bits of integer argument to set the floating point rounding mode.
2411+
2412+
.. code-block:: c++
2413+
2414+
double __builtin_setrnd(int mode);
2415+
2416+
The effective values for mode are:
2417+
2418+
- 0 - round to nearest
2419+
- 1 - round to zero
2420+
- 2 - round to +infinity
2421+
- 3 - round to -infinity
2422+
2423+
Note that the mode argument will modulo 4, so if the integer argument is greater
2424+
than 3, it will only use the least significant two bits of the mode.
2425+
Namely, ``__builtin_setrnd(102))`` is equal to ``__builtin_setrnd(2)``.
2426+
2427+
PowerPC Language Extensions
2428+
------------------------------
2429+
2430+
Set the Floating Point Rounding Mode
2431+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2432+
PowerPC64/PowerPC64le supports the builtin function ``__builtin_setrnd`` to set
2433+
the floating point rounding mode. This function will use the least significant
2434+
two bits of integer argument to set the floating point rounding mode.
2435+
2436+
.. code-block:: c++
2437+
2438+
double __builtin_setrnd(int mode);
2439+
2440+
The effective values for mode are:
2441+
2442+
- 0 - round to nearest
2443+
- 1 - round to zero
2444+
- 2 - round to +infinity
2445+
- 3 - round to -infinity
2446+
2447+
Note that the mode argument will modulo 4, so if the integer argument is greater
2448+
than 3, it will only use the least significant two bits of the mode.
2449+
Namely, ``__builtin_setrnd(102))`` is equal to ``__builtin_setrnd(2)``.
2450+
23792451
Extensions for Static Analysis
23802452
==============================
23812453

‎clang/include/clang/Basic/BuiltinsPPC.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ BUILTIN(__builtin_bpermd, "SLLiSLLiSLLi", "")
475475
BUILTIN(__builtin_unpack_vector_int128, "ULLiV1LLLii", "")
476476
BUILTIN(__builtin_pack_vector_int128, "V1LLLiULLiULLi", "")
477477

478+
// Set the floating point rounding mode
479+
BUILTIN(__builtin_setrnd, "di", "")
480+
478481
// FIXME: Obviously incomplete.
479482

480483
#undef BUILTIN

‎clang/test/CodeGen/builtins-ppc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,16 @@ long long test_builtin_ppc_get_timebase() {
1414
return __builtin_ppc_get_timebase();
1515
}
1616

17+
void test_builtin_ppc_setrnd() {
18+
volatile double res;
19+
volatile int x = 100;
20+
21+
// CHECK: call double @llvm.ppc.setrnd(i32 2)
22+
res = __builtin_setrnd(2);
23+
24+
// CHECK: call double @llvm.ppc.setrnd(i32 100)
25+
res = __builtin_setrnd(100);
26+
27+
// CHECK: call double @llvm.ppc.setrnd(i32 %2)
28+
res = __builtin_setrnd(x);
29+
}

0 commit comments

Comments
 (0)
Please sign in to comment.