| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <architecture/ppc/fp_regs.h> |
| 21 |
#include "gsl_ieee_utils.h" |
| 22 |
#include "gsl_errno.h" |
| 23 |
|
| 24 |
int |
| 25 |
gsl_ieee_set_mode (int precision, int rounding, int exception_mask) |
| 26 |
{ |
| 27 |
ppc_fp_scr_t fp_scr = get_fp_scr() ; |
| 28 |
|
| 29 |
switch (precision) |
| 30 |
{ |
| 31 |
case GSL_IEEE_SINGLE_PRECISION: |
| 32 |
GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP); |
| 33 |
break ; |
| 34 |
case GSL_IEEE_DOUBLE_PRECISION: |
| 35 |
GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP); |
| 36 |
break ; |
| 37 |
case GSL_IEEE_EXTENDED_PRECISION: |
| 38 |
GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP); |
| 39 |
break ; |
| 40 |
} |
| 41 |
|
| 42 |
switch (rounding) |
| 43 |
{ |
| 44 |
case GSL_IEEE_ROUND_TO_NEAREST: |
| 45 |
fp_scr.rn = RN_NEAREST ; |
| 46 |
break ; |
| 47 |
case GSL_IEEE_ROUND_DOWN: |
| 48 |
fp_scr.rn = RN_TOWARD_MINUS ; |
| 49 |
break ; |
| 50 |
case GSL_IEEE_ROUND_UP: |
| 51 |
fp_scr.rn = RN_TOWARD_PLUS ; |
| 52 |
break ; |
| 53 |
case GSL_IEEE_ROUND_TO_ZERO: |
| 54 |
fp_scr.rn = RN_TOWARD_ZERO ; |
| 55 |
break ; |
| 56 |
default: |
| 57 |
fp_scr.rn = RN_NEAREST ; |
| 58 |
} |
| 59 |
|
| 60 |
if (exception_mask & GSL_IEEE_MASK_INVALID) |
| 61 |
fp_scr.ve = 0 ; |
| 62 |
|
| 63 |
if (exception_mask & GSL_IEEE_MASK_DENORMALIZED) |
| 64 |
{ |
| 65 |
|
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
GSL_ERROR ("powerpc does not support the denormalized operand exception. " |
| 70 |
"Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ; |
| 71 |
} |
| 72 |
|
| 73 |
if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO) |
| 74 |
fp_scr.ze = 0 ; |
| 75 |
|
| 76 |
if (exception_mask & GSL_IEEE_MASK_OVERFLOW) |
| 77 |
fp_scr.oe = 0 ; |
| 78 |
|
| 79 |
if (exception_mask & GSL_IEEE_MASK_UNDERFLOW) |
| 80 |
fp_scr.ue = 0 ; |
| 81 |
|
| 82 |
if (exception_mask & GSL_IEEE_TRAP_INEXACT) |
| 83 |
{ |
| 84 |
fp_scr.xe = 1 ; |
| 85 |
} |
| 86 |
else |
| 87 |
{ |
| 88 |
fp_scr.xe = 01 ; |
| 89 |
} |
| 90 |
|
| 91 |
set_fp_scr(fp_scr); |
| 92 |
|
| 93 |
return GSL_SUCCESS ; |
| 94 |
|
| 95 |
} |