build administrativa
[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 <assert.h>
27
28 #include "token.h"
29 static inline token_t psi_calc_minus(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
30 {
31 (void) t2;
32 (void) v2;
33
34 switch (t1) {
35 case PSI_T_INT8:
36 res->i8 = -v1->i8;
37 break;
38 case PSI_T_UINT8:
39 res->u8 = -v1->u8;
40 break;
41 case PSI_T_INT16:
42 res->i16 = -v1->i16;
43 break;
44 case PSI_T_UINT16:
45 res->u16 = -v1->u16;
46 break;
47 case PSI_T_INT32:
48 res->i32 = -v1->i32;
49 break;
50 case PSI_T_UINT32:
51 res->u32 = -v1->u32;
52 break;
53 case PSI_T_INT64:
54 res->i64 = -v1->i64;
55 break;
56 case PSI_T_UINT64:
57 res->u64 = -v1->u64;
58 break;
59 #if HAVE_INT128
60 case PSI_T_INT128:
61 res->i128 = -v1->i128;
62 break;
63 #endif
64
65 #if HAVE_UINT128
66 case PSI_T_UINT128:
67 res->u128 = -v1->u128;
68 break;
69 #endif
70
71 case PSI_T_FLOAT:
72 res->fval = -v1->fval;
73 break;
74 case PSI_T_DOUBLE:
75 res->dval = -v1->dval;
76 break;
77 #if HAVE_LONG_DOUBLE
78 case PSI_T_LONG_DOUBLE:
79 res->ldval = -v1->ldval;
80 break;
81 #endif
82
83 default:
84 assert(0);
85 break;
86 }
87 return t1;
88 }
89
90
91 static inline token_t psi_calc_bool_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
92 {
93 (void) t2;
94 (void) v2;
95
96 switch (t1) {
97 case PSI_T_INT8:
98 res->u8 = !v1->i8;
99 break;
100 case PSI_T_UINT8:
101 res->u8 = !v1->u8;
102 break;
103 case PSI_T_INT16:
104 res->u8 = !v1->i16;
105 break;
106 case PSI_T_UINT16:
107 res->u8 = !v1->u16;
108 break;
109 case PSI_T_INT32:
110 res->u8 = !v1->i32;
111 break;
112 case PSI_T_UINT32:
113 res->u8 = !v1->u32;
114 break;
115 case PSI_T_INT64:
116 res->u8 = !v1->i64;
117 break;
118 case PSI_T_UINT64:
119 res->u8 = !v1->u64;
120 break;
121 #if HAVE_INT128
122 case PSI_T_INT128:
123 res->u8 = !v1->i128;
124 break;
125 #endif
126
127 #if HAVE_UINT128
128 case PSI_T_UINT128:
129 res->u8 = !v1->u128;
130 break;
131 #endif
132
133 case PSI_T_FLOAT:
134 res->u8 = !v1->fval;
135 break;
136 case PSI_T_DOUBLE:
137 res->u8 = !v1->dval;
138 break;
139 #if HAVE_LONG_DOUBLE
140 case PSI_T_LONG_DOUBLE:
141 res->u8 = !v1->ldval;
142 break;
143 #endif
144
145 default:
146 assert(0);
147 break;
148 }
149 return PSI_T_UINT8;
150 }
151
152
153 static inline token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
154 {
155 impl_val i1;
156
157 (void) t2;
158 (void) v2;
159
160 switch (t1) {
161 case PSI_T_INT8:
162 i1.u64 = v1->i8;
163 break;
164
165 case PSI_T_UINT8:
166 i1.u64 = v1->u8;
167 break;
168
169 case PSI_T_INT16:
170 i1.u64 = v1->i16;
171 break;
172
173 case PSI_T_UINT16:
174 i1.u64 = v1->u16;
175 break;
176
177 case PSI_T_INT32:
178 i1.u64 = v1->i32;
179 break;
180
181 case PSI_T_UINT32:
182 i1.u64 = v1->u32;
183 break;
184
185 case PSI_T_INT64:
186 i1.u64 = v1->i64;
187 break;
188
189 case PSI_T_UINT64:
190 i1.u64 = v1->u64;
191 break;
192
193 #if HAVE_INT128
194 case PSI_T_INT128:
195 i1.u64 = v1->i128;
196 break;
197
198 #endif
199
200 #if HAVE_UINT128
201 case PSI_T_UINT128:
202 i1.u64 = v1->u128;
203 break;
204
205 #endif
206
207 case PSI_T_FLOAT:
208 i1.u64 = v1->fval;
209 break;
210
211 case PSI_T_DOUBLE:
212 i1.u64 = v1->dval;
213 break;
214
215 #if HAVE_LONG_DOUBLE
216 case PSI_T_LONG_DOUBLE:
217 i1.u64 = v1->ldval;
218 break;
219
220 #endif
221
222 default:
223 assert(0);
224 break;
225 }
226
227 res->u64 = ~i1.u64;
228 return PSI_T_UINT64;
229 }