1#include <assert.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include "opcodes.h"
5
6#define srnmt(b,d) \
7   ({ \
8      __asm__ volatile ( "lghi 8," #b "\n\t" \
9                         SRNMT(8,d) \
10                         ::: "8"); \
11   })
12
13
14/* Like srnmt above, except it uses r0 as a base register */
15#define srnmt0(d) \
16   ({ \
17      __asm__ volatile ( SRNMT(0,d) \
18                         ::: "0"); \
19   })
20
21unsigned
22get_dfp_rounding_mode(void)
23{
24   unsigned fpc;
25
26   __asm__ volatile ("stfpc  %0\n\t" : "=m"(fpc));
27
28   return (fpc & 0x70) >> 4;
29}
30
31int main(void)
32{
33   printf("initial rounding mode = %u\n", get_dfp_rounding_mode());
34
35   /* Set basic rounding modes in various ways */
36   srnmt(1,002);  // 1 + 2 = 3
37   printf("rounding mode = %u\n", get_dfp_rounding_mode());
38
39   srnmt(2,000);
40   printf("rounding mode = %u\n", get_dfp_rounding_mode());
41
42   srnmt(0,001);
43   printf("rounding mode = %u\n", get_dfp_rounding_mode());
44
45   srnmt(0,000);
46   printf("rounding mode = %u\n", get_dfp_rounding_mode());
47
48   srnmt(7,000);
49   printf("rounding mode = %u\n", get_dfp_rounding_mode());
50
51   srnmt(0,006);
52   printf("rounding mode = %u\n", get_dfp_rounding_mode());
53
54   srnmt0(005);
55   printf("rounding mode = %u\n", get_dfp_rounding_mode());
56
57   srnmt0(004);
58   printf("rounding mode = %u\n", get_dfp_rounding_mode());
59
60   return 0;
61}
62