ifdef HAVE_INT128
[m6w6/ext-psi] / src / calc / unary.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #include "php_psi_stdinc.h"
27 #include <assert.h>
28
29 #include "token.h"
30 static inline token_t psi_calc_minus(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
31 {
32 (void) t2;
33 (void) v2;
34
35 switch (t1) {
36 case PSI_T_INT8:
37 res->i8 = -v1->i8;
38 break;
39 case PSI_T_UINT8:
40 res->u8 = -v1->u8;
41 break;
42 case PSI_T_INT16:
43 res->i16 = -v1->i16;
44 break;
45 case PSI_T_UINT16:
46 res->u16 = -v1->u16;
47 break;
48 case PSI_T_INT32:
49 res->i32 = -v1->i32;
50 break;
51 case PSI_T_UINT32:
52 res->u32 = -v1->u32;
53 break;
54 case PSI_T_INT64:
55 res->i64 = -v1->i64;
56 break;
57 case PSI_T_UINT64:
58 res->u64 = -v1->u64;
59 break;
60 #if HAVE_INT128
61 case PSI_T_INT128:
62 res->i128 = -v1->i128;
63 break;
64 #endif
65
66 #if HAVE_UINT128
67 case PSI_T_UINT128:
68 res->u128 = -v1->u128;
69 break;
70 #endif
71
72 case PSI_T_FLOAT:
73 res->fval = -v1->fval;
74 break;
75 case PSI_T_DOUBLE:
76 res->dval = -v1->dval;
77 break;
78 #if HAVE_LONG_DOUBLE
79 case PSI_T_LONG_DOUBLE:
80 res->ldval = -v1->ldval;
81 break;
82 #endif
83
84 default:
85 assert(0);
86 break;
87 }
88 return t1;
89 }
90
91
92 static inline token_t psi_calc_bool_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
93 {
94 (void) t2;
95 (void) v2;
96
97 switch (t1) {
98 case PSI_T_INT8:
99 res->u8 = !v1->i8;
100 break;
101 case PSI_T_UINT8:
102 res->u8 = !v1->u8;
103 break;
104 case PSI_T_INT16:
105 res->u8 = !v1->i16;
106 break;
107 case PSI_T_UINT16:
108 res->u8 = !v1->u16;
109 break;
110 case PSI_T_INT32:
111 res->u8 = !v1->i32;
112 break;
113 case PSI_T_UINT32:
114 res->u8 = !v1->u32;
115 break;
116 case PSI_T_INT64:
117 res->u8 = !v1->i64;
118 break;
119 case PSI_T_UINT64:
120 res->u8 = !v1->u64;
121 break;
122 #if HAVE_INT128
123 case PSI_T_INT128:
124 res->u8 = !v1->i128;
125 break;
126 #endif
127
128 #if HAVE_UINT128
129 case PSI_T_UINT128:
130 res->u8 = !v1->u128;
131 break;
132 #endif
133
134 case PSI_T_FLOAT:
135 res->u8 = !v1->fval;
136 break;
137 case PSI_T_DOUBLE:
138 res->u8 = !v1->dval;
139 break;
140 #if HAVE_LONG_DOUBLE
141 case PSI_T_LONG_DOUBLE:
142 res->u8 = !v1->ldval;
143 break;
144 #endif
145
146 default:
147 assert(0);
148 break;
149 }
150 return PSI_T_UINT8;
151 }
152
153
154 static inline token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
155 {
156 impl_val i1;
157
158 (void) t2;
159 (void) v2;
160
161 switch (t1) {
162 case PSI_T_INT8:
163 i1.u64 = v1->i8;
164 break;
165
166 case PSI_T_UINT8:
167 i1.u64 = v1->u8;
168 break;
169
170 case PSI_T_INT16:
171 i1.u64 = v1->i16;
172 break;
173
174 case PSI_T_UINT16:
175 i1.u64 = v1->u16;
176 break;
177
178 case PSI_T_INT32:
179 i1.u64 = v1->i32;
180 break;
181
182 case PSI_T_UINT32:
183 i1.u64 = v1->u32;
184 break;
185
186 case PSI_T_INT64:
187 i1.u64 = v1->i64;
188 break;
189
190 case PSI_T_UINT64:
191 i1.u64 = v1->u64;
192 break;
193
194 #if HAVE_INT128
195 case PSI_T_INT128:
196 i1.u64 = v1->i128;
197 break;
198
199 #endif
200
201 #if HAVE_UINT128
202 case PSI_T_UINT128:
203 i1.u64 = v1->u128;
204 break;
205
206 #endif
207
208 case PSI_T_FLOAT:
209 i1.u64 = v1->fval;
210 break;
211
212 case PSI_T_DOUBLE:
213 i1.u64 = v1->dval;
214 break;
215
216 #if HAVE_LONG_DOUBLE
217 case PSI_T_LONG_DOUBLE:
218 i1.u64 = v1->ldval;
219 break;
220
221 #endif
222
223 default:
224 assert(0);
225 break;
226 }
227
228 res->u64 = ~i1.u64;
229 return PSI_T_UINT64;
230 }