Home | History | Annotate | Download | only in s390x
      1 #include <assert.h>
      2 #include <stdlib.h>
      3 #include <stdio.h>
      4 #include "opcodes.h"
      5 
      6 /* Basic test that we can set the rounding mode in the FPC and
      7    query it. Covers only generally available rounding modes. */
      8 
      9 void
     10 set_rounding_mode(unsigned mode)
     11 {
     12    register unsigned r asm("1") = mode;
     13    __asm__ volatile ( SFPC(1) : : "d"(r) );
     14 }
     15 
     16 unsigned
     17 get_rounding_mode(void)
     18 {
     19    unsigned fpc;
     20 
     21    __asm__ volatile ("stfpc  %0\n\t" : "=m"(fpc));
     22 
     23    return fpc & 0x7;
     24 }
     25 
     26 
     27 int main(void)
     28 {
     29    int i;
     30    const unsigned rmodes[] = { 0, 1, 2, 3 };
     31 
     32    printf("initial rounding mode: %u\n", get_rounding_mode());
     33 
     34    for (i = 0; i < sizeof rmodes / sizeof rmodes[0]; ++i) {
     35       printf("setting rounding mode to %u\n", rmodes[i]);
     36       set_rounding_mode(rmodes[i]);
     37       printf("...checking: %u\n", get_rounding_mode());
     38    }
     39 
     40    return 0;
     41 }
     42