Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / js / src / jslong.h
blob4a1fccc9ea39d9579e58123081f742cb6bcef589
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 ** File: jslong.h
41 ** Description: Portable access to 64 bit numerics
43 ** Long-long (64-bit signed integer type) support. Some C compilers
44 ** don't support 64 bit integers yet, so we use these macros to
45 ** support both machines that do and don't.
46 **/
47 #ifndef jslong_h___
48 #define jslong_h___
50 #include "jstypes.h"
52 JS_BEGIN_EXTERN_C
54 #define JSLL_INIT(hi, lo) ((((JSInt64)(hi)) << 32) + (JSInt64)(lo))
56 /***********************************************************************
57 ** MACROS: JSLL_*
58 ** DESCRIPTION:
59 ** The following macros define portable access to the 64 bit
60 ** math facilities.
62 ***********************************************************************/
64 /***********************************************************************
65 ** MACROS: JSLL_<relational operators>
67 ** JSLL_IS_ZERO Test for zero
68 ** JSLL_EQ Test for equality
69 ** JSLL_NE Test for inequality
70 ** JSLL_GE_ZERO Test for zero or positive
71 ** JSLL_CMP Compare two values
72 ***********************************************************************/
73 #define JSLL_IS_ZERO(a) ((a) == 0)
74 #define JSLL_EQ(a, b) ((a) == (b))
75 #define JSLL_NE(a, b) ((a) != (b))
76 #define JSLL_GE_ZERO(a) ((a) >= 0)
77 #define JSLL_CMP(a, op, b) ((JSInt64)(a) op (JSInt64)(b))
78 #define JSLL_UCMP(a, op, b) ((JSUint64)(a) op (JSUint64)(b))
80 /***********************************************************************
81 ** MACROS: JSLL_<logical operators>
83 ** JSLL_AND Logical and
84 ** JSLL_OR Logical or
85 ** JSLL_XOR Logical exclusion
86 ** JSLL_OR2 A disgusting deviation
87 ** JSLL_NOT Negation (one's compliment)
88 ***********************************************************************/
89 #define JSLL_AND(r, a, b) ((r) = (a) & (b))
90 #define JSLL_OR(r, a, b) ((r) = (a) | (b))
91 #define JSLL_XOR(r, a, b) ((r) = (a) ^ (b))
92 #define JSLL_OR2(r, a) ((r) = (r) | (a))
93 #define JSLL_NOT(r, a) ((r) = ~(a))
95 /***********************************************************************
96 ** MACROS: JSLL_<mathematical operators>
98 ** JSLL_NEG Negation (two's compliment)
99 ** JSLL_ADD Summation (two's compliment)
100 ** JSLL_SUB Difference (two's compliment)
101 ***********************************************************************/
102 #define JSLL_NEG(r, a) ((r) = -(a))
103 #define JSLL_ADD(r, a, b) ((r) = (a) + (b))
104 #define JSLL_SUB(r, a, b) ((r) = (a) - (b))
106 /***********************************************************************
107 ** MACROS: JSLL_<mathematical operators>
109 ** JSLL_MUL Product (two's compliment)
110 ** JSLL_DIV Quotient (two's compliment)
111 ** JSLL_MOD Modulus (two's compliment)
112 ***********************************************************************/
113 #define JSLL_MUL(r, a, b) ((r) = (a) * (b))
114 #define JSLL_DIV(r, a, b) ((r) = (a) / (b))
115 #define JSLL_MOD(r, a, b) ((r) = (a) % (b))
117 /***********************************************************************
118 ** MACROS: JSLL_<shifting operators>
120 ** JSLL_SHL Shift left [0..64] bits
121 ** JSLL_SHR Shift right [0..64] bits with sign extension
122 ** JSLL_USHR Unsigned shift right [0..64] bits
123 ** JSLL_ISHL Signed shift left [0..64] bits
124 ***********************************************************************/
125 #define JSLL_SHL(r, a, b) ((r) = (JSInt64)(a) << (b))
126 #define JSLL_SHR(r, a, b) ((r) = (JSInt64)(a) >> (b))
127 #define JSLL_USHR(r, a, b) ((r) = (JSUint64)(a) >> (b))
128 #define JSLL_ISHL(r, a, b) ((r) = (JSInt64)(a) << (b))
130 /***********************************************************************
131 ** MACROS: JSLL_<conversion operators>
133 ** JSLL_L2I Convert to signed 32 bit
134 ** JSLL_L2UI Convert to unsigned 32 bit
135 ** JSLL_L2F Convert to floating point
136 ** JSLL_L2D Convert to floating point
137 ** JSLL_I2L Convert signed to 64 bit
138 ** JSLL_UI2L Convert unsigned to 64 bit
139 ** JSLL_F2L Convert float to 64 bit
140 ** JSLL_D2L Convert float to 64 bit
141 ***********************************************************************/
142 #define JSLL_L2I(i, l) ((i) = (JSInt32)(l))
143 #define JSLL_L2UI(ui, l) ((ui) = (JSUint32)(l))
144 #define JSLL_L2F(f, l) ((f) = (JSFloat64)(l))
145 #define JSLL_L2D(d, l) ((d) = (JSFloat64)(l))
147 #define JSLL_I2L(l, i) ((l) = (JSInt64)(i))
148 #define JSLL_UI2L(l, ui) ((l) = (JSInt64)(ui))
149 #define JSLL_F2L(l, f) ((l) = (JSInt64)(f))
150 #define JSLL_D2L(l, d) ((l) = (JSInt64)(d))
152 /***********************************************************************
153 ** MACROS: JSLL_UDIVMOD
154 ** DESCRIPTION:
155 ** Produce both a quotient and a remainder given an unsigned
156 ** INPUTS: JSUint64 a: The dividend of the operation
157 ** JSUint64 b: The quotient of the operation
158 ** OUTPUTS: JSUint64 *qp: pointer to quotient
159 ** JSUint64 *rp: pointer to remainder
160 ***********************************************************************/
161 #define JSLL_UDIVMOD(qp, rp, a, b) \
162 (*(qp) = ((JSUint64)(a) / (b)), \
163 *(rp) = ((JSUint64)(a) % (b)))
165 JS_END_EXTERN_C
167 #endif /* jslong_h___ */