aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/or1k/fpu/fraiseexcpt.c
blob: bbacfd50bc9490566c2b1c89439555aa16a07669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Raise given exceptions.  OpenRISC version.
   Copyright (C) 2024 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library.  If not, see
   <https://www.gnu.org/licenses/>.  */

#include <fenv.h>
#include <fpu_control.h>
#include <float.h>
#include <math.h>

int
__feraiseexcept (int excepts)
{
  if (excepts == 0)
    return 0;

  /* Raise exceptions represented by EXPECTS.  */

  if (excepts & FE_INEXACT)
  {
    float d = 1.0, x = 3.0;
    __asm__ volatile ("lf.div.s %0, %0, %1" : "+r" (d) : "r" (x));
  }

  if (excepts & FE_UNDERFLOW)
  {
    float d = FLT_MIN;
    __asm__ volatile ("lf.mul.s %0, %0, %0" : "+r" (d));
  }

  if (excepts & FE_OVERFLOW)
  {
    float d = FLT_MAX;
    __asm__ volatile ("lf.mul.s %0, %0, %0" : "+r" (d) : "r" (d));
  }

  if (excepts & FE_DIVBYZERO)
  {
    float d = 1.0, x = 0.0;
    __asm__ volatile ("lf.div.s %0, %0, %1" : "+r" (d) : "r" (x));
  }

  if (excepts & FE_INVALID)
  {
    float d = HUGE_VAL, x = 0.0;
    __asm__ volatile ("lf.mul.s %0, %1, %0" : "+r" (d) : "r" (x));
  }

  /* Success.  */
  return 0;
}
libm_hidden_def (__feraiseexcept)
weak_alias (__feraiseexcept, feraiseexcept)
libm_hidden_weak (feraiseexcept)