1 #include <assert.h> 2 #include <stdlib.h> 3 #include <stdio.h> 4 #include "opcodes.h" 5 6 #define srnm(b,d) \ 7 ({ \ 8 __asm__ volatile ( "lghi 8," #b "\n\t" \ 9 "srnm " #d "(8)\n\t" ::: "8"); \ 10 }) 11 12 unsigned 13 get_rounding_mode(void) 14 { 15 unsigned fpc; 16 17 __asm__ volatile ("stfpc %0\n\t" : "=m"(fpc)); 18 19 return fpc & 0x7; 20 } 21 22 int main(void) 23 { 24 printf("initial rounding mode = %u\n", get_rounding_mode()); 25 26 /* Set basic rounding modes in various ways */ 27 srnm(1,2); // 1 + 2 = 3 28 printf("rounding mode = %u\n", get_rounding_mode()); 29 30 srnm(2,0); 31 printf("rounding mode = %u\n", get_rounding_mode()); 32 33 srnm(0,1); 34 printf("rounding mode = %u\n", get_rounding_mode()); 35 36 srnm(0,0); 37 printf("rounding mode = %u\n", get_rounding_mode()); 38 39 /* Some rounding modes with bits to be ignored */ 40 srnm(0xff,0); // -> 3 41 printf("rounding mode = %u\n", get_rounding_mode()); 42 43 srnm(0,0xfe); // -> 2 44 printf("rounding mode = %u\n", get_rounding_mode()); 45 46 srnm(0xf0,0x0f); // -> 3 47 printf("rounding mode = %u\n", get_rounding_mode()); 48 49 return 0; 50 } 51