• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <assert.h>
3 #include "opcodes.h"
4 
5 /* Test "load rounded" with universally available rounding modes.
6    Rounding mode is provided via FPC.
7    Also test "load lengthened" (which is independent of rounding modes). */
8 
9 volatile double d;
10 volatile float f;
11 
12 const char *
rtext(unsigned fpc_round)13 rtext(unsigned fpc_round)
14 {
15    switch (fpc_round) {
16    case 0: return "[-> near]";
17    case 1: return "[-> zero]";
18    case 2: return "[-> +inf]";
19    case 3: return "[-> -inf]";
20    }
21    assert(0);
22 }
23 
24 void
set_rounding_mode(unsigned mode)25 set_rounding_mode(unsigned mode)
26 {
27    printf("setting FPC rounding mode to %s\n", rtext(mode));
28    register unsigned r asm("1") = mode;
29    __asm__ volatile ( SFPC(1) : : "d"(r) );
30 }
31 
32 
33 void
load_rounded(void)34 load_rounded(void)
35 {
36    f = d;
37    printf("load rounded  d = %10.3f     f = %10.3f\n", d, f);
38 }
39 
40 void
load_lengthened(void)41 load_lengthened(void)
42 {
43    d = f;
44    printf("load lengthened  d = %22.20g    f = %22.20g\n", d, f);
45 }
46 
47 /* Tests for load rounded and load lengthened */
main()48 int main()
49 {
50    d = 12345678.25;
51    set_rounding_mode(0);
52    load_rounded();
53    set_rounding_mode(1);
54    load_rounded();
55    set_rounding_mode(2);
56    load_rounded();
57    set_rounding_mode(3);
58    load_rounded();
59    printf("======================================\n");
60    d = 12345678.75;
61    set_rounding_mode(0);
62    load_rounded();
63    set_rounding_mode(1);
64    load_rounded();
65    set_rounding_mode(2);
66    load_rounded();
67    set_rounding_mode(3);
68    load_rounded();
69    printf("======================================\n");
70    d = -12345678.25;
71    set_rounding_mode(0);
72    load_rounded();
73    set_rounding_mode(1);
74    load_rounded();
75    set_rounding_mode(2);
76    load_rounded();
77    set_rounding_mode(3);
78    load_rounded();
79    printf("======================================\n");
80    d = -12345678.75;
81    set_rounding_mode(0);
82    load_rounded();
83    set_rounding_mode(1);
84    load_rounded();
85    set_rounding_mode(2);
86    load_rounded();
87    set_rounding_mode(3);
88    load_rounded();
89    printf("\n");
90 
91    f = 1234.5678f;
92    load_lengthened();
93 
94    return 0;
95 }
96