| 1 |
/* Copyright (C) 2019-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
This file is part of LIBF7, which is part of GCC. |
| 4 |
|
| 5 |
GCC is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License as published by the Free |
| 7 |
Software Foundation; either version 3, or (at your option) any later |
| 8 |
version. |
| 9 |
|
| 10 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
for more details. |
| 14 |
|
| 15 |
Under Section 7 of GPL version 3, you are granted additional |
| 16 |
permissions described in the GCC Runtime Library Exception, version |
| 17 |
3.1, as published by the Free Software Foundation. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License and |
| 20 |
a copy of the GCC Runtime Library Exception along with this program; |
| 21 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 22 |
<http://www.gnu.org/licenses/>. */ |
| 23 |
|
| 24 |
#ifndef LIBF7_H |
| 25 |
#define LIBF7_H |
| 26 |
#define IN_LIBF7_H |
| 27 |
|
| 28 |
#include "f7-renames.h" |
| 29 |
|
| 30 |
#define F7_MANT_BYTES 7 |
| 31 |
#define F7_MANT_BITS (8 * F7_MANT_BYTES) |
| 32 |
#define F7_SIZEOF (1 + F7_MANT_BYTES + 2) |
| 33 |
|
| 34 |
/* Using the following GCC features: |
| 35 |
-- Unnamed structs / unions (GNU-C) |
| 36 |
-- Fixed-point types (GNU-C) |
| 37 |
-- Inline asm |
| 38 |
-- Setting assembler names by means of __asm (GNU-C). |
| 39 |
-- Attributes: alias, always_inline, const, noinline, unused, |
| 40 |
progmem, weak, warning |
| 41 |
-- GCC built-ins: __builtin_abort, __builtin_constant_p |
| 42 |
-- AVR built-ins: __builtin_avr_bitsr, __builtin_avr_rbits |
| 43 |
*/ |
| 44 |
|
| 45 |
/* We have 2 kinds of flags: |
| 46 |
|
| 47 |
A) The flags that are stored in f7_t.flags: |
| 48 |
-- f7_t.is_nan (NaN) |
| 49 |
-- f7_t.is_inf (+Inf or -Inf) |
| 50 |
-- f7_t.sign (negative or -Inf). |
| 51 |
-- _plusx: This flag is used by f7_horner. Is is set in some |
| 52 |
polynomial coefficients from libf7-const.def to indicate that |
| 53 |
the respective polynomial has a leading coefficient of 1. |
| 54 |
The flag is set in the second-highest coefficient, and the leading |
| 55 |
coefficient is omitted. |
| 56 |
|
| 57 |
B) The flags that are returned by f7_classify(). This are the |
| 58 |
flags from A) together with |
| 59 |
-- _zero: indicate that a number is zero. |
| 60 |
*/ |
| 61 |
|
| 62 |
#define F7_FLAGNO_sign 0 |
| 63 |
#define F7_FLAGNO_zero 1 |
| 64 |
#define F7_FLAGNO_nan 2 |
| 65 |
#define F7_FLAGNO_plusx 3 |
| 66 |
#define F7_FLAGNO_inf 7 |
| 67 |
|
| 68 |
#define F7_HAVE_Inf 1 |
| 69 |
|
| 70 |
// Flags that might be set by f7_classify(). |
| 71 |
#define F7_FLAG_sign (1 << F7_FLAGNO_sign) |
| 72 |
#define F7_FLAG_zero (1 << F7_FLAGNO_zero) |
| 73 |
#define F7_FLAG_nan (1 << F7_FLAGNO_nan) |
| 74 |
#define F7_FLAG_plusx (1 << F7_FLAGNO_plusx) |
| 75 |
#define F7_FLAG_inf (F7_HAVE_Inf << F7_FLAGNO_inf) |
| 76 |
|
| 77 |
// Flags that might be set in f7_t.flags. |
| 78 |
#define F7_FLAGS (F7_FLAG_inf | F7_FLAG_nan | F7_FLAG_sign) |
| 79 |
|
| 80 |
#if !defined __ASSEMBLER__ |
| 81 |
|
| 82 |
#ifndef IN_LIBGCC2 |
| 83 |
#include <stdint.h> |
| 84 |
#include <stdbool.h> |
| 85 |
#include <stdlib.h> |
| 86 |
#include <stdio.h> |
| 87 |
#else |
| 88 |
/* Do not assume that we have std headers when we build libgcc. */ |
| 89 |
|
| 90 |
typedef __UINT64_TYPE__ uint64_t; |
| 91 |
typedef __UINT32_TYPE__ uint32_t; |
| 92 |
typedef __UINT16_TYPE__ uint16_t; |
| 93 |
typedef __UINT8_TYPE__ uint8_t; |
| 94 |
typedef __INT64_TYPE__ int64_t; |
| 95 |
typedef __INT32_TYPE__ int32_t; |
| 96 |
typedef __INT16_TYPE__ int16_t; |
| 97 |
typedef __INT8_TYPE__ int8_t; |
| 98 |
#define INT8_MIN (-1 - __INT8_MAX__) |
| 99 |
#define INT16_MAX __INT16_MAX__ |
| 100 |
#define NULL ((void*) 0) |
| 101 |
#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L |
| 102 |
/* bool, true and false are keywords. */ |
| 103 |
#else |
| 104 |
#define bool _Bool |
| 105 |
#define true 1 |
| 106 |
#define false 0 |
| 107 |
#endif /* C23 ? */ |
| 108 |
#endif /* IN_LIBGCC2 */ |
| 109 |
|
| 110 |
#include "asm-defs.h" |
| 111 |
|
| 112 |
#ifdef __cplusplus |
| 113 |
extern "C" { |
| 114 |
#define _Static_assert(X, Y) static_assert (X) |
| 115 |
#endif // C++ |
| 116 |
|
| 117 |
#define F7_INLINE inline __attribute__((__always_inline__)) |
| 118 |
#define F7_NOINLINE __attribute__((__noinline__)) |
| 119 |
#define F7_WEAK __attribute__((__weak__)) |
| 120 |
#define F7_UNUSED __attribute__((__unused__)) |
| 121 |
#define F7_CONST __attribute__((__const__)) |
| 122 |
|
| 123 |
#define F7_STRINGY2(X) #X |
| 124 |
#define F7_STRINGY(X) F7_STRINGY2(X) |
| 125 |
#define F7ASM(X) __asm (F7_STRINGY2(X)) |
| 126 |
|
| 127 |
typedef struct f7_t |
| 128 |
{ |
| 129 |
union |
| 130 |
{ |
| 131 |
struct |
| 132 |
{ |
| 133 |
uint8_t sign :1; |
| 134 |
uint8_t reserved1 :1; |
| 135 |
uint8_t is_nan :1; |
| 136 |
uint8_t reserved2 :4; |
| 137 |
uint8_t is_inf :1; |
| 138 |
}; |
| 139 |
uint8_t flags; |
| 140 |
}; |
| 141 |
|
| 142 |
uint8_t mant[7]; |
| 143 |
int16_t expo; |
| 144 |
} f7_t; |
| 145 |
|
| 146 |
typedef uint64_t f7_double_t; |
| 147 |
|
| 148 |
#define F7_MANT_HI4(X) \ |
| 149 |
(*(uint32_t*) & (X)->mant[F7_MANT_BYTES - 4]) |
| 150 |
|
| 151 |
#define F7_MANT_CONST_HI4(X) \ |
| 152 |
(*(const uint32_t*) & (X)->mant[F7_MANT_BYTES - 4]) |
| 153 |
|
| 154 |
#define F7_MANT_HI2(X) \ |
| 155 |
(*(uint16_t*) & (X)->mant[F7_MANT_BYTES - 2]) |
| 156 |
|
| 157 |
static F7_INLINE |
| 158 |
uint8_t f7_classify (const f7_t *aa) |
| 159 |
{ |
| 160 |
extern void f7_classify_asm (void); |
| 161 |
register uint8_t rclass __asm ("r24"); |
| 162 |
__asm ("%~call %x[f]" |
| 163 |
: "=r" (rclass) |
| 164 |
: [f] "i" (f7_classify_asm), "z" (aa)); |
| 165 |
return rclass; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
// +Inf or -Inf |
| 170 |
static F7_INLINE |
| 171 |
bool f7_class_inf (uint8_t c) |
| 172 |
{ |
| 173 |
#if defined (F7_HAVE_Inf) && F7_HAVE_Inf == 1 |
| 174 |
return c >= F7_FLAG_inf; |
| 175 |
#elif defined (F7_HAVE_Inf) && F7_HAVE_Inf == 0 |
| 176 |
(void) c; |
| 177 |
return false; |
| 178 |
#else |
| 179 |
#error macro F7_HAVE_Inf must be defined to 0 or to 1. |
| 180 |
#endif // Have Inf |
| 181 |
} |
| 182 |
|
| 183 |
static F7_INLINE |
| 184 |
bool f7_is_inf (const f7_t *aa) |
| 185 |
{ |
| 186 |
return f7_class_inf (aa->flags); |
| 187 |
} |
| 188 |
|
| 189 |
// Not-a-Number (NaN). |
| 190 |
static F7_INLINE |
| 191 |
bool f7_class_nan (uint8_t c) |
| 192 |
{ |
| 193 |
return c & F7_FLAG_nan; |
| 194 |
} |
| 195 |
|
| 196 |
static F7_INLINE |
| 197 |
bool f7_is_nan (const f7_t *aa) |
| 198 |
{ |
| 199 |
return f7_class_nan (aa->flags); |
| 200 |
} |
| 201 |
|
| 202 |
// Some number |
| 203 |
static F7_INLINE |
| 204 |
bool f7_class_number (uint8_t c) |
| 205 |
{ |
| 206 |
return c <= (F7_FLAG_sign | F7_FLAG_zero); |
| 207 |
} |
| 208 |
|
| 209 |
static F7_INLINE |
| 210 |
bool f7_is_number (const f7_t *aa) |
| 211 |
{ |
| 212 |
return f7_class_number (f7_classify (aa)); |
| 213 |
} |
| 214 |
|
| 215 |
// Zero |
| 216 |
static F7_INLINE |
| 217 |
bool f7_class_zero (uint8_t c) |
| 218 |
{ |
| 219 |
return c & F7_FLAG_zero; |
| 220 |
} |
| 221 |
|
| 222 |
static F7_INLINE |
| 223 |
bool f7_is_zero (const f7_t *aa) |
| 224 |
{ |
| 225 |
return f7_class_zero (f7_classify (aa)); |
| 226 |
} |
| 227 |
|
| 228 |
// A non-zero number. |
| 229 |
static F7_INLINE |
| 230 |
bool f7_class_nonzero (uint8_t c) |
| 231 |
{ |
| 232 |
return c <= F7_FLAG_sign; |
| 233 |
} |
| 234 |
|
| 235 |
static F7_INLINE |
| 236 |
bool f7_is_nonzero (const f7_t *aa) |
| 237 |
{ |
| 238 |
return f7_class_nonzero (f7_classify (aa)); |
| 239 |
} |
| 240 |
|
| 241 |
static F7_INLINE |
| 242 |
bool f7_class_sign (uint8_t c) |
| 243 |
{ |
| 244 |
return c & F7_FLAG_sign; |
| 245 |
} |
| 246 |
|
| 247 |
static F7_INLINE |
| 248 |
bool f7_signbit (const f7_t *aa) |
| 249 |
{ |
| 250 |
return aa->flags & F7_FLAG_sign; |
| 251 |
} |
| 252 |
|
| 253 |
static F7_INLINE |
| 254 |
void f7_set_sign (f7_t *cc, bool sign) |
| 255 |
{ |
| 256 |
_Static_assert (F7_FLAGNO_sign == 0, ""); |
| 257 |
cc->flags &= ~F7_FLAG_sign; |
| 258 |
cc->flags |= sign; |
| 259 |
} |
| 260 |
|
| 261 |
static F7_INLINE |
| 262 |
void f7_set_nan (f7_t *cc) |
| 263 |
{ |
| 264 |
cc->flags = F7_FLAG_nan; |
| 265 |
} |
| 266 |
|
| 267 |
static F7_INLINE |
| 268 |
void f7_clr (f7_t *cc) |
| 269 |
{ |
| 270 |
extern void f7_clr_asm (void); |
| 271 |
__asm ("%~call %x[f]" |
| 272 |
: |
| 273 |
: [f] "i" (f7_clr_asm), "z" (cc) |
| 274 |
: "memory"); |
| 275 |
} |
| 276 |
|
| 277 |
static F7_INLINE |
| 278 |
f7_t* f7_copy (f7_t *cc, const f7_t *aa) |
| 279 |
{ |
| 280 |
extern void f7_copy_asm (void); |
| 281 |
__asm ("%~call %x[f]" |
| 282 |
: |
| 283 |
: [f] "i" (f7_copy_asm), "z" (cc), "x" (aa) |
| 284 |
: "memory"); |
| 285 |
return cc; |
| 286 |
} |
| 287 |
|
| 288 |
static F7_INLINE |
| 289 |
f7_t* f7_copy_P (f7_t *cc, const f7_t *aa) |
| 290 |
{ |
| 291 |
extern void f7_copy_P_asm (void); |
| 292 |
__asm ("%~call %x[f]" |
| 293 |
: |
| 294 |
: [f] "i" (f7_copy_P_asm), "x" (cc), "z" (aa) |
| 295 |
: "memory"); |
| 296 |
return cc; |
| 297 |
} |
| 298 |
|
| 299 |
static F7_INLINE |
| 300 |
void f7_copy_mant (f7_t *cc, const f7_t *aa) |
| 301 |
{ |
| 302 |
extern void f7_copy_mant_asm (void); |
| 303 |
__asm ("%~call %x[f]" |
| 304 |
: |
| 305 |
: [f] "i" (f7_copy_mant_asm), "z" (cc), "x" (aa) |
| 306 |
: "memory"); |
| 307 |
} |
| 308 |
|
| 309 |
static F7_INLINE |
| 310 |
void f7_set_inf (f7_t *cc, bool sign) |
| 311 |
{ |
| 312 |
#if F7_HAVE_Inf == 1 |
| 313 |
cc->flags = F7_FLAG_inf | sign; |
| 314 |
#else |
| 315 |
(void) sign; |
| 316 |
cc->flags = F7_FLAG_nan; |
| 317 |
#endif // Have Inf |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
static F7_INLINE |
| 322 |
bool f7_msbit (const f7_t *aa) |
| 323 |
{ |
| 324 |
return aa->mant[F7_MANT_BYTES - 1] & 0x80; |
| 325 |
} |
| 326 |
|
| 327 |
// Quick test against 0 if A is known to be a number (neither NaN nor Inf). |
| 328 |
static F7_INLINE |
| 329 |
bool f7_is0 (const f7_t *aa) |
| 330 |
{ |
| 331 |
return 0 == f7_msbit (aa); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
static F7_INLINE |
| 336 |
int8_t f7_cmp_mant (const f7_t *aa, const f7_t *bb) |
| 337 |
{ |
| 338 |
extern void f7_cmp_mant_asm (void); |
| 339 |
register int8_t r24 __asm ("r24"); |
| 340 |
__asm ("%~call %x[f] ;; %1 %3" |
| 341 |
: "=r" (r24) |
| 342 |
: [f] "i" (f7_cmp_mant_asm), "x" (aa), "z" (bb)); |
| 343 |
return r24; |
| 344 |
} |
| 345 |
|
| 346 |
static F7_INLINE |
| 347 |
bool f7_store_expo (f7_t *cc, int16_t expo) |
| 348 |
{ |
| 349 |
extern void f7_store_expo_asm (void); |
| 350 |
register bool r24 __asm ("r24"); |
| 351 |
register int16_t rexpo __asm ("r24") = expo; |
| 352 |
__asm ("%~call %x[f] ;; %0 %2 %3" |
| 353 |
: "=r" (r24) |
| 354 |
: [f] "i" (f7_store_expo_asm), "z" (cc), "r" (rexpo)); |
| 355 |
return r24; |
| 356 |
} |
| 357 |
|
| 358 |
static F7_INLINE |
| 359 |
f7_t* f7_abs (f7_t *cc, const f7_t *aa) |
| 360 |
{ |
| 361 |
f7_copy (cc, aa); |
| 362 |
f7_set_sign (cc, 0); |
| 363 |
|
| 364 |
return cc; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
extern int8_t f7_cmp (const f7_t*, const f7_t*); |
| 369 |
extern bool f7_lt_impl (const f7_t*, const f7_t*); |
| 370 |
extern bool f7_le_impl (const f7_t*, const f7_t*); |
| 371 |
extern bool f7_gt_impl (const f7_t*, const f7_t*); |
| 372 |
extern bool f7_ge_impl (const f7_t*, const f7_t*); |
| 373 |
extern bool f7_ne_impl (const f7_t*, const f7_t*); |
| 374 |
extern bool f7_eq_impl (const f7_t*, const f7_t*); |
| 375 |
extern bool f7_unord_impl (const f7_t*, const f7_t*); |
| 376 |
|
| 377 |
static F7_INLINE |
| 378 |
bool f7_lt (const f7_t *aa, const f7_t *bb) |
| 379 |
{ |
| 380 |
return 2 & f7_cmp (aa, bb); |
| 381 |
} |
| 382 |
|
| 383 |
static F7_INLINE |
| 384 |
bool f7_gt (const f7_t *aa, const f7_t *bb) |
| 385 |
{ |
| 386 |
return 1 == f7_cmp (aa, bb); |
| 387 |
} |
| 388 |
|
| 389 |
static F7_INLINE |
| 390 |
bool f7_le (const f7_t *aa, const f7_t *bb) |
| 391 |
{ |
| 392 |
int8_t c = f7_cmp (aa, bb); |
| 393 |
return (uint8_t) (c + 1) <= 1; |
| 394 |
} |
| 395 |
|
| 396 |
static F7_INLINE |
| 397 |
bool f7_ge (const f7_t *aa, const f7_t *bb) |
| 398 |
{ |
| 399 |
return f7_cmp (aa, bb) >= 0; |
| 400 |
} |
| 401 |
|
| 402 |
static F7_INLINE |
| 403 |
bool f7_unordered (const f7_t *aa, const f7_t *bb) |
| 404 |
{ |
| 405 |
return INT8_MIN == f7_cmp (aa, bb); |
| 406 |
} |
| 407 |
|
| 408 |
static F7_INLINE |
| 409 |
bool f7_ordered (const f7_t *aa, const f7_t *bb) |
| 410 |
{ |
| 411 |
return INT8_MIN != f7_cmp (aa, bb); |
| 412 |
} |
| 413 |
|
| 414 |
static F7_INLINE |
| 415 |
bool f7_eq (const f7_t *aa, const f7_t *bb) |
| 416 |
{ |
| 417 |
return 0 == f7_cmp (aa, bb); |
| 418 |
} |
| 419 |
|
| 420 |
static F7_INLINE |
| 421 |
bool f7_ne (const f7_t *aa, const f7_t *bb) |
| 422 |
{ |
| 423 |
return 1 & f7_cmp (aa, bb); |
| 424 |
} |
| 425 |
|
| 426 |
extern void f7_clr (f7_t*); |
| 427 |
|
| 428 |
__attribute__((warning ("foo_u16"))) void foo_u16 (void); |
| 429 |
__attribute__((warning ("foo_s16"))) void foo_s16 (void); |
| 430 |
|
| 431 |
extern f7_t* f7_set_s16_impl (f7_t*, int16_t); |
| 432 |
extern f7_t* f7_set_u16_impl (f7_t*, uint16_t); |
| 433 |
|
| 434 |
static F7_INLINE |
| 435 |
f7_t* f7_set_u16_worker (f7_t *cc, uint16_t u16) |
| 436 |
{ |
| 437 |
if (__builtin_constant_p (u16)) |
| 438 |
{ |
| 439 |
if (u16 == 0) |
| 440 |
return cc; |
| 441 |
|
| 442 |
uint8_t off = __builtin_clz (u16); |
| 443 |
if (15 - off) |
| 444 |
* (uint8_t*) & cc->expo = (uint8_t) (15 - off); |
| 445 |
u16 <<= off; |
| 446 |
if (u16 & 0xff) |
| 447 |
cc->mant[5] = (uint8_t) u16; |
| 448 |
if (u16 & 0xff00) |
| 449 |
cc->mant[6] = (uint8_t) (u16 >> 8); |
| 450 |
|
| 451 |
return cc; |
| 452 |
} |
| 453 |
else |
| 454 |
{ |
| 455 |
foo_u16(); |
| 456 |
__builtin_abort(); |
| 457 |
return NULL; |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
static F7_INLINE |
| 462 |
f7_t* f7_set_u16 (f7_t *cc, uint16_t u16) |
| 463 |
{ |
| 464 |
if (__builtin_constant_p (u16)) |
| 465 |
{ |
| 466 |
f7_clr (cc); |
| 467 |
return f7_set_u16_worker (cc, u16); |
| 468 |
} |
| 469 |
|
| 470 |
return f7_set_u16_impl (cc, u16); |
| 471 |
} |
| 472 |
|
| 473 |
static F7_INLINE |
| 474 |
f7_t* f7_set_s16 (f7_t *cc, int16_t s16) |
| 475 |
{ |
| 476 |
if (__builtin_constant_p (s16)) |
| 477 |
{ |
| 478 |
f7_clr (cc); |
| 479 |
|
| 480 |
uint16_t u16 = (uint16_t) s16; |
| 481 |
|
| 482 |
if (s16 < 0) |
| 483 |
{ |
| 484 |
u16 = -u16; |
| 485 |
cc->flags = F7_FLAG_sign; |
| 486 |
} |
| 487 |
|
| 488 |
return f7_set_u16_worker (cc, u16); |
| 489 |
} |
| 490 |
|
| 491 |
return f7_set_s16_impl (cc, s16); |
| 492 |
} |
| 493 |
|
| 494 |
static F7_INLINE |
| 495 |
void f7_set_eps (f7_t *cc, uint8_t eps, bool sign) |
| 496 |
{ |
| 497 |
cc = f7_set_u16 (cc, 1); |
| 498 |
if (!__builtin_constant_p (sign) || sign) |
| 499 |
cc->flags = sign; |
| 500 |
cc->mant[0] = eps; |
| 501 |
} |
| 502 |
|
| 503 |
static F7_INLINE |
| 504 |
f7_t* f7_set_1pow2 (f7_t *cc, int16_t expo, bool sign) |
| 505 |
{ |
| 506 |
cc = f7_set_u16 (cc, 1); |
| 507 |
cc->expo = expo; |
| 508 |
if (!__builtin_constant_p (sign) || sign) |
| 509 |
cc->flags = sign; |
| 510 |
return cc; |
| 511 |
} |
| 512 |
|
| 513 |
static F7_INLINE |
| 514 |
f7_t* f7_set_u64 (f7_t *cc, uint64_t u64) |
| 515 |
{ |
| 516 |
extern f7_t* f7_set_u64_asm (uint64_t, f7_t*); |
| 517 |
return f7_set_u64_asm (u64, cc); |
| 518 |
} |
| 519 |
|
| 520 |
static F7_INLINE |
| 521 |
f7_t* f7_set_s64 (f7_t *cc, int64_t s64) |
| 522 |
{ |
| 523 |
extern f7_t* f7_set_s64_asm (int64_t, f7_t*); |
| 524 |
return f7_set_s64_asm (s64, cc); |
| 525 |
} |
| 526 |
|
| 527 |
extern void f7_set_double_impl (f7_double_t, f7_t*); |
| 528 |
static F7_INLINE |
| 529 |
void f7_set_double (f7_t *cc, f7_double_t val64) |
| 530 |
{ |
| 531 |
f7_set_double_impl (val64, cc); |
| 532 |
} |
| 533 |
|
| 534 |
extern f7_t* f7_init_impl (uint64_t, uint8_t, f7_t*, int16_t); |
| 535 |
|
| 536 |
static F7_INLINE |
| 537 |
f7_t* f7_init (f7_t *cc, uint8_t flags, uint64_t mant, int16_t expo) |
| 538 |
{ |
| 539 |
return f7_init_impl (mant, flags, cc, expo); |
| 540 |
} |
| 541 |
|
| 542 |
extern f7_t* f7_set_s32 (f7_t*, int32_t); |
| 543 |
extern f7_t* f7_set_u16 (f7_t*, uint16_t); |
| 544 |
extern f7_t* f7_set_u32 (f7_t*, uint32_t); |
| 545 |
extern void f7_set_float (f7_t*, float); |
| 546 |
extern void f7_set_pdouble (f7_t*, const f7_double_t*); |
| 547 |
|
| 548 |
extern int16_t f7_get_s16 (const f7_t*); |
| 549 |
extern int32_t f7_get_s32 (const f7_t*); |
| 550 |
extern int64_t f7_get_s64 (const f7_t*); |
| 551 |
extern uint16_t f7_get_u16 (const f7_t*); |
| 552 |
extern uint32_t f7_get_u32 (const f7_t*); |
| 553 |
extern uint64_t f7_get_u64 (const f7_t*); |
| 554 |
extern float f7_get_float (const f7_t*); |
| 555 |
extern f7_double_t f7_get_double (const f7_t*); |
| 556 |
|
| 557 |
#if USE_LPM == 1 |
| 558 |
#define F7_PGMSPACE __attribute__((__progmem__)) |
| 559 |
#define f7_copy_flash f7_copy_P |
| 560 |
|
| 561 |
#define f7_const(X, NAME) \ |
| 562 |
f7_copy_P ((X), & F7_(const_ ## NAME ## _P)) |
| 563 |
|
| 564 |
#define F7_CONST_DEF(NAME, FLAGS, M0, M1, M2, M3, M4, M5, M6, EXPO) \ |
| 565 |
extern const f7_t F7_(const_ ## NAME ## _P); |
| 566 |
#include "libf7-const.def" |
| 567 |
#undef F7_CONST_DEF |
| 568 |
#else |
| 569 |
#define F7_PGMSPACE // Empty |
| 570 |
#define f7_copy_flash f7_copy |
| 571 |
|
| 572 |
#define f7_const(X, NAME) \ |
| 573 |
f7_copy ((X), & F7_(const_ ## NAME)) |
| 574 |
|
| 575 |
#define F7_CONST_DEF(NAME, FLAGS, M0, M1, M2, M3, M4, M5, M6, EXPO) \ |
| 576 |
extern const f7_t F7_(const_ ## NAME); |
| 577 |
#include "libf7-const.def" |
| 578 |
#undef F7_CONST_DEF |
| 579 |
#endif // USE_LPM |
| 580 |
|
| 581 |
|
| 582 |
// Basic floating point arithmetic: |
| 583 |
// double output <=> f7_t* |
| 584 |
// double input <=> const f7_t* |
| 585 |
extern f7_t* f7_neg (f7_t*, const f7_t*); |
| 586 |
extern void f7_add (f7_t*, const f7_t*, const f7_t*); |
| 587 |
extern void f7_sub (f7_t*, const f7_t*, const f7_t*); |
| 588 |
extern void f7_mul (f7_t*, const f7_t*, const f7_t*); |
| 589 |
extern void f7_div (f7_t*, const f7_t*, const f7_t*); |
| 590 |
|
| 591 |
// Analogies of functions from math.h: |
| 592 |
// double output <=> f7_t* |
| 593 |
// double input <=> const f7_t* |
| 594 |
extern void f7_fabs (f7_t*, const f7_t*); |
| 595 |
extern void f7_fmod (f7_t*, const f7_t*, const f7_t*); |
| 596 |
extern void f7_frexp (f7_t*, const f7_t*, int*); |
| 597 |
extern void f7_exp (f7_t*, const f7_t*); |
| 598 |
extern void f7_log (f7_t*, const f7_t*); |
| 599 |
extern void f7_pow (f7_t*, const f7_t*, const f7_t*); |
| 600 |
extern void f7_sqrt (f7_t*, const f7_t*); |
| 601 |
extern void f7_cbrt (f7_t*, const f7_t*); |
| 602 |
extern void f7_hypot (f7_t*, const f7_t*, const f7_t*); |
| 603 |
extern f7_t* f7_ldexp (f7_t*, const f7_t*, int); |
| 604 |
extern f7_t* f7_fmax (f7_t*, const f7_t*, const f7_t*); |
| 605 |
extern f7_t* f7_fmin (f7_t*, const f7_t*, const f7_t*); |
| 606 |
extern f7_t* f7_trunc (f7_t*, const f7_t*); |
| 607 |
extern f7_t* f7_floor (f7_t*, const f7_t*); |
| 608 |
extern void f7_ceil (f7_t*, const f7_t*); |
| 609 |
extern void f7_round (f7_t*, const f7_t*); |
| 610 |
extern void f7_sin (f7_t*, const f7_t*); |
| 611 |
extern void f7_cos (f7_t*, const f7_t*); |
| 612 |
extern void f7_tan (f7_t*, const f7_t*); |
| 613 |
extern void f7_atan (f7_t*, const f7_t*); |
| 614 |
extern void f7_atan2 (f7_t*, const f7_t*, const f7_t*); |
| 615 |
extern void f7_fdim (f7_t*, const f7_t*, const f7_t*); |
| 616 |
extern void f7_asin (f7_t*, const f7_t*); |
| 617 |
extern void f7_acos (f7_t*, const f7_t*); |
| 618 |
extern void f7_tanh (f7_t*, const f7_t*); |
| 619 |
extern void f7_sinh (f7_t*, const f7_t*); |
| 620 |
extern void f7_cosh (f7_t*, const f7_t*); |
| 621 |
extern void f7_log2 (f7_t*, const f7_t*); |
| 622 |
extern void f7_log10 (f7_t*, const f7_t*); |
| 623 |
extern void f7_exp10 (f7_t*, const f7_t*); |
| 624 |
extern void f7_pow10 (f7_t*, const f7_t*); |
| 625 |
|
| 626 |
// Just prototypes, not implemented yet. |
| 627 |
extern long f7_lrint (const f7_t*); |
| 628 |
extern long f7_lround (const f7_t*); |
| 629 |
|
| 630 |
// Helper functions, aliases, convenience. |
| 631 |
extern void f7_div1 (f7_t*, const f7_t*); |
| 632 |
extern void f7_square (f7_t*, const f7_t*); |
| 633 |
|
| 634 |
extern void f7_powi (f7_t*, const f7_t*, int); |
| 635 |
extern f7_t* f7_max (f7_t*, const f7_t*, const f7_t*); |
| 636 |
extern f7_t* f7_min (f7_t*, const f7_t*, const f7_t*); |
| 637 |
extern f7_t* f7_truncx (f7_t*, const f7_t*, bool); |
| 638 |
extern void f7_cotan (f7_t*, const f7_t*); |
| 639 |
extern void f7_sincos (f7_t*, f7_t*, const f7_t*); |
| 640 |
extern void f7_asinacos (f7_t*, const f7_t*, uint8_t); |
| 641 |
extern void f7_sinhcosh (f7_t*, const f7_t*, bool); |
| 642 |
|
| 643 |
extern void f7_horner (f7_t*, const f7_t*, uint8_t, const f7_t *coeff, f7_t*); |
| 644 |
extern void f7_mul_noround (f7_t*, const f7_t*, const f7_t*); |
| 645 |
extern void f7_clr_mant_lsbs (f7_t*, const f7_t*, uint8_t) F7ASM(f7_clr_mant_lsbs_asm); |
| 646 |
|
| 647 |
extern int8_t f7_cmp_unordered (const f7_t*, const f7_t*, bool); |
| 648 |
extern int8_t f7_cmp_abs (const f7_t*, const f7_t*); |
| 649 |
|
| 650 |
extern bool f7_abscmp_msb_ge (const f7_t*, uint8_t msb, int16_t expo); |
| 651 |
extern void f7_addsub (f7_t*, const f7_t*, const f7_t*, bool neg_b); |
| 652 |
extern void f7_madd_msub (f7_t*, const f7_t*, const f7_t*, const f7_t*, bool); |
| 653 |
extern void f7_madd (f7_t*, const f7_t*, const f7_t*, const f7_t*); |
| 654 |
extern void f7_msub (f7_t*, const f7_t*, const f7_t*, const f7_t*); |
| 655 |
extern uint8_t f7_mulx (f7_t*, const f7_t*, const f7_t*, bool); |
| 656 |
extern void f7_divx (f7_t*, const f7_t*, const f7_t*, uint8_t); |
| 657 |
extern void f7_logx (f7_t*, const f7_t*, const f7_t*); |
| 658 |
extern f7_t* f7_minmax (f7_t*, const f7_t*, const f7_t*, bool); |
| 659 |
|
| 660 |
// Idem: |
| 661 |
// f7_Ifunc (y) = f7_func (y, y) |
| 662 |
// f7_Ifunc (y, x) = f7_func (y, y, x) |
| 663 |
extern void f7_Iadd (f7_t*, const f7_t*); |
| 664 |
extern void f7_Isub (f7_t*, const f7_t*); |
| 665 |
extern void f7_Imul (f7_t*, const f7_t*); |
| 666 |
extern void f7_Idiv (f7_t*, const f7_t*); |
| 667 |
extern void f7_IRsub (f7_t*, const f7_t*); |
| 668 |
extern void f7_Ineg (f7_t*); |
| 669 |
extern void f7_Isqrt (f7_t*); |
| 670 |
extern void f7_Isquare (f7_t*); |
| 671 |
extern f7_t* f7_Ildexp (f7_t*, int); |
| 672 |
|
| 673 |
// Protoypes for some functions from libf7-asm.sx. |
| 674 |
F7_CONST extern uint16_t f7_sqrt16_round (uint16_t) F7ASM(f7_sqrt16_round_asm); |
| 675 |
F7_CONST extern uint8_t f7_sqrt16_floor (uint16_t) F7ASM(f7_sqrt16_floor_asm); |
| 676 |
extern void f7_addsub_mant_scaled_asm (f7_t*, const f7_t*, const f7_t*, uint8_t); |
| 677 |
extern uint8_t f7_mul_mant_asm (f7_t*, const f7_t*, const f7_t*, uint8_t); |
| 678 |
extern void f7_sqrt_approx_asm (f7_t*, const f7_t*); |
| 679 |
extern uint64_t f7_lshrdi3 (uint64_t, uint8_t) F7ASM(f7_lshrdi3_asm); |
| 680 |
extern uint64_t f7_ashldi3 (uint64_t, uint8_t) F7ASM(f7_ashldi3_asm); |
| 681 |
// Normalize a non-Inf, non-NaN value. Sets .sign to 0. |
| 682 |
extern f7_t* f7_normalize_asm (f7_t*); |
| 683 |
|
| 684 |
// Dumping. |
| 685 |
#ifndef IN_LIBGCC2 |
| 686 |
extern void f7_dump (const f7_t*); |
| 687 |
extern void f7_dump_mant (const f7_t*); |
| 688 |
extern void f7_put_C (const f7_t*, FILE*); |
| 689 |
extern void f7_put_CDEF (const char *name, const f7_t*, FILE*); |
| 690 |
#endif /* IN_LIBGCC2 */ |
| 691 |
|
| 692 |
#ifdef __cplusplus |
| 693 |
} // extern "C" |
| 694 |
#include "libf7-class.h" |
| 695 |
#endif // C++ |
| 696 |
|
| 697 |
#endif /* __ASSEMBLER__ */ |
| 698 |
#undef IN_LIBF7_H |
| 699 |
#endif /* LIBF7_H */ |