(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
nios2/
custom-fp-conversion.c
       1  /* Test generation of conversion custom instructions.  */
       2  
       3  /* { dg-do compile } */
       4  /* { dg-options "-O1 -ffinite-math-only -funsafe-math-optimizations -fno-math-errno" } */
       5  
       6  /* -O1 in the options is significant.  Without it FP operations may not be
       7     optimized to custom instructions.  Also, -fno-math-errno is required
       8     to inline lroundf. */
       9  
      10  #include <stdio.h> 
      11  #include <math.h>
      12  
      13  #pragma GCC target ("custom-frdxhi=40")
      14  #pragma GCC target ("custom-frdxlo=41")
      15  #pragma GCC target ("custom-frdy=42")
      16  #pragma GCC target ("custom-fwrx=43")
      17  #pragma GCC target ("custom-fwry=44")
      18  
      19  #pragma GCC target ("custom-fextsd=100")
      20  #pragma GCC target ("custom-fixdi=101")
      21  #pragma GCC target ("custom-fixdu=102")
      22  #pragma GCC target ("custom-fixsi=103")
      23  #pragma GCC target ("custom-fixsu=104")
      24  #pragma GCC target ("custom-floatid=105")
      25  #pragma GCC target ("custom-floatis=106")
      26  #pragma GCC target ("custom-floatud=107")
      27  #pragma GCC target ("custom-floatus=108")
      28  #pragma GCC target ("custom-ftruncds=109")
      29  #pragma GCC target ("custom-round=110")
      30  
      31  
      32  typedef struct data {
      33    double fextsd;
      34    int fixdi;
      35    unsigned fixdu;
      36    int fixsi;
      37    unsigned fixsu;
      38    double floatid;
      39    float floatis;
      40    double floatud;
      41    float floatus;
      42    float ftruncds;
      43    int round;
      44  } data_t;
      45  
      46  void
      47  custom_fp (int i, unsigned u, float f, double d, data_t *out)
      48  {
      49    out->fextsd = (double) f;
      50    out->fixdi = (int) d;
      51    out->fixdu = (unsigned) d;
      52    out->fixsi = (int) f;
      53    out->fixsu = (unsigned) f;
      54    out->floatid = (double) i;
      55    out->floatis = (float) i;
      56    out->floatud = (double) u;
      57    out->floatus = (float) u;
      58    out->ftruncds = (float) d;
      59    out->round = lroundf (f);
      60  }
      61  
      62  /* { dg-final { scan-assembler "custom\\t100, .* # fextsd .*" } } */
      63  /* { dg-final { scan-assembler "custom\\t101, .* # fixdi .*" } } */
      64  /* { dg-final { scan-assembler "custom\\t102, .* # fixdu .*" } } */
      65  /* { dg-final { scan-assembler "custom\\t103, .* # fixsi .*" } } */
      66  /* { dg-final { scan-assembler "custom\\t104, .* # fixsu .*" } } */
      67  /* { dg-final { scan-assembler "custom\\t105, .* # floatid .*" } } */
      68  /* { dg-final { scan-assembler "custom\\t106, .* # floatis .*" } } */
      69  /* { dg-final { scan-assembler "custom\\t107, .* # floatud .*" } } */
      70  /* { dg-final { scan-assembler "custom\\t108, .* # floatus .*" } } */
      71  /* { dg-final { scan-assembler "custom\\t109, .* # ftruncds .*" } } */
      72  /* { dg-final { scan-assembler "custom\\t110, .* # round .*" } } */