c7dbf0188ee61663143a86d4e4f47ab32c6aa599
[m6w6/ext-psi] / scripts / gen_calc_bin.php
1 <?php
2
3 include __DIR__."/_include.php";
4
5 $ops = [
6 "lshift" => "<<",
7 "rshift" => ">>",
8 "and" => "&",
9 "xor" => "^",
10 "or" => "|",
11 ];
12
13 ?>
14
15 <?php foreach ($ops as $op_name => $op) : ?>
16
17 static inline token_t psi_calc_bin_<?=$op_name?>(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
18 {
19 impl_val i1, i2;
20
21 switch (t1) {<?php /*nobr*/ ?>
22 <?php foreach ($types as $t1 => $v1) : ?>
23 <?php if (t_is_special($t1)) :?>
24
25 #if HAVE_<?=$t1?>
26 <?php endif; ?>
27
28 case PSI_T_<?=$t1?>:
29 i1.u64 = v1-><?=$v1?>;
30 break;
31 <?php if (t_is_special($t1)) : ?>
32
33 #endif
34 <?php endif; ?>
35 <?php endforeach; ?>
36
37 default:
38 assert(0);
39 break;
40 }
41
42 switch (t2) {<?php /*nobr*/ ?>
43 <?php foreach ($types as $t2 => $v2) : ?>
44 <?php if (t_is_special($t2)) :?>
45
46 #if HAVE_<?=$t2?>
47 <?php endif; ?>
48
49 case PSI_T_<?=$t2?>:
50 i2.u64 = v2-><?=$v2?>;
51 break;<?php /*nobr*/ ?>
52 <?php endforeach; ?>
53 <?php if (t_is_special($t2)) : ?>
54
55 #endif
56 <?php endif; ?>
57
58 default:
59 assert(0);
60 break;
61 }
62
63 res->u64 = i1.u64 <?=$op?> i2.u64;
64 return PSI_T_UINT64;
65 }
66 <?php endforeach; ?>
67
68 static inline token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
69 {
70 impl_val i1;
71
72 (void) t2;
73 (void) v2;
74
75 switch (t1) {<?php /*nobr*/ ?>
76 <?php foreach ($types as $t1 => $v1) : ?>
77 <?php if (t_is_special($t1)) :?>
78
79 #if HAVE_<?=$t1?>
80 <?php endif; ?>
81
82 case PSI_T_<?=$t1?>:
83 i1.u64 = v1-><?=$v1?>;
84 break;
85 <?php if (t_is_special($t1)) : ?>
86
87 #endif
88 <?php endif; ?>
89 <?php endforeach; ?>
90
91 default:
92 assert(0);
93 break;
94 }
95
96 res->u64 = ~i1.u64;
97 return PSI_T_UINT64;
98 }