1 : // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 : // Redistribution and use in source and binary forms, with or without
3 : // modification, are permitted provided that the following conditions are
4 : // met:
5 : //
6 : // * Redistributions of source code must retain the above copyright
7 : // notice, this list of conditions and the following disclaimer.
8 : // * Redistributions in binary form must reproduce the above
9 : // copyright notice, this list of conditions and the following
10 : // disclaimer in the documentation and/or other materials provided
11 : // with the distribution.
12 : // * Neither the name of Google Inc. nor the names of its
13 : // contributors may be used to endorse or promote products derived
14 : // from this software without specific prior written permission.
15 : //
16 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 :
28 : // MOZ: This file is a merge of the relevant parts of all the platform-*.cc
29 : // files in v8; the amount of code remaining was small enough that putting
30 : // everything in a single file was easier, particularly because it means we
31 : // can always compile this one file on every platform.
32 :
33 : #include <math.h>
34 : #include <signal.h>
35 : #include <stdlib.h>
36 :
37 : #include "v8.h"
38 :
39 : namespace v8 {
40 : namespace internal {
41 :
42 257335 : double ceiling(double x) {
43 : #if defined(__APPLE__)
44 : // Correct Mac OS X Leopard 'ceil' behavior.
45 : //
46 : // MOZ: This appears to be fixed in Mac OS X 10.5.8.
47 : //
48 : // MOZ: This fix is apprently also required for FreeBSD and OpenBSD, if we
49 : // have to worry about them.
50 : if (-1.0 < x && x < 0.0) {
51 : return -0.0;
52 : } else {
53 : return ceil(x);
54 : }
55 : #else
56 257335 : return ceil(x);
57 : #endif
58 : }
59 :
60 :
61 : // MOZ: These exit behaviours were copied from SpiderMonkey's JS_Assert()
62 : // function.
63 0 : void OS::Abort() {
64 : #if defined(WIN32)
65 : /*
66 : * We used to call DebugBreak() on Windows, but amazingly, it causes
67 : * the MSVS 2010 debugger not to be able to recover a call stack.
68 : */
69 : *((volatile int *) NULL) = 0;
70 : exit(3);
71 : #elif defined(__APPLE__)
72 : /*
73 : * On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
74 : * trapped.
75 : */
76 : *((volatile int *) NULL) = 0; /* To continue from here in GDB: "return" then "continue". */
77 : raise(SIGABRT); /* In case above statement gets nixed by the optimizer. */
78 : #else
79 0 : raise(SIGABRT); /* To continue from here in GDB: "signal 0". */
80 : #endif
81 0 : }
82 :
83 : } } // namespace v8::internal
84 :
85 : // Extra POSIX/ANSI routines for Win32 when when using Visual Studio C++. Please
86 : // refer to The Open Group Base Specification for specification of the correct
87 : // semantics for these functions.
88 : // (http://www.opengroup.org/onlinepubs/000095399/)
89 : #ifdef _MSC_VER
90 :
91 : #include <float.h>
92 :
93 : // Classify floating point number - usually defined in math.h
94 : int fpclassify(double x) {
95 : // Use the MS-specific _fpclass() for classification.
96 : int flags = _fpclass(x);
97 :
98 : // Determine class. We cannot use a switch statement because
99 : // the _FPCLASS_ constants are defined as flags.
100 : if (flags & (_FPCLASS_PN | _FPCLASS_NN)) return FP_NORMAL;
101 : if (flags & (_FPCLASS_PZ | _FPCLASS_NZ)) return FP_ZERO;
102 : if (flags & (_FPCLASS_PD | _FPCLASS_ND)) return FP_SUBNORMAL;
103 : if (flags & (_FPCLASS_PINF | _FPCLASS_NINF)) return FP_INFINITE;
104 :
105 : // All cases should be covered by the code above.
106 : ASSERT(flags & (_FPCLASS_SNAN | _FPCLASS_QNAN));
107 : return FP_NAN;
108 : }
109 :
110 :
111 : #endif // _MSC_VER
112 :
113 : #ifdef SOLARIS
114 :
115 : #include <ieeefp.h>
116 :
117 : // Classify floating point number
118 : int fpclassify(double x) {
119 :
120 : fpclass_t rv = fpclass(x);
121 :
122 : switch (rv) {
123 : case FP_SNAN:
124 : case FP_QNAN: return FP_NAN;
125 : case FP_NINF:
126 : case FP_PINF: return FP_INFINITE;
127 : case FP_NDENORM:
128 : case FP_PDENORM: return FP_SUBNORMAL;
129 : case FP_NZERO:
130 : case FP_PZERO: return FP_ZERO;
131 : default:
132 : ASSERT(rv == FP_NNORM || rv == FP_PNORM);
133 : return FP_NORMAL;
134 : }
135 :
136 : }
137 : #endif // SOLARIS
|