Advertisement
Guest User

t125_results_ubuntu_20.04

a guest
Apr 1st, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.43 KB | None | 0 0
  1. ```
  2. /*
  3. * Sample code (t125.c) (added checking of __STDC__ and __STDC_IEC_559__)
  4. */
  5. #include <fenv.h>
  6. #include <stdio.h>
  7. #include <math.h>
  8. #include <stdint.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11.  
  12. #if _MSC_VER && ! __clang__
  13. #pragma fenv_access (on)
  14. #else
  15. #pragma STDC FENV_ACCESS ON
  16. #endif
  17.  
  18. void show_fe_exceptions(void)
  19. {
  20. printf("exceptions raised:");
  21. if (fetestexcept(FE_DIVBYZERO)) printf(" FE_DIVBYZERO");
  22. if (fetestexcept(FE_INEXACT)) printf(" FE_INEXACT");
  23. if (fetestexcept(FE_INVALID)) printf(" FE_INVALID");
  24. if (fetestexcept(FE_OVERFLOW)) printf(" FE_OVERFLOW");
  25. if (fetestexcept(FE_UNDERFLOW)) printf(" FE_UNDERFLOW");
  26. if (fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
  27. printf("\n");
  28. }
  29.  
  30. /* based on https://github.com/google/flatbuffers/blob/4133a39df80546ff5269894a3961c7069fcd45d0/tests/test.cpp#L693 */
  31. #if TID == 32
  32. _Bool is_quiet_nan(float v)
  33. #elif TID == 64
  34. _Bool is_quiet_nan(double v)
  35. #else
  36. #error "unknown TID"
  37. #endif
  38. {
  39. #if TID == 32
  40. uint32_t qnan_base = 0x7FC00000u;
  41. uint32_t u;
  42. #elif TID == 64
  43. uint64_t qnan_base = 0x7FF8000000000000ul;
  44. uint64_t u;
  45. #else
  46. #error "unknown TID"
  47. #endif
  48. _Static_assert(sizeof(v) == sizeof(u), "unexpected");
  49. memcpy(&u, &v, sizeof(v));
  50. return ((u & qnan_base) == qnan_base);
  51. }
  52.  
  53. #if TID == 32
  54. float xfma(float x, float y, float z) { return fmaf(x, y, z); }
  55. float xsqrt(float x) { return sqrtf(x); }
  56. #elif TID == 64
  57. double xfma(double x, double y, double z) { return fma(x, y, z); }
  58. double xsqrt(double x) { return sqrt(x); }
  59. #else
  60. #error "unknown TID"
  61. #endif
  62.  
  63. int main(void)
  64. {
  65. volatile _Bool b;
  66. #if TID == 32
  67. QUAL float f = NAN;
  68. #elif TID == 64
  69. QUAL double f = NAN;
  70. #else
  71. #error "unknown TID"
  72. #endif
  73. #ifndef __STDC__
  74. printf("Does not ID itself as compliant to any C standard, exiting\n");
  75. exit(1);
  76. #elif __STDC__ == 1
  77. printf("Compliant to some C standard\n");
  78. #ifndef __STDC_VERSION__
  79. printf("C 1989\n");
  80. #else
  81. printf("C %ld\n", __STDC_VERSION__);
  82. #endif
  83. #endif
  84. #if __STDC_IEC_559__ == 1
  85. printf("Has IEC 60559 conformance\n");
  86. #else
  87. printf("Has no IEC 60559 conformance OR has IEC 60559 conformance but __STDC_IEC_559__ is not defined to 1\n");
  88. printf("Conclude that non-IEEE 754 conformant results may be produced, exiting\n");
  89. exit(1);
  90. #endif
  91. printf("f is %f\n", f);
  92. printf("f is quiet nan %d\n", is_quiet_nan(f));
  93. printf("NAN is quiet nan %d\n", is_quiet_nan(NAN));
  94.  
  95. #define TEST(expr) \
  96. printf("%-25s => ", #expr); \
  97. feclearexcept(FE_ALL_EXCEPT); \
  98. b = (expr) != 0; \
  99. show_fe_exceptions();
  100.  
  101. printf("\n");
  102. printf("C11, 5.2.4.2.2, p3:\n");
  103. printf("> A quiet NaN propagates through almost every arithmetic\n");
  104. printf("> operation without raising a floating-point exception; ...\n");
  105. TEST(f + f);
  106. TEST(f - f);
  107. TEST(f * f);
  108. TEST(f / f);
  109. TEST(xsqrt(f));
  110. TEST(xfma(f, f, f));
  111.  
  112. TEST(NAN + NAN);
  113. TEST(NAN - NAN);
  114. TEST(NAN * NAN);
  115. TEST(NAN / NAN);
  116. TEST(xsqrt(NAN));
  117. TEST(xfma(NAN, NAN, NAN));
  118.  
  119. printf("\n");
  120. printf("IEEE 754, 5.11, p4:\n");
  121. printf("> Programs that explicitly take account of the possibility of\n");
  122. printf("> quiet NaN operands may use the unordered-quiet predicates in\n");
  123. printf("> Table 5.3 which do not signal such an invalid operation exception.\n");
  124. TEST(f == f);
  125. TEST(f != f);
  126. TEST(f >= f);
  127. TEST(f <= f);
  128. TEST(f > f);
  129. TEST(f < f);
  130.  
  131. TEST(NAN == NAN);
  132. TEST(NAN != NAN);
  133. TEST(NAN >= NAN);
  134. TEST(NAN <= NAN);
  135. TEST(NAN > NAN);
  136. TEST(NAN < NAN);
  137.  
  138. return b ? 1 : 0;
  139. }
  140. ```
  141.  
  142. Invocations (attention: many results):
  143. ```
  144. # clang
  145. # const float (baseline)
  146. $ clang t125.c -lm -std=c11 -ffp-model=strict -Wall -Wextra -pedantic -DQUAL=const -O3 -DTID=32 && ./a.out
  147. t125.c:11:14: warning: pragma STDC FENV_ACCESS ON is not supported, ignoring pragma [-Wunknown-pragmas]
  148. #pragma STDC FENV_ACCESS ON
  149. ^
  150. 1 warning generated.
  151. Compliant to some C standard
  152. C 201112
  153. Has IEC 60559 conformance
  154. f is nan
  155. f is quiet nan 1
  156. NAN is quiet nan 1
  157.  
  158. C11, 5.2.4.2.2, p3:
  159. > A quiet NaN propagates through almost every arithmetic
  160. > operation without raising a floating-point exception; ...
  161. f + f => exceptions raised: none
  162. f - f => exceptions raised: none
  163. f * f => exceptions raised: none
  164. f / f => exceptions raised: none
  165. xsqrt(f) => exceptions raised: none
  166. xfma(f, f, f) => exceptions raised: none
  167. NAN + NAN => exceptions raised: none
  168. NAN - NAN => exceptions raised: none
  169. NAN * NAN => exceptions raised: none
  170. NAN / NAN => exceptions raised: none
  171. xsqrt(NAN) => exceptions raised: none
  172. xfma(NAN, NAN, NAN) => exceptions raised: none
  173.  
  174. IEEE 754, 5.11, p4:
  175. > Programs that explicitly take account of the possibility of
  176. > quiet NaN operands may use the unordered-quiet predicates in
  177. > Table 5.3 which do not signal such an invalid operation exception.
  178. f == f => exceptions raised: none
  179. f != f => exceptions raised: none
  180. f >= f => exceptions raised: FE_INVALID
  181. f <= f => exceptions raised: FE_INVALID
  182. f > f => exceptions raised: FE_INVALID
  183. f < f => exceptions raised: FE_INVALID
  184. NAN == NAN => exceptions raised: none
  185. NAN != NAN => exceptions raised: none
  186. NAN >= NAN => exceptions raised: FE_INVALID
  187. NAN <= NAN => exceptions raised: FE_INVALID
  188. NAN > NAN => exceptions raised: FE_INVALID
  189. NAN < NAN => exceptions raised: FE_INVALID
  190.  
  191. $ get_cmd() { cmd="clang t125.c -lm -std=c11 -ffp-model=strict -Wall -Wextra -pedantic \
  192. -O3 -Wfatal-errors -DQUAL=$QUAL1 -DTID=$TID1 && ./a.out > out1 && clang t125.c -lm \
  193. -std=c11 -ffp-model=strict -Wall -Wextra -pedantic -O3 -Wfatal-errors -DQUAL=$QUAL2 \
  194. -DTID=$TID2 && ./a.out > out2 && diff out1 out2" ; }
  195.  
  196. # note: below we do not count `warning: pragma STDC FENV_ACCESS ON is not supported`
  197.  
  198. # const float vs const double
  199. $ QUAL1=const TID1=32 QUAL2=const TID2=64 get_cmd ; eval $cmd
  200. <nothing>
  201.  
  202. # const float vs volatile float
  203. $ QUAL1=const TID1=32 QUAL2=volatile TID2=32 get_cmd ; eval $cmd
  204. <nothing>
  205.  
  206. # const float vs volatile double
  207. $ QUAL1=const TID1=32 QUAL2=volatile TID2=64 get_cmd ; eval $cmd
  208. <nothing>
  209.  
  210. # const double vs volatile float
  211. $ QUAL1=const TID1=64 QUAL2=volatile TID2=32 get_cmd ; eval $cmd
  212. <nothing>
  213.  
  214. # const double vs volatile double
  215. $ QUAL1=const TID1=64 QUAL2=volatile TID2=64 get_cmd ; eval $cmd
  216. <nothing>
  217.  
  218. # volatile float vs volatile double
  219. $ QUAL1=volatile TID1=32 QUAL2=volatile TID2=64 get_cmd ; eval $cmd
  220. <nothing>
  221.  
  222. # gcc
  223. # const float (baseline)
  224. $ gcc t125.c -lm -std=c11 -frounding-math -fsignaling-nans -Wall -Wextra -pedantic -O3 -DQUAL=const -DTID=32 && ./a.out
  225. t125.c:11: warning: ignoring ‘#pragma STDC FENV_ACCESS’ [-Wunknown-pragmas]
  226. 11 | #pragma STDC FENV_ACCESS ON
  227. |
  228. Compliant to some C standard
  229. C 201112
  230. Has IEC 60559 conformance
  231. f is nan
  232. f is quiet nan 1
  233. NAN is quiet nan 1
  234.  
  235. C11, 5.2.4.2.2, p3:
  236. > A quiet NaN propagates through almost every arithmetic
  237. > operation without raising a floating-point exception; ...
  238. f + f => exceptions raised: none
  239. f - f => exceptions raised: none
  240. f * f => exceptions raised: none
  241. f / f => exceptions raised: none
  242. xsqrt(f) => exceptions raised: none
  243. xfma(f, f, f) => exceptions raised: none
  244. NAN + NAN => exceptions raised: none
  245. NAN - NAN => exceptions raised: none
  246. NAN * NAN => exceptions raised: none
  247. NAN / NAN => exceptions raised: none
  248. xsqrt(NAN) => exceptions raised: none
  249. xfma(NAN, NAN, NAN) => exceptions raised: none
  250.  
  251. IEEE 754, 5.11, p4:
  252. > Programs that explicitly take account of the possibility of
  253. > quiet NaN operands may use the unordered-quiet predicates in
  254. > Table 5.3 which do not signal such an invalid operation exception.
  255. f == f => exceptions raised: none
  256. f != f => exceptions raised: none
  257. f >= f => exceptions raised: none
  258. f <= f => exceptions raised: none
  259. f > f => exceptions raised: none
  260. f < f => exceptions raised: none
  261. NAN == NAN => exceptions raised: none
  262. NAN != NAN => exceptions raised: none
  263. NAN >= NAN => exceptions raised: none
  264. NAN <= NAN => exceptions raised: none
  265. NAN > NAN => exceptions raised: none
  266. NAN < NAN => exceptions raised: none
  267.  
  268. $ get_cmd() { cmd="gcc t125.c -lm -std=c11 -frounding-math -fsignaling-nans -Wall -Wextra -pedantic -O3 -DQUAL=$QUAL1 \
  269. -DTID=$TID1 && ./a.out > out1 && gcc t125.c -lm -std=c11 -frounding-math -fsignaling-nans -Wall -Wextra -pedantic -O3 \
  270. -DQUAL=$QUAL2 -DTID=$TID2 && ./a.out > out2 && diff out1 out2" ; }
  271.  
  272. # note: below we do not count `warning: pragma STDC FENV_ACCESS ON is not supported`
  273.  
  274. # const float vs const double
  275. $ QUAL1=const TID1=32 QUAL2=const TID2=64 get_cmd ; eval $cmd
  276. <nothing>
  277.  
  278. # const float vs volatile float
  279. $ QUAL1=const TID1=32 QUAL2=volatile TID2=32 get_cmd ; eval $cmd
  280. 30,33c30,33
  281. < f >= f => exceptions raised: none
  282. < f <= f => exceptions raised: none
  283. < f > f => exceptions raised: none
  284. < f < f => exceptions raised: none
  285. ---
  286. > f >= f => exceptions raised: FE_INVALID
  287. > f <= f => exceptions raised: FE_INVALID
  288. > f > f => exceptions raised: FE_INVALID
  289. > f < f => exceptions raised: FE_INVALID
  290.  
  291. # const float vs volatile double
  292. $ QUAL1=const TID1=32 QUAL2=volatile TID2=64 get_cmd ; eval $cmd
  293. 30,33c30,33
  294. < f >= f => exceptions raised: none
  295. < f <= f => exceptions raised: none
  296. < f > f => exceptions raised: none
  297. < f < f => exceptions raised: none
  298. ---
  299. > f >= f => exceptions raised: FE_INVALID
  300. > f <= f => exceptions raised: FE_INVALID
  301. > f > f => exceptions raised: FE_INVALID
  302. > f < f => exceptions raised: FE_INVALID
  303.  
  304. # const double vs volatile float
  305. $ QUAL1=const TID1=64 QUAL2=volatile TID2=32 get_cmd ; eval $cmd
  306. 30,33c30,33
  307. < f >= f => exceptions raised: none
  308. < f <= f => exceptions raised: none
  309. < f > f => exceptions raised: none
  310. < f < f => exceptions raised: none
  311. ---
  312. > f >= f => exceptions raised: FE_INVALID
  313. > f <= f => exceptions raised: FE_INVALID
  314. > f > f => exceptions raised: FE_INVALID
  315. > f < f => exceptions raised: FE_INVALID
  316.  
  317. # const double vs volatile double
  318. $ QUAL1=const TID1=64 QUAL2=volatile TID2=64 get_cmd ; eval $cmd
  319. 30,33c30,33
  320. < f >= f => exceptions raised: none
  321. < f <= f => exceptions raised: none
  322. < f > f => exceptions raised: none
  323. < f < f => exceptions raised: none
  324. ---
  325. > f >= f => exceptions raised: FE_INVALID
  326. > f <= f => exceptions raised: FE_INVALID
  327. > f > f => exceptions raised: FE_INVALID
  328. > f < f => exceptions raised: FE_INVALID
  329.  
  330. # volatile float vs volatile double
  331. $ QUAL1=volatile TID1=32 QUAL2=volatile TID2=64 get_cmd ; eval $cmd
  332. <nothing>
  333.  
  334. # cl
  335. # not on ubuntu
  336.  
  337. dev0@dev0-VirtualBox:~/dev$ gcc --version
  338. gcc (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
  339. Copyright (C) 2020 Free Software Foundation, Inc.
  340. This is free software; see the source for copying conditions. There is NO
  341. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  342.  
  343. dev0@dev0-VirtualBox:~/dev$ clang --version
  344. Ubuntu clang version 11.0.0-2~ubuntu20.04.1
  345. Target: x86_64-pc-linux-gnu
  346. Thread model: posix
  347. InstalledDir: /usr/bin
  348.  
  349. $ cl
  350. # not on ubuntu
  351. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement