| 1 |
// floating point operations |
| 2 |
// Copyright (C) 2005-2020 Red Hat Inc. |
| 3 |
// |
| 4 |
// This file is part of systemtap, and is free software. You can |
| 5 |
// redistribute it and/or modify it under the terms of the GNU General |
| 6 |
// Public License (GPL); either version 2, or (at your option) any |
| 7 |
// later version. |
| 8 |
|
| 9 |
%{ |
| 10 |
#include "softfloat.c" |
| 11 |
%} |
| 12 |
|
| 13 |
/** |
| 14 |
* sfunction fp_to_string - Convert 64 bit floating point to string |
| 15 |
* |
| 16 |
* @infp: the 64 bit floating point stored in long |
| 17 |
* |
| 18 |
* @precision: number of digits after decimal point |
| 19 |
* |
| 20 |
* Description: Given a 64 bit floating point, which is stored in long, |
| 21 |
* use the long value to initiate self-defined float64_t type, then |
| 22 |
* apply the f64_to_i64 function to get the string representation. |
| 23 |
*/ |
| 24 |
function fp_to_string:string (infp:long, precision:long) |
| 25 |
%{ |
| 26 |
float64_t fp; |
| 27 |
fp.v = (unsigned long) STAP_ARG_infp; |
| 28 |
f64_to_str(STAP_RETVALUE, MAXSTRINGLEN, fp, STAP_ARG_precision); |
| 29 |
%} |
| 30 |
|
| 31 |
/** |
| 32 |
* sfunction string_to_fp - Convert the given string into floating point |
| 33 |
* |
| 34 |
* @input: the string representation of a decimal number |
| 35 |
* |
| 36 |
* Description: Given the string representation of a decimal number, convert |
| 37 |
* it to a floating point which is stored in 64 bit long. |
| 38 |
*/ |
| 39 |
function string_to_fp:long (input:string) |
| 40 |
%{ |
| 41 |
float64_t fp; |
| 42 |
fp = str_to_f64(STAP_ARG_input); |
| 43 |
if (fp.v == defaultNaNF64UI) |
| 44 |
STAP_ERROR ("invalid format"); |
| 45 |
else |
| 46 |
STAP_RETVALUE = fp.v; |
| 47 |
%} |
| 48 |
|
| 49 |
/** |
| 50 |
* sfunction long_to_fp - Convert long int to 64 bit floating point |
| 51 |
* |
| 52 |
* @input: a long integer |
| 53 |
* |
| 54 |
* Description: Convert from a long to a 64 bit softfloat floating point. |
| 55 |
*/ |
| 56 |
function long_to_fp:long (input:long) |
| 57 |
%{ |
| 58 |
float64_t fp; |
| 59 |
|
| 60 |
fp = i64_to_f64(STAP_ARG_input); |
| 61 |
STAP_RETVALUE = fp.v; |
| 62 |
%} |
| 63 |
|
| 64 |
/** |
| 65 |
* sfunction fp_to_long - Convert fp to int64 |
| 66 |
* |
| 67 |
* @infp: the 64 bit floating point stored in long |
| 68 |
* @roundingMode: through 0-6, which are round to nearest even, minMag, |
| 69 |
* min, max, near maxMag and round to odd |
| 70 |
* @exact: the boolean value, if exact is 1 than raising inexact |
| 71 |
* exception, otherwise ignore the exception. |
| 72 |
* |
| 73 |
* Description: Given a 64 bit floating point, which is stored in long, |
| 74 |
* use the long value to initiate self-defined float64_t type, then |
| 75 |
* apply the f64_to_i64 function to get the string representation. |
| 76 |
*/ |
| 77 |
function fp_to_long:long (infp:long, roundingMode:long, exact:long) |
| 78 |
%{ |
| 79 |
float64_t fp; |
| 80 |
fp.v = (unsigned long) STAP_ARG_infp; |
| 81 |
|
| 82 |
STAP_RETVALUE = |
| 83 |
(long) f64_to_i64( |
| 84 |
fp, |
| 85 |
(uint_fast8_t)STAP_ARG_roundingMode, |
| 86 |
(bool)STAP_ARG_exact); |
| 87 |
%} |
| 88 |
|
| 89 |
/** |
| 90 |
* sfunction fp_add - Addition between floating points |
| 91 |
* |
| 92 |
* @add1: the 64 bit floating point addend |
| 93 |
* @add2: second 64 bit floating point addend |
| 94 |
* |
| 95 |
* Description: Given addend 1 and addend 2, apply floating point adding |
| 96 |
*/ |
| 97 |
function fp_add:long (add1:long, add2:long) |
| 98 |
%{ |
| 99 |
float64_t fp1; |
| 100 |
float64_t fp2; |
| 101 |
float64_t result; |
| 102 |
|
| 103 |
fp1.v = (unsigned long) STAP_ARG_add1; |
| 104 |
fp2.v = (unsigned long) STAP_ARG_add2; |
| 105 |
|
| 106 |
result = f64_add(fp1, fp2); |
| 107 |
STAP_RETVALUE = result.v; |
| 108 |
%} |
| 109 |
|
| 110 |
/** |
| 111 |
* sfunction fp_sub - Subtraction between floating points |
| 112 |
* |
| 113 |
* @sub1: the 64 bit floating point minuend |
| 114 |
* @sub2: 64 bit floating point subtrahend |
| 115 |
* |
| 116 |
* Description: result would be minuend minus subtrahend |
| 117 |
*/ |
| 118 |
function fp_sub:long (sub1:long, sub2:long) |
| 119 |
%{ |
| 120 |
float64_t fp1; |
| 121 |
float64_t fp2; |
| 122 |
float64_t result; |
| 123 |
|
| 124 |
fp1.v = (unsigned long) STAP_ARG_sub1; |
| 125 |
fp2.v = (unsigned long) STAP_ARG_sub2; |
| 126 |
|
| 127 |
result = f64_sub(fp1, fp2); |
| 128 |
STAP_RETVALUE = result.v; |
| 129 |
%} |
| 130 |
|
| 131 |
/** |
| 132 |
* sfunction fp_mul - Multiplication between floating points |
| 133 |
* |
| 134 |
* @mul1: the 64 bit floating point multiplicand |
| 135 |
* @mul2: 64 bit floating point multiplier |
| 136 |
* |
| 137 |
* Description: result is multiplicand times multiplier |
| 138 |
*/ |
| 139 |
function fp_mul:long (mul1:long, mul2:long) |
| 140 |
%{ |
| 141 |
float64_t fp1; |
| 142 |
float64_t fp2; |
| 143 |
float64_t result; |
| 144 |
|
| 145 |
fp1.v = (unsigned long) STAP_ARG_mul1; |
| 146 |
fp2.v = (unsigned long) STAP_ARG_mul2; |
| 147 |
|
| 148 |
result = f64_mul(fp1, fp2); |
| 149 |
STAP_RETVALUE = result.v; |
| 150 |
%} |
| 151 |
|
| 152 |
/* |
| 153 |
* sfunction fp_div - fp divide |
| 154 |
* |
| 155 |
* @div1: the 64 bit floating point dividend |
| 156 |
* @div2: 64 bit floating point divisor |
| 157 |
* |
| 158 |
* Description: result would be divisor divides dividend |
| 159 |
*/ |
| 160 |
function fp_div:long (div1:long, div2:long) |
| 161 |
%{ |
| 162 |
float64_t fp1; |
| 163 |
float64_t fp2; |
| 164 |
float64_t result; |
| 165 |
|
| 166 |
fp1.v = (unsigned long) STAP_ARG_div1; |
| 167 |
fp2.v = (unsigned long) STAP_ARG_div2; |
| 168 |
|
| 169 |
result = f64_div(fp1, fp2); |
| 170 |
STAP_RETVALUE = result.v; |
| 171 |
%} |
| 172 |
|
| 173 |
/** |
| 174 |
* sfunction fp_rem - Floating point division |
| 175 |
* |
| 176 |
* @div1: the 64 bit floating point dividend |
| 177 |
* @div2: 64 bit floating point divisor |
| 178 |
* |
| 179 |
* Description: result would be the remainder after divisor divides dividend |
| 180 |
*/ |
| 181 |
function fp_rem:long (div1:long, div2:long) |
| 182 |
%{ |
| 183 |
float64_t fp1; |
| 184 |
float64_t fp2; |
| 185 |
float64_t result; |
| 186 |
|
| 187 |
fp1.v = (unsigned long) STAP_ARG_div1; |
| 188 |
fp2.v = (unsigned long) STAP_ARG_div2; |
| 189 |
|
| 190 |
result = f64_rem(fp1, fp2); |
| 191 |
STAP_RETVALUE = result.v; |
| 192 |
%} |
| 193 |
|
| 194 |
/** |
| 195 |
* sfunction fp_sqrt - Floating point square root |
| 196 |
* |
| 197 |
* @infp: the 64 bit floating point input |
| 198 |
* |
| 199 |
* Description: apply sqrt to input floating point |
| 200 |
*/ |
| 201 |
function fp_sqrt:long (infp:long) |
| 202 |
%{ |
| 203 |
float64_t fp; |
| 204 |
float64_t result; |
| 205 |
|
| 206 |
fp.v = (unsigned long) STAP_ARG_infp; |
| 207 |
|
| 208 |
result = f64_sqrt(fp); |
| 209 |
STAP_RETVALUE = result.v; |
| 210 |
%} |
| 211 |
|
| 212 |
/** |
| 213 |
* sfunction fp_eq - fp comparison function equal |
| 214 |
* |
| 215 |
* @infp1: the 64 bit floating point input |
| 216 |
* @infp2: second 64 bit floating point input |
| 217 |
* |
| 218 |
* Description: check if infp1 is equal to infp2 |
| 219 |
*/ |
| 220 |
function fp_eq:long (infp1:long, infp2:long) |
| 221 |
%{ |
| 222 |
float64_t fp1; |
| 223 |
float64_t fp2; |
| 224 |
|
| 225 |
fp1.v = (unsigned long) STAP_ARG_infp1; |
| 226 |
fp2.v = (unsigned long) STAP_ARG_infp2; |
| 227 |
|
| 228 |
STAP_RETVALUE = f64_eq(fp1, fp2); |
| 229 |
%} |
| 230 |
|
| 231 |
/** |
| 232 |
* sfunction fp_le - Check if first fp is less than or equal to |
| 233 |
* |
| 234 |
* @infp1: the 64 bit floating point input |
| 235 |
* @infp2: second 64 bit floating point input |
| 236 |
* |
| 237 |
* Description: check if infp1 is less than or equal to infp2 |
| 238 |
*/ |
| 239 |
function fp_le:long (infp1:long, infp2:long) |
| 240 |
%{ |
| 241 |
float64_t fp1; |
| 242 |
float64_t fp2; |
| 243 |
|
| 244 |
fp1.v = (unsigned long) STAP_ARG_infp1; |
| 245 |
fp2.v = (unsigned long) STAP_ARG_infp2; |
| 246 |
|
| 247 |
STAP_RETVALUE = f64_le(fp1, fp2); |
| 248 |
%} |
| 249 |
|
| 250 |
/** |
| 251 |
* sfunction fp_lt - fp comparison function less than |
| 252 |
* |
| 253 |
* @infp1: the 64 bit floating point input |
| 254 |
* @infp2: second 64 bit floating point input |
| 255 |
* |
| 256 |
* Description: check if infp1 is strictly less than infp2 |
| 257 |
*/ |
| 258 |
function fp_lt:long (infp1:long, infp2:long) |
| 259 |
%{ |
| 260 |
float64_t fp1; |
| 261 |
float64_t fp2; |
| 262 |
|
| 263 |
fp1.v = (unsigned long) STAP_ARG_infp1; |
| 264 |
fp2.v = (unsigned long) STAP_ARG_infp2; |
| 265 |
|
| 266 |
STAP_RETVALUE = f64_lt(fp1, fp2); |
| 267 |
%} |
| 268 |
|
| 269 |
/** |
| 270 |
* sfunction fp32_to_fp64 - Convert fp32 to 64 bit floating point |
| 271 |
* |
| 272 |
* @input: a long integer |
| 273 |
* |
| 274 |
* Description: Convert from 32 bit floating point to a 64 bit softfloat floating point. |
| 275 |
*/ |
| 276 |
function fp32_to_fp64:long (input:long) |
| 277 |
%{ |
| 278 |
float64_t fp64; |
| 279 |
float32_t fp32; |
| 280 |
fp32.v = STAP_ARG_input; |
| 281 |
|
| 282 |
fp64 = f32_to_f64(fp32); |
| 283 |
STAP_RETVALUE = fp64.v; |
| 284 |
%} |
| 285 |
|