this repo has no description
1/*
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*******************************************************************************
23* *
24* File fp_private.h *
25* Masks used for single and double floating point representations *
26* on PowerPC. *
27* *
28*******************************************************************************/
29#ifndef __FP_PRIVATE__
30#define __FP_PRIVATE__
31#include "stdint.h"
32
33/******************************************************************************
34* Functions used internally *
35******************************************************************************/
36double copysign ( double arg2, double arg1 );
37double fabs ( double x );
38double nan ( const char *string );
39
40/* gcc inlines fabs() and fabsf() */
41#define __FABS(x) __builtin_fabs(x)
42#define __FABSF(x) __builtin_fabsf(x)
43
44#if defined(__APPLE_CC__)
45#define likely(x) __builtin_expect(!!(x), 1)
46#define unlikely(x) __builtin_expect((x), 0)
47#else
48#define likely(x) (x)
49#define unlikely(x) (x)
50#endif
51
52#include "ppc_intrinsics.h"
53
54#define __FMADD __fmadd
55#define __FMADDS __fmadds
56#define __FMSUB __fmsub
57#define __FNMSUB __fnmsub
58#define __FMUL __fmul
59#define __FADD __fadd
60#define __FSUB __fsub
61
62static inline double __fadd (double a, double b) __attribute__((always_inline));
63static inline double
64__fadd (double a, double b)
65{
66 double result;
67 __asm__ ("fadd %0, %1, %2"
68 /* outputs: */ : "=f" (result)
69 /* inputs: */ : "f" (a), "f" (b));
70 return result;
71}
72
73static inline double __fsub (double a, double b) __attribute__((always_inline));
74static inline double
75__fsub (double a, double b)
76{
77 double result;
78 __asm__ ("fsub %0, %1, %2"
79 /* outputs: */ : "=f" (result)
80 /* inputs: */ : "f" (a), "f" (b));
81 return result;
82}
83
84// The following macros are invoked for side-effect. Not written as inline functions because the
85// compiler could discard the code as an optimization.
86#define __NOOP \
87({ __label__ L1, L2; L1: (void)&&L1;\
88 asm volatile ( "nop" ); /* NOOP */ \
89 L2: (void)&&L2; \
90})
91
92#define __ENSURE(x, y, z) \
93({ \
94 double __value, __argx = (x), __argy = (y), __argz = (z); \
95 asm volatile ("fmadd %0,%1,%2,%3" : "=f" (__value): "f" (__argx), "f" (__argy), "f" (__argz)); \
96 __value; \
97})
98
99#define __PROD(x, y) \
100({ \
101 double __value, __argx = (x), __argy = (y); \
102 asm volatile ("fmul %0,%1,%2" : "=f" (__value): "f" (__argx), "f" (__argy)); \
103 __value; \
104})
105
106#define __PROG_INEXACT( x ) (void)__PROD( x, x ) /* Raises INEXACT for suitable choice of x */
107
108#define __PROG_UF_INEXACT( x ) (void)__PROD( x, x ) /* Raises UNDERFLOW and INEXACT for suitable choice of x e.g. MIN_NORMAL */
109
110#define __PROG_OF_INEXACT( x ) (void)__PROD( x, x ) /* Raises OVERFLOW and INEXACT for suitable choice of x e.g. MAX_NORMAL */
111
112/******************************************************************************
113* Single precision *
114******************************************************************************/
115
116#define fQuietNan 0x00400000
117
118typedef union {
119 int32_t lval;
120 float fval;
121} hexsingle;
122
123/******************************************************************************
124* Double precision *
125******************************************************************************/
126
127#define dQuietNan 0x00080000
128
129#if defined(__BIG_ENDIAN__)
130
131typedef union {
132 struct {
133 uint32_t hi;
134 uint32_t lo;
135 } i;
136 double d;
137} hexdouble;
138
139#define HEXDOUBLE(hi, lo) { { hi, lo } }
140
141#elif defined(__LITTLE_ENDIAN__)
142
143typedef union {
144 struct {
145 uint32_t lo;
146 uint32_t hi;
147 } i;
148 double d;
149} hexdouble;
150
151#define HEXDOUBLE(hi, lo) { { lo, hi } }
152
153#else
154#error Unknown endianness
155#endif
156
157typedef union {
158 uint32_t i[4];
159 struct {
160 hexdouble hexhead;
161 hexdouble hextail;
162 } hh;
163 struct {
164 double head;
165 double tail;
166 } dd;
167 long double ld;
168} hexdbldbl;
169
170#endif /* __FP_PRIVATE__ */