File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed
regression/cbmc/Float-Rounding3 Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ // This is C99, but currently only works with clang.
2+ // gcc and Visual Studio appear to hard-wire FLT_ROUNDS to 1.
3+
4+ #ifdef __clang__
5+
6+ #include <assert.h>
7+ #include <fenv.h>
8+ #include <float.h>
9+
10+ int main ()
11+ {
12+ fesetround (FE_DOWNWARD );
13+ assert (FLT_ROUNDS == 3 );
14+
15+ fesetround (FE_TONEAREST );
16+ assert (FLT_ROUNDS == 1 );
17+
18+ fesetround (FE_TOWARDZERO );
19+ assert (FLT_ROUNDS == 0 );
20+
21+ fesetround (FE_UPWARD );
22+ assert (FLT_ROUNDS == 2 );
23+ }
24+
25+ #else
26+
27+ int main ()
28+ {
29+ }
30+
31+ #endif
Original file line number Diff line number Diff line change 1+ CORE
2+ main.c
3+
4+ ^EXIT=0$
5+ ^SIGNAL=0$
6+ ^VERIFICATION SUCCESSFUL$
7+ --
8+ ^warning: ignoring
Original file line number Diff line number Diff line change 11typedef float __gcc_v4sf __attribute__ ((__vector_size__ (16 )));
22
33__gcc_v4sf __builtin_shufflevector (__gcc_v4sf , __gcc_v4sf , ...);
4+
5+ int __builtin_flt_rounds (void );
Original file line number Diff line number Diff line change @@ -67,3 +67,19 @@ inline int _isnan(double x)
6767{
6868 return __CPROVER_isnand (x );
6969}
70+
71+ /* FUNCTION: __builtin_flt_rounds */
72+
73+ extern int __CPROVER_rounding_mode ;
74+
75+ inline int __builtin_flt_rounds (void )
76+ {
77+ // This is a clang builtin for FLT_ROUNDS
78+ // The magic numbers are C99 and different from the
79+ // x86 encoding that CPROVER uses.
80+ return __CPROVER_rounding_mode == 0 ?1 : // to nearest
81+ __CPROVER_rounding_mode == 1 ?3 : // downward
82+ __CPROVER_rounding_mode == 2 ?2 : // upward
83+ __CPROVER_rounding_mode == 3 ?0 : // to zero
84+ -1 ;
85+ }
You can’t perform that action at this time.
0 commit comments