carray 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +568 -0
  3. data/README.md +6 -6
  4. data/carray.gemspec +1 -1
  5. data/ext/ca_axis_descriptor.h +27 -24
  6. data/ext/ca_axis_dispatch.c +220 -0
  7. data/ext/ca_axis_group.c +201 -123
  8. data/ext/ca_binop_dispatch.c +46 -52
  9. data/ext/ca_binop_dispatch.h +1 -1
  10. data/ext/ca_categorical_iterator.c +249 -183
  11. data/ext/ca_compare.c +7 -12
  12. data/ext/ca_for_buffer.h +21 -68
  13. data/ext/ca_group_iter.c +38 -23
  14. data/ext/ca_kernel_iterator.c +1765 -2076
  15. data/ext/ca_kernel_iterator.h +584 -566
  16. data/ext/ca_monop_dispatch.c +86 -63
  17. data/ext/ca_monop_dispatch.h +5 -0
  18. data/ext/ca_obj_array.c +223 -56
  19. data/ext/ca_obj_bincmp.c +172 -138
  20. data/ext/ca_obj_binop.c +116 -230
  21. data/ext/ca_obj_bitarray.c +40 -26
  22. data/ext/ca_obj_bitfield.c +100 -68
  23. data/ext/ca_obj_block.c +19 -9
  24. data/ext/ca_obj_byte_swap.c +45 -46
  25. data/ext/ca_obj_const_string.c +269 -44
  26. data/ext/ca_obj_face.c +612 -89
  27. data/ext/ca_obj_face.h +111 -47
  28. data/ext/ca_obj_fake.c +36 -79
  29. data/ext/ca_obj_farray.c +7 -3
  30. data/ext/ca_obj_field.c +33 -8
  31. data/ext/ca_obj_fixlen_string.c +23 -24
  32. data/ext/ca_obj_grid.c +541 -210
  33. data/ext/ca_obj_meld.c +331 -111
  34. data/ext/ca_obj_moncmp.c +80 -65
  35. data/ext/ca_obj_monop.c +177 -149
  36. data/ext/ca_obj_object.c +664 -248
  37. data/ext/ca_obj_record.c +63 -23
  38. data/ext/ca_obj_reduce.c +18 -16
  39. data/ext/ca_obj_refer.c +140 -58
  40. data/ext/ca_obj_remap.c +85 -24
  41. data/ext/ca_obj_repeat.c +24 -9
  42. data/ext/ca_obj_roll.c +121 -16
  43. data/ext/ca_obj_select.c +61 -58
  44. data/ext/ca_obj_select_axis.c +73 -107
  45. data/ext/ca_obj_shift.c +32 -102
  46. data/ext/ca_obj_stack.c +372 -122
  47. data/ext/ca_obj_stride.c +348 -140
  48. data/ext/ca_obj_string.c +88 -22
  49. data/ext/ca_obj_tile.c +38 -21
  50. data/ext/ca_obj_time.c +45 -31
  51. data/ext/ca_obj_timedelta.c +43 -29
  52. data/ext/ca_obj_transpose.c +17 -6
  53. data/ext/ca_obj_triop.c +125 -141
  54. data/ext/ca_obj_window.c +330 -44
  55. data/ext/ca_op_ipower.c +24 -11
  56. data/ext/ca_op_powi.h +57 -30
  57. data/ext/ca_pow5_table.h +656 -0
  58. data/ext/ca_sort_kernels.h +70 -0
  59. data/ext/ca_sweep_engine.c +104 -81
  60. data/ext/ca_sweep_engine.h +7 -20
  61. data/ext/ca_triop_dispatch.c +4 -1
  62. data/ext/ca_triop_dispatch.h +5 -2
  63. data/ext/caframe_csv_reader.c +542 -0
  64. data/ext/carray.h +241 -92
  65. data/ext/carray_access.c +608 -276
  66. data/ext/carray_address_basis.c +494 -97
  67. data/ext/carray_attribute.c +129 -4
  68. data/ext/carray_bincount.c +39 -7
  69. data/ext/carray_broadcast.c +56 -19
  70. data/ext/carray_build_flags.h +1 -1
  71. data/ext/carray_call_cfunc.c +108 -28
  72. data/ext/carray_cast.c +1576 -223
  73. data/ext/carray_cast_func.rb +77 -24
  74. data/ext/carray_class.c +4 -3
  75. data/ext/carray_conversion.c +208 -75
  76. data/ext/carray_copy.c +82 -24
  77. data/ext/carray_core.c +646 -162
  78. data/ext/carray_count.c +171 -88
  79. data/ext/carray_element.c +94 -60
  80. data/ext/carray_factorize.c +670 -324
  81. data/ext/carray_generate.c +260 -83
  82. data/ext/carray_histogram.c +209 -106
  83. data/ext/carray_hold.c +14 -16
  84. data/ext/carray_index_classifier.c +422 -243
  85. data/ext/carray_internal.h +692 -3
  86. data/ext/carray_kernels_bincmp.c +7 -0
  87. data/ext/carray_kernels_binop.c +487 -120
  88. data/ext/carray_kernels_init.c +653 -50
  89. data/ext/carray_kernels_moncmp.c +15 -8
  90. data/ext/carray_kernels_monop.c +99 -43
  91. data/ext/carray_kernels_reduce_aggregate.c +3925 -6112
  92. data/ext/carray_kernels_reduce_boolean.c +112 -36
  93. data/ext/carray_kernels_reduce_cumulative.c +2127 -6903
  94. data/ext/carray_kernels_reduce_extreme.c +3032 -2892
  95. data/ext/carray_kernels_reduce_variance.c +439 -500
  96. data/ext/carray_kernels_scan.c +1097 -488
  97. data/ext/carray_kernels_search.c +3787 -2176
  98. data/ext/carray_kernels_sort.c +1200 -920
  99. data/ext/carray_kernels_triop.c +479 -7
  100. data/ext/carray_key_windows.c +216 -0
  101. data/ext/carray_lazy.c +967 -153
  102. data/ext/carray_loop.c +81 -65
  103. data/ext/carray_mask.c +910 -324
  104. data/ext/carray_math_kernel.h +1 -0
  105. data/ext/carray_median_percentile.c +299 -100
  106. data/ext/carray_memory_view.c +872 -758
  107. data/ext/carray_operator.c +1171 -364
  108. data/ext/carray_order.c +505 -133
  109. data/ext/carray_partition.c +112 -65
  110. data/ext/carray_random.c +327 -239
  111. data/ext/carray_round.c +273 -0
  112. data/ext/carray_scatter.c +346 -78
  113. data/ext/carray_segment.c +257 -0
  114. data/ext/carray_slab.c +249 -86
  115. data/ext/carray_sort.c +224 -227
  116. data/ext/carray_sort_kernel.c +8 -1
  117. data/ext/carray_struct.c +118 -39
  118. data/ext/carray_test.c +193 -69
  119. data/ext/carray_time_text.c +1182 -0
  120. data/ext/carray_undef.c +4 -0
  121. data/ext/carray_utils.c +579 -113
  122. data/ext/extconf.rb +27 -2
  123. data/ext/mk_call_cfunc.rb +19 -4
  124. data/ext/mk_pow5_table.rb +35 -0
  125. data/ext/mkkernel.rb +1202 -1014
  126. data/ext/ruby_carray.c +17 -5
  127. data/ext/version.h +4 -4
  128. data/ext/version.rb +4 -2
  129. data/lib/carray/attribute.rb +160 -17
  130. data/lib/carray/autoload_carray.rb +23 -27
  131. data/lib/carray/autoload_method_extension.rb +20 -5
  132. data/lib/carray/axis_group.rb +360 -63
  133. data/lib/carray/basics.rb +162 -28
  134. data/lib/carray/bincount_nd.rb +18 -2
  135. data/lib/carray/block_iterator.rb +231 -58
  136. data/lib/carray/boolean_reduce.rb +34 -42
  137. data/lib/carray/categorical.rb +242 -52
  138. data/lib/carray/categorical_iterator.rb +437 -827
  139. data/lib/carray/complex.rb +41 -34
  140. data/lib/carray/conditional.rb +150 -14
  141. data/lib/carray/const_string.rb +59 -4
  142. data/lib/carray/construct.rb +15 -11
  143. data/lib/carray/data_type_extension.rb +1 -0
  144. data/lib/carray/distance_limit.rb +77 -0
  145. data/lib/carray/fixlen_string.rb +7 -1
  146. data/lib/carray/frame/column_verbs.rb +70 -0
  147. data/lib/carray/frame/concat.rb +157 -6
  148. data/lib/carray/frame/convert.rb +82 -7
  149. data/lib/carray/frame/csv_parser.rb +688 -87
  150. data/lib/carray/frame/describe.rb +80 -0
  151. data/lib/carray/frame/frame.rb +369 -45
  152. data/lib/carray/frame/group.rb +631 -90
  153. data/lib/carray/frame/io.rb +506 -79
  154. data/lib/carray/frame/join.rb +411 -62
  155. data/lib/carray/frame/records.rb +116 -19
  156. data/lib/carray/frame/reshape.rb +455 -0
  157. data/lib/carray/frame/sort.rb +30 -18
  158. data/lib/carray/frame/verbs.rb +868 -61
  159. data/lib/carray/frame/windows.rb +117 -0
  160. data/lib/carray/frame.rb +4 -0
  161. data/lib/carray/fuse_source.rb +118 -2
  162. data/lib/carray/fusion.rb +257 -42
  163. data/lib/carray/histogram.rb +6 -1
  164. data/lib/carray/inspect.rb +54 -13
  165. data/lib/carray/iterator.rb +99 -9
  166. data/lib/carray/key_windows.rb +620 -0
  167. data/lib/carray/lazy.rb +216 -193
  168. data/lib/carray/mask_gap_fill.rb +112 -92
  169. data/lib/carray/math.rb +32 -19
  170. data/lib/carray/meld_reduce.rb +52 -21
  171. data/lib/carray/methods/align_addr.rb +8 -4
  172. data/lib/carray/methods/bin.rb +26 -18
  173. data/lib/carray/methods/bincount.rb +18 -2
  174. data/lib/carray/methods/bit_string.rb +15 -4
  175. data/lib/carray/methods/choose.rb +16 -3
  176. data/lib/carray/methods/composition.rb +18 -10
  177. data/lib/carray/methods/factorize.rb +2 -2
  178. data/lib/carray/methods/gather_nd.rb +25 -5
  179. data/lib/carray/methods/insert_block.rb +9 -14
  180. data/lib/carray/methods/is_between.rb +59 -0
  181. data/lib/carray/methods/is_in.rb +140 -10
  182. data/lib/carray/methods/join.rb +2 -7
  183. data/lib/carray/methods/lag.rb +49 -0
  184. data/lib/carray/methods/locate_addr.rb +182 -45
  185. data/lib/carray/methods/mode.rb +18 -1
  186. data/lib/carray/methods/nunique.rb +11 -6
  187. data/lib/carray/methods/repeat.rb +1 -20
  188. data/lib/carray/methods/resize.rb +21 -23
  189. data/lib/carray/methods/snap.rb +34 -12
  190. data/lib/carray/methods/unique.rb +11 -2
  191. data/lib/carray/methods/value_counts.rb +4 -11
  192. data/lib/carray/record_order.rb +208 -0
  193. data/lib/carray/rng.rb +3 -0
  194. data/lib/carray/runtime.rb +65 -17
  195. data/lib/carray/segment_iterator.rb +1221 -0
  196. data/lib/carray/serialize.rb +214 -30
  197. data/lib/carray/slab_iterator.rb +101 -27
  198. data/lib/carray/stack.rb +10 -4
  199. data/lib/carray/string.rb +105 -5
  200. data/lib/carray/string_operation_extension.rb +12 -4
  201. data/lib/carray/struct.rb +137 -58
  202. data/lib/carray/struct_builder.rb +124 -17
  203. data/lib/carray/time.rb +1222 -186
  204. data/lib/carray/window_iterator.rb +242 -81
  205. data/lib/carray.rb +9 -2
  206. data/yard-stubs/ca_obj_array.rb +4 -4
  207. data/yard-stubs/ca_obj_bitarray.rb +7 -0
  208. data/yard-stubs/ca_obj_bitfield.rb +23 -12
  209. data/yard-stubs/ca_obj_fake.rb +1 -1
  210. data/yard-stubs/ca_obj_field.rb +5 -1
  211. data/yard-stubs/ca_obj_grid.rb +21 -10
  212. data/yard-stubs/ca_obj_refer.rb +5 -4
  213. data/yard-stubs/ca_obj_roll.rb +2 -3
  214. data/yard-stubs/ca_obj_shift.rb +5 -1
  215. data/yard-stubs/ca_obj_stride.rb +10 -7
  216. data/yard-stubs/ca_obj_tile.rb +1 -1
  217. data/yard-stubs/ca_obj_transpose.rb +1 -1
  218. data/yard-stubs/ca_obj_window.rb +9 -5
  219. data/yard-stubs/carray_access.rb +11 -5
  220. data/yard-stubs/carray_attribute.rb +0 -5
  221. data/yard-stubs/carray_broadcast.rb +1 -1
  222. data/yard-stubs/carray_cast.rb +88 -43
  223. data/yard-stubs/carray_conversion.rb +15 -2
  224. data/yard-stubs/carray_copy.rb +12 -5
  225. data/yard-stubs/carray_core.rb +3 -3
  226. data/yard-stubs/carray_count.rb +9 -0
  227. data/yard-stubs/carray_element.rb +10 -4
  228. data/yard-stubs/carray_generate.rb +21 -1
  229. data/yard-stubs/carray_lazy.rb +5 -1
  230. data/yard-stubs/carray_loop.rb +4 -1
  231. data/yard-stubs/carray_mask.rb +60 -12
  232. data/yard-stubs/carray_math.rb +52 -14
  233. data/yard-stubs/carray_median_percentile.rb +15 -8
  234. data/yard-stubs/carray_memory_view.rb +40 -23
  235. data/yard-stubs/carray_order.rb +61 -29
  236. data/yard-stubs/carray_random.rb +13 -4
  237. data/yard-stubs/carray_scatter.rb +21 -9
  238. data/yard-stubs/carray_segment.rb +72 -0
  239. data/yard-stubs/carray_slab.rb +10 -2
  240. data/yard-stubs/carray_sort.rb +49 -8
  241. data/yard-stubs/carray_test.rb +15 -3
  242. data/yard-stubs/carray_utils.rb +0 -26
  243. metadata +19 -5
  244. data/ext/ca_for_each_element.h +0 -239
  245. data/ext/carray_kernels_map.c +0 -3467
  246. data/lib/carray/arrow_tensor.rb +0 -401
  247. data/lib/carray/table.rb +0 -108
@@ -3,10 +3,9 @@
3
3
 
4
4
  void Init_carray_kernels_reduce_aggregate (void);
5
5
  void Init_carray_kernels_reduce_extreme (void);
6
- void Init_carray_kernels_reduce_cumulative (void);
7
6
  void Init_carray_kernels_reduce_boolean (void);
8
7
  void Init_carray_kernels_reduce_variance (void);
9
- void Init_carray_kernels_map (void);
8
+ void Init_carray_kernels_reduce_cumulative (void);
10
9
  void Init_carray_kernels_scan (void);
11
10
  void Init_carray_kernels_sort (void);
12
11
  void Init_carray_kernels_search (void);
@@ -28,6 +27,262 @@ typedef struct {
28
27
  } ca_kernel_body_t;
29
28
 
30
29
  static const ca_kernel_body_t ca_kernel_bodies[] = {
30
+ { "binop", "ipow", "float32",
31
+ "(#3) = op_powi_<type>((#1), (#2));" },
32
+ { "binop", "ipow", "float64",
33
+ "(#3) = op_powi_<type>((#1), (#2));" },
34
+ { "binop", "ipow", "cmplx64",
35
+ "(#3) = op_powi_<type>((#1), (#2));" },
36
+ { "binop", "ipow", "cmplx128",
37
+ "(#3) = op_powi_<type>((#1), (#2));" },
38
+ { "monop", "cast_int8", "boolean",
39
+ "(#2) = (int8_t)(#1);" },
40
+ { "monop", "cast_uint8", "boolean",
41
+ "(#2) = (uint8_t)(#1);" },
42
+ { "monop", "cast_int16", "boolean",
43
+ "(#2) = (int16_t)(#1);" },
44
+ { "monop", "cast_uint16", "boolean",
45
+ "(#2) = (uint16_t)(#1);" },
46
+ { "monop", "cast_int32", "boolean",
47
+ "(#2) = (int32_t)(#1);" },
48
+ { "monop", "cast_uint32", "boolean",
49
+ "(#2) = (uint32_t)(#1);" },
50
+ { "monop", "cast_int64", "boolean",
51
+ "(#2) = (int64_t)(#1);" },
52
+ { "monop", "cast_uint64", "boolean",
53
+ "(#2) = (uint64_t)(#1);" },
54
+ { "monop", "cast_float32", "boolean",
55
+ "(#2) = (float)(#1);" },
56
+ { "monop", "cast_float64", "boolean",
57
+ "(#2) = (double)(#1);" },
58
+ { "monop", "cast_cmplx64", "boolean",
59
+ "(#2) = (cmplx64_t)(#1);" },
60
+ { "monop", "cast_cmplx128", "boolean",
61
+ "(#2) = (cmplx128_t)(#1);" },
62
+ { "monop", "cast_int8", "int8",
63
+ "(#2) = (int8_t)(#1);" },
64
+ { "monop", "cast_uint8", "int8",
65
+ "(#2) = (uint8_t)(#1);" },
66
+ { "monop", "cast_int16", "int8",
67
+ "(#2) = (int16_t)(#1);" },
68
+ { "monop", "cast_uint16", "int8",
69
+ "(#2) = (uint16_t)(#1);" },
70
+ { "monop", "cast_int32", "int8",
71
+ "(#2) = (int32_t)(#1);" },
72
+ { "monop", "cast_uint32", "int8",
73
+ "(#2) = (uint32_t)(#1);" },
74
+ { "monop", "cast_int64", "int8",
75
+ "(#2) = (int64_t)(#1);" },
76
+ { "monop", "cast_uint64", "int8",
77
+ "(#2) = (uint64_t)(#1);" },
78
+ { "monop", "cast_float32", "int8",
79
+ "(#2) = (float)(#1);" },
80
+ { "monop", "cast_float64", "int8",
81
+ "(#2) = (double)(#1);" },
82
+ { "monop", "cast_cmplx64", "int8",
83
+ "(#2) = (cmplx64_t)(#1);" },
84
+ { "monop", "cast_cmplx128", "int8",
85
+ "(#2) = (cmplx128_t)(#1);" },
86
+ { "monop", "cast_int8", "uint8",
87
+ "(#2) = (int8_t)(#1);" },
88
+ { "monop", "cast_uint8", "uint8",
89
+ "(#2) = (uint8_t)(#1);" },
90
+ { "monop", "cast_int16", "uint8",
91
+ "(#2) = (int16_t)(#1);" },
92
+ { "monop", "cast_uint16", "uint8",
93
+ "(#2) = (uint16_t)(#1);" },
94
+ { "monop", "cast_int32", "uint8",
95
+ "(#2) = (int32_t)(#1);" },
96
+ { "monop", "cast_uint32", "uint8",
97
+ "(#2) = (uint32_t)(#1);" },
98
+ { "monop", "cast_int64", "uint8",
99
+ "(#2) = (int64_t)(#1);" },
100
+ { "monop", "cast_uint64", "uint8",
101
+ "(#2) = (uint64_t)(#1);" },
102
+ { "monop", "cast_float32", "uint8",
103
+ "(#2) = (float)(#1);" },
104
+ { "monop", "cast_float64", "uint8",
105
+ "(#2) = (double)(#1);" },
106
+ { "monop", "cast_cmplx64", "uint8",
107
+ "(#2) = (cmplx64_t)(#1);" },
108
+ { "monop", "cast_cmplx128", "uint8",
109
+ "(#2) = (cmplx128_t)(#1);" },
110
+ { "monop", "cast_int8", "int16",
111
+ "(#2) = (int8_t)(#1);" },
112
+ { "monop", "cast_uint8", "int16",
113
+ "(#2) = (uint8_t)(#1);" },
114
+ { "monop", "cast_int16", "int16",
115
+ "(#2) = (int16_t)(#1);" },
116
+ { "monop", "cast_uint16", "int16",
117
+ "(#2) = (uint16_t)(#1);" },
118
+ { "monop", "cast_int32", "int16",
119
+ "(#2) = (int32_t)(#1);" },
120
+ { "monop", "cast_uint32", "int16",
121
+ "(#2) = (uint32_t)(#1);" },
122
+ { "monop", "cast_int64", "int16",
123
+ "(#2) = (int64_t)(#1);" },
124
+ { "monop", "cast_uint64", "int16",
125
+ "(#2) = (uint64_t)(#1);" },
126
+ { "monop", "cast_float32", "int16",
127
+ "(#2) = (float)(#1);" },
128
+ { "monop", "cast_float64", "int16",
129
+ "(#2) = (double)(#1);" },
130
+ { "monop", "cast_cmplx64", "int16",
131
+ "(#2) = (cmplx64_t)(#1);" },
132
+ { "monop", "cast_cmplx128", "int16",
133
+ "(#2) = (cmplx128_t)(#1);" },
134
+ { "monop", "cast_int8", "uint16",
135
+ "(#2) = (int8_t)(#1);" },
136
+ { "monop", "cast_uint8", "uint16",
137
+ "(#2) = (uint8_t)(#1);" },
138
+ { "monop", "cast_int16", "uint16",
139
+ "(#2) = (int16_t)(#1);" },
140
+ { "monop", "cast_uint16", "uint16",
141
+ "(#2) = (uint16_t)(#1);" },
142
+ { "monop", "cast_int32", "uint16",
143
+ "(#2) = (int32_t)(#1);" },
144
+ { "monop", "cast_uint32", "uint16",
145
+ "(#2) = (uint32_t)(#1);" },
146
+ { "monop", "cast_int64", "uint16",
147
+ "(#2) = (int64_t)(#1);" },
148
+ { "monop", "cast_uint64", "uint16",
149
+ "(#2) = (uint64_t)(#1);" },
150
+ { "monop", "cast_float32", "uint16",
151
+ "(#2) = (float)(#1);" },
152
+ { "monop", "cast_float64", "uint16",
153
+ "(#2) = (double)(#1);" },
154
+ { "monop", "cast_cmplx64", "uint16",
155
+ "(#2) = (cmplx64_t)(#1);" },
156
+ { "monop", "cast_cmplx128", "uint16",
157
+ "(#2) = (cmplx128_t)(#1);" },
158
+ { "monop", "cast_int8", "int32",
159
+ "(#2) = (int8_t)(#1);" },
160
+ { "monop", "cast_uint8", "int32",
161
+ "(#2) = (uint8_t)(#1);" },
162
+ { "monop", "cast_int16", "int32",
163
+ "(#2) = (int16_t)(#1);" },
164
+ { "monop", "cast_uint16", "int32",
165
+ "(#2) = (uint16_t)(#1);" },
166
+ { "monop", "cast_int32", "int32",
167
+ "(#2) = (int32_t)(#1);" },
168
+ { "monop", "cast_uint32", "int32",
169
+ "(#2) = (uint32_t)(#1);" },
170
+ { "monop", "cast_int64", "int32",
171
+ "(#2) = (int64_t)(#1);" },
172
+ { "monop", "cast_uint64", "int32",
173
+ "(#2) = (uint64_t)(#1);" },
174
+ { "monop", "cast_float32", "int32",
175
+ "(#2) = (float)(#1);" },
176
+ { "monop", "cast_float64", "int32",
177
+ "(#2) = (double)(#1);" },
178
+ { "monop", "cast_cmplx64", "int32",
179
+ "(#2) = (cmplx64_t)(#1);" },
180
+ { "monop", "cast_cmplx128", "int32",
181
+ "(#2) = (cmplx128_t)(#1);" },
182
+ { "monop", "cast_int8", "uint32",
183
+ "(#2) = (int8_t)(#1);" },
184
+ { "monop", "cast_uint8", "uint32",
185
+ "(#2) = (uint8_t)(#1);" },
186
+ { "monop", "cast_int16", "uint32",
187
+ "(#2) = (int16_t)(#1);" },
188
+ { "monop", "cast_uint16", "uint32",
189
+ "(#2) = (uint16_t)(#1);" },
190
+ { "monop", "cast_int32", "uint32",
191
+ "(#2) = (int32_t)(#1);" },
192
+ { "monop", "cast_uint32", "uint32",
193
+ "(#2) = (uint32_t)(#1);" },
194
+ { "monop", "cast_int64", "uint32",
195
+ "(#2) = (int64_t)(#1);" },
196
+ { "monop", "cast_uint64", "uint32",
197
+ "(#2) = (uint64_t)(#1);" },
198
+ { "monop", "cast_float32", "uint32",
199
+ "(#2) = (float)(#1);" },
200
+ { "monop", "cast_float64", "uint32",
201
+ "(#2) = (double)(#1);" },
202
+ { "monop", "cast_cmplx64", "uint32",
203
+ "(#2) = (cmplx64_t)(#1);" },
204
+ { "monop", "cast_cmplx128", "uint32",
205
+ "(#2) = (cmplx128_t)(#1);" },
206
+ { "monop", "cast_int8", "int64",
207
+ "(#2) = (int8_t)(#1);" },
208
+ { "monop", "cast_uint8", "int64",
209
+ "(#2) = (uint8_t)(#1);" },
210
+ { "monop", "cast_int16", "int64",
211
+ "(#2) = (int16_t)(#1);" },
212
+ { "monop", "cast_uint16", "int64",
213
+ "(#2) = (uint16_t)(#1);" },
214
+ { "monop", "cast_int32", "int64",
215
+ "(#2) = (int32_t)(#1);" },
216
+ { "monop", "cast_uint32", "int64",
217
+ "(#2) = (uint32_t)(#1);" },
218
+ { "monop", "cast_int64", "int64",
219
+ "(#2) = (int64_t)(#1);" },
220
+ { "monop", "cast_uint64", "int64",
221
+ "(#2) = (uint64_t)(#1);" },
222
+ { "monop", "cast_float32", "int64",
223
+ "(#2) = (float)(double)(#1);" },
224
+ { "monop", "cast_float64", "int64",
225
+ "(#2) = (double)(#1);" },
226
+ { "monop", "cast_cmplx64", "int64",
227
+ "(#2) = (cmplx64_t)(double)(#1);" },
228
+ { "monop", "cast_cmplx128", "int64",
229
+ "(#2) = (cmplx128_t)(#1);" },
230
+ { "monop", "cast_int8", "uint64",
231
+ "(#2) = (int8_t)(#1);" },
232
+ { "monop", "cast_uint8", "uint64",
233
+ "(#2) = (uint8_t)(#1);" },
234
+ { "monop", "cast_int16", "uint64",
235
+ "(#2) = (int16_t)(#1);" },
236
+ { "monop", "cast_uint16", "uint64",
237
+ "(#2) = (uint16_t)(#1);" },
238
+ { "monop", "cast_int32", "uint64",
239
+ "(#2) = (int32_t)(#1);" },
240
+ { "monop", "cast_uint32", "uint64",
241
+ "(#2) = (uint32_t)(#1);" },
242
+ { "monop", "cast_int64", "uint64",
243
+ "(#2) = (int64_t)(#1);" },
244
+ { "monop", "cast_uint64", "uint64",
245
+ "(#2) = (uint64_t)(#1);" },
246
+ { "monop", "cast_float32", "uint64",
247
+ "(#2) = (float)(double)(#1);" },
248
+ { "monop", "cast_float64", "uint64",
249
+ "(#2) = (double)(#1);" },
250
+ { "monop", "cast_cmplx64", "uint64",
251
+ "(#2) = (cmplx64_t)(double)(#1);" },
252
+ { "monop", "cast_cmplx128", "uint64",
253
+ "(#2) = (cmplx128_t)(#1);" },
254
+ { "monop", "cast_float32", "float32",
255
+ "(#2) = (float)(#1);" },
256
+ { "monop", "cast_float64", "float32",
257
+ "(#2) = (double)(#1);" },
258
+ { "monop", "cast_cmplx64", "float32",
259
+ "(#2) = (cmplx64_t)(#1);" },
260
+ { "monop", "cast_cmplx128", "float32",
261
+ "(#2) = (cmplx128_t)(#1);" },
262
+ { "monop", "cast_float32", "float64",
263
+ "(#2) = (float)(#1);" },
264
+ { "monop", "cast_float64", "float64",
265
+ "(#2) = (double)(#1);" },
266
+ { "monop", "cast_cmplx64", "float64",
267
+ "(#2) = (cmplx64_t)(#1);" },
268
+ { "monop", "cast_cmplx128", "float64",
269
+ "(#2) = (cmplx128_t)(#1);" },
270
+ { "monop", "cast_float32", "cmplx64",
271
+ "(#2) = (float)(#1);" },
272
+ { "monop", "cast_float64", "cmplx64",
273
+ "(#2) = (double)(#1);" },
274
+ { "monop", "cast_cmplx64", "cmplx64",
275
+ "(#2) = (cmplx64_t)(#1);" },
276
+ { "monop", "cast_cmplx128", "cmplx64",
277
+ "(#2) = (cmplx128_t)(#1);" },
278
+ { "monop", "cast_float32", "cmplx128",
279
+ "(#2) = (float)(#1);" },
280
+ { "monop", "cast_float64", "cmplx128",
281
+ "(#2) = (double)(#1);" },
282
+ { "monop", "cast_cmplx64", "cmplx128",
283
+ "(#2) = (cmplx64_t)(#1);" },
284
+ { "monop", "cast_cmplx128", "cmplx128",
285
+ "(#2) = (cmplx128_t)(#1);" },
31
286
  { "monop", "zero", "int8",
32
287
  "(#2) = 0;" },
33
288
  { "monop", "zero", "uint8",
@@ -313,7 +568,7 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
313
568
  { "monop", "imag_i", "cmplx128",
314
569
  "(#2) = cimag(#1);" },
315
570
  { "monop", "arg_i", "float32",
316
- "(#2) = cargf((cmplx64_t)(#1));" },
571
+ "(#2) = carg((cmplx128_t)(#1));" },
317
572
  { "monop", "arg_i", "float64",
318
573
  "(#2) = carg((cmplx128_t)(#1));" },
319
574
  { "monop", "arg_i", "cmplx64",
@@ -387,23 +642,23 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
387
642
  { "monop", "round", "uint64",
388
643
  "(#2) = (#1);" },
389
644
  { "monop", "round", "float32",
390
- "(#2) = ((#1)>0.0) ? floor((#1)+0.5) : ((#1)<0.0) ? ceil((#1)-0.5) : (#1);" },
645
+ "(#2) = round(#1);" },
391
646
  { "monop", "round", "float64",
392
- "(#2) = ((#1)>0.0) ? floor((#1)+0.5) : ((#1)<0.0) ? ceil((#1)-0.5) : (#1);" },
647
+ "(#2) = round(#1);" },
393
648
  { "monop", "rcp", "int8",
394
- "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
649
+ "if ((#1)==0) {ca_zerodiv();}; (#2) = ((#1)==1) ? 1 : ((#1) < 0) ? -1 : 0;" },
395
650
  { "monop", "rcp", "uint8",
396
651
  "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
397
652
  { "monop", "rcp", "int16",
398
- "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
653
+ "if ((#1)==0) {ca_zerodiv();}; (#2) = ((#1)==1) ? 1 : ((#1) < 0) ? -1 : 0;" },
399
654
  { "monop", "rcp", "uint16",
400
655
  "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
401
656
  { "monop", "rcp", "int32",
402
- "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
657
+ "if ((#1)==0) {ca_zerodiv();}; (#2) = ((#1)==1) ? 1 : ((#1) < 0) ? -1 : 0;" },
403
658
  { "monop", "rcp", "uint32",
404
659
  "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
405
660
  { "monop", "rcp", "int64",
406
- "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
661
+ "if ((#1)==0) {ca_zerodiv();}; (#2) = ((#1)==1) ? 1 : ((#1) < 0) ? -1 : 0;" },
407
662
  { "monop", "rcp", "uint64",
408
663
  "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);" },
409
664
  { "monop", "rcp", "float32",
@@ -695,9 +950,9 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
695
950
  { "binop", "maximum", "uint64",
696
951
  "(#3) = (#1) > (#2) ? (#1) : (#2);" },
697
952
  { "binop", "maximum", "float32",
698
- "(#3) = isnan(#1) ? (#1) : (isnan(#2) ? (#2) : ((#1) > (#2) ? (#1) : (#2)));" },
953
+ "(#3) = isnan(#1) ? (#1) : isnan(#2) ? (#2) : ((#1) > (#2) || ((#1) == (#2) && !signbit(#1))) ? (#1) : (#2);" },
699
954
  { "binop", "maximum", "float64",
700
- "(#3) = isnan(#1) ? (#1) : (isnan(#2) ? (#2) : ((#1) > (#2) ? (#1) : (#2)));" },
955
+ "(#3) = isnan(#1) ? (#1) : isnan(#2) ? (#2) : ((#1) > (#2) || ((#1) == (#2) && !signbit(#1))) ? (#1) : (#2);" },
701
956
  { "binop", "minimum", "int8",
702
957
  "(#3) = (#1) < (#2) ? (#1) : (#2);" },
703
958
  { "binop", "minimum", "uint8",
@@ -715,9 +970,9 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
715
970
  { "binop", "minimum", "uint64",
716
971
  "(#3) = (#1) < (#2) ? (#1) : (#2);" },
717
972
  { "binop", "minimum", "float32",
718
- "(#3) = isnan(#1) ? (#1) : (isnan(#2) ? (#2) : ((#1) < (#2) ? (#1) : (#2)));" },
973
+ "(#3) = isnan(#1) ? (#1) : isnan(#2) ? (#2) : ((#1) < (#2) || ((#1) == (#2) && signbit(#1))) ? (#1) : (#2);" },
719
974
  { "binop", "minimum", "float64",
720
- "(#3) = isnan(#1) ? (#1) : (isnan(#2) ? (#2) : ((#1) < (#2) ? (#1) : (#2)));" },
975
+ "(#3) = isnan(#1) ? (#1) : isnan(#2) ? (#2) : ((#1) < (#2) || ((#1) == (#2) && signbit(#1))) ? (#1) : (#2);" },
721
976
  { "binop", "add", "int8",
722
977
  "(#3) = (#1) + (#2);" },
723
978
  { "binop", "add", "uint8",
@@ -791,19 +1046,19 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
791
1046
  { "binop", "mul", "cmplx128",
792
1047
  "(#3) = (#1) * (#2);" },
793
1048
  { "binop", "div", "int8",
794
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
1049
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = (<type>) (0 - (uint64_t) (#1)); }\n else {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
795
1050
  { "binop", "div", "uint8",
796
1051
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) / (#2);" },
797
1052
  { "binop", "div", "int16",
798
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
1053
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = (<type>) (0 - (uint64_t) (#1)); }\n else {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
799
1054
  { "binop", "div", "uint16",
800
1055
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) / (#2);" },
801
1056
  { "binop", "div", "int32",
802
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
1057
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = (<type>) (0 - (uint64_t) (#1)); }\n else {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
803
1058
  { "binop", "div", "uint32",
804
1059
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) / (#2);" },
805
1060
  { "binop", "div", "int64",
806
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
1061
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = (<type>) (0 - (uint64_t) (#1)); }\n else {\n <type> _q = (#1) / (#2);\n if ( (#1) % (#2) != 0 && (((#1) < 0) != ((#2) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
807
1062
  { "binop", "div", "uint64",
808
1063
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) / (#2);" },
809
1064
  { "binop", "div", "float32",
@@ -815,19 +1070,19 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
815
1070
  { "binop", "div", "cmplx128",
816
1071
  "(#3) = (#1) / (#2);" },
817
1072
  { "binop", "rcp_mul", "int8",
818
- "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
1073
+ "\n if ((#1)==0) {ca_zerodiv();};\n if ((#1)==-1) { (#3) = (<type>) (0 - (uint64_t) (#2)); }\n else {\n <type> _q = (#2) / (#1);\n if ( (#2) % (#1) != 0 && (((#2) < 0) != ((#1) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
819
1074
  { "binop", "rcp_mul", "uint8",
820
1075
  "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
821
1076
  { "binop", "rcp_mul", "int16",
822
- "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
1077
+ "\n if ((#1)==0) {ca_zerodiv();};\n if ((#1)==-1) { (#3) = (<type>) (0 - (uint64_t) (#2)); }\n else {\n <type> _q = (#2) / (#1);\n if ( (#2) % (#1) != 0 && (((#2) < 0) != ((#1) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
823
1078
  { "binop", "rcp_mul", "uint16",
824
1079
  "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
825
1080
  { "binop", "rcp_mul", "int32",
826
- "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
1081
+ "\n if ((#1)==0) {ca_zerodiv();};\n if ((#1)==-1) { (#3) = (<type>) (0 - (uint64_t) (#2)); }\n else {\n <type> _q = (#2) / (#1);\n if ( (#2) % (#1) != 0 && (((#2) < 0) != ((#1) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
827
1082
  { "binop", "rcp_mul", "uint32",
828
1083
  "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
829
1084
  { "binop", "rcp_mul", "int64",
830
- "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
1085
+ "\n if ((#1)==0) {ca_zerodiv();};\n if ((#1)==-1) { (#3) = (<type>) (0 - (uint64_t) (#2)); }\n else {\n <type> _q = (#2) / (#1);\n if ( (#2) % (#1) != 0 && (((#2) < 0) != ((#1) < 0)) ) { _q -= 1; }\n (#3) = _q;\n }\n " },
831
1086
  { "binop", "rcp_mul", "uint64",
832
1087
  "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);" },
833
1088
  { "binop", "rcp_mul", "float32",
@@ -839,19 +1094,19 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
839
1094
  { "binop", "rcp_mul", "cmplx128",
840
1095
  "(#3) = (#2) / (#1);" },
841
1096
  { "binop", "mod", "int8",
842
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
1097
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = 0; }\n else {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
843
1098
  { "binop", "mod", "uint8",
844
1099
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
845
1100
  { "binop", "mod", "int16",
846
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
1101
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = 0; }\n else {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
847
1102
  { "binop", "mod", "uint16",
848
1103
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
849
1104
  { "binop", "mod", "int32",
850
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
1105
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = 0; }\n else {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
851
1106
  { "binop", "mod", "uint32",
852
1107
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
853
1108
  { "binop", "mod", "int64",
854
- "\n if ((#2)==0) {ca_zerodiv();};\n {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
1109
+ "\n if ((#2)==0) {ca_zerodiv();};\n if ((#2)==-1) { (#3) = 0; }\n else {\n <type> _r = (#1) % (#2);\n if ( _r != 0 && ((_r < 0) != ((#2) < 0)) ) { _r += (#2); }\n (#3) = _r;\n }\n " },
855
1110
  { "binop", "mod", "uint64",
856
1111
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
857
1112
  { "binop", "mod", "float32",
@@ -859,19 +1114,19 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
859
1114
  { "binop", "mod", "float64",
860
1115
  "\n {\n <type> _r = fmod((#1), (#2));\n if ( _r != 0 ) {\n if ( (_r < 0) != ((#2) < 0) ) { _r += (#2); }\n }\n else { _r = copysign((<type>) 0, (#2)); }\n (#3) = _r;\n }\n " },
861
1116
  { "binop", "fmod", "int8",
862
- "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
1117
+ "if ((#2)==0) {ca_zerodiv();}; (#3) = ((#2)==-1) ? 0 : (#1) % (#2);" },
863
1118
  { "binop", "fmod", "uint8",
864
1119
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
865
1120
  { "binop", "fmod", "int16",
866
- "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
1121
+ "if ((#2)==0) {ca_zerodiv();}; (#3) = ((#2)==-1) ? 0 : (#1) % (#2);" },
867
1122
  { "binop", "fmod", "uint16",
868
1123
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
869
1124
  { "binop", "fmod", "int32",
870
- "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
1125
+ "if ((#2)==0) {ca_zerodiv();}; (#3) = ((#2)==-1) ? 0 : (#1) % (#2);" },
871
1126
  { "binop", "fmod", "uint32",
872
1127
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
873
1128
  { "binop", "fmod", "int64",
874
- "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
1129
+ "if ((#2)==0) {ca_zerodiv();}; (#3) = ((#2)==-1) ? 0 : (#1) % (#2);" },
875
1130
  { "binop", "fmod", "uint64",
876
1131
  "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);" },
877
1132
  { "binop", "fmod", "float32",
@@ -933,37 +1188,37 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
933
1188
  { "binop", "bit_xor_i", "boolean",
934
1189
  "(#3) = ((#1) != (#2)) ? 1 : 0;" },
935
1190
  { "binop", "bit_lshift", "int8",
936
- "(#3) = (#1) << (#2);" },
1191
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = 0;\n else if ( _n <= -_w ) _r = _x < 0 ? -1 : 0;\n else if ( _n < 0 ) _r = _x >> -_n;\n else _r = (int64_t) ((uint64_t) _x << _n);\n (#3) = (<type>) _r;\n }\n " },
937
1192
  { "binop", "bit_lshift", "uint8",
938
- "(#3) = (#1) << (#2);" },
1193
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) << (#2));" },
939
1194
  { "binop", "bit_lshift", "int16",
940
- "(#3) = (#1) << (#2);" },
1195
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = 0;\n else if ( _n <= -_w ) _r = _x < 0 ? -1 : 0;\n else if ( _n < 0 ) _r = _x >> -_n;\n else _r = (int64_t) ((uint64_t) _x << _n);\n (#3) = (<type>) _r;\n }\n " },
941
1196
  { "binop", "bit_lshift", "uint16",
942
- "(#3) = (#1) << (#2);" },
1197
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) << (#2));" },
943
1198
  { "binop", "bit_lshift", "int32",
944
- "(#3) = (#1) << (#2);" },
1199
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = 0;\n else if ( _n <= -_w ) _r = _x < 0 ? -1 : 0;\n else if ( _n < 0 ) _r = _x >> -_n;\n else _r = (int64_t) ((uint64_t) _x << _n);\n (#3) = (<type>) _r;\n }\n " },
945
1200
  { "binop", "bit_lshift", "uint32",
946
- "(#3) = (#1) << (#2);" },
1201
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) << (#2));" },
947
1202
  { "binop", "bit_lshift", "int64",
948
- "(#3) = (#1) << (#2);" },
1203
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = 0;\n else if ( _n <= -_w ) _r = _x < 0 ? -1 : 0;\n else if ( _n < 0 ) _r = _x >> -_n;\n else _r = (int64_t) ((uint64_t) _x << _n);\n (#3) = (<type>) _r;\n }\n " },
949
1204
  { "binop", "bit_lshift", "uint64",
950
- "(#3) = (#1) << (#2);" },
1205
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) << (#2));" },
951
1206
  { "binop", "bit_rshift", "int8",
952
- "(#3) = (#1) >> (#2);" },
1207
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = _x < 0 ? -1 : 0;\n else if ( _n <= -_w ) _r = 0;\n else if ( _n < 0 ) _r = (int64_t) ((uint64_t) _x << -_n);\n else _r = _x >> _n;\n (#3) = (<type>) _r;\n }\n " },
953
1208
  { "binop", "bit_rshift", "uint8",
954
- "(#3) = (#1) >> (#2);" },
1209
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) >> (#2));" },
955
1210
  { "binop", "bit_rshift", "int16",
956
- "(#3) = (#1) >> (#2);" },
1211
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = _x < 0 ? -1 : 0;\n else if ( _n <= -_w ) _r = 0;\n else if ( _n < 0 ) _r = (int64_t) ((uint64_t) _x << -_n);\n else _r = _x >> _n;\n (#3) = (<type>) _r;\n }\n " },
957
1212
  { "binop", "bit_rshift", "uint16",
958
- "(#3) = (#1) >> (#2);" },
1213
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) >> (#2));" },
959
1214
  { "binop", "bit_rshift", "int32",
960
- "(#3) = (#1) >> (#2);" },
1215
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = _x < 0 ? -1 : 0;\n else if ( _n <= -_w ) _r = 0;\n else if ( _n < 0 ) _r = (int64_t) ((uint64_t) _x << -_n);\n else _r = _x >> _n;\n (#3) = (<type>) _r;\n }\n " },
961
1216
  { "binop", "bit_rshift", "uint32",
962
- "(#3) = (#1) >> (#2);" },
1217
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) >> (#2));" },
963
1218
  { "binop", "bit_rshift", "int64",
964
- "(#3) = (#1) >> (#2);" },
1219
+ "\n {\n int64_t _x = (int64_t) (#1), _n = (int64_t) (#2), _r;\n const int64_t _w = (int64_t) (8 * sizeof(<type>));\n if ( _n >= _w ) _r = _x < 0 ? -1 : 0;\n else if ( _n <= -_w ) _r = 0;\n else if ( _n < 0 ) _r = (int64_t) ((uint64_t) _x << -_n);\n else _r = _x >> _n;\n (#3) = (<type>) _r;\n }\n " },
965
1220
  { "binop", "bit_rshift", "uint64",
966
- "(#3) = (#1) >> (#2);" },
1221
+ "(#3) = ((uint64_t) (#2) >= 8 * sizeof(<type>)) ? 0 : (<type>) ((uint64_t) (#1) >> (#2));" },
967
1222
  { "binop", "and", "boolean",
968
1223
  "(#3) = (#1) && (#2);" },
969
1224
  { "binop", "or", "boolean",
@@ -987,7 +1242,7 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
987
1242
  { "triop", "fma", "uint64",
988
1243
  "(#4) = (#1) * (#2) + (#3);" },
989
1244
  { "triop", "fma", "float32",
990
- "(#4) = fma((#1), (#2), (#3));" },
1245
+ "(#4) = fmaf((#1), (#2), (#3));" },
991
1246
  { "triop", "fma", "float64",
992
1247
  "(#4) = fma((#1), (#2), (#3));" },
993
1248
  { "triop", "fma", "cmplx64",
@@ -1011,7 +1266,7 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
1011
1266
  { "triop", "fms", "uint64",
1012
1267
  "(#4) = (#1) * (#2) - (#3);" },
1013
1268
  { "triop", "fms", "float32",
1014
- "(#4) = fma((#1), (#2), -(#3));" },
1269
+ "(#4) = fmaf((#1), (#2), -(#3));" },
1015
1270
  { "triop", "fms", "float64",
1016
1271
  "(#4) = fma((#1), (#2), -(#3));" },
1017
1272
  { "triop", "fms", "cmplx64",
@@ -1038,6 +1293,32 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
1038
1293
  "(#4) = isnan(#1) ? (#1) : fmin(fmax((#1), (#2)), (#3));" },
1039
1294
  { "triop", "clip", "float64",
1040
1295
  "(#4) = isnan(#1) ? (#1) : fmin(fmax((#1), (#2)), (#3));" },
1296
+ { "triop", "select", "int8",
1297
+ "(#4) = (#1) ? (#2) : (#3);" },
1298
+ { "triop", "select", "uint8",
1299
+ "(#4) = (#1) ? (#2) : (#3);" },
1300
+ { "triop", "select", "int16",
1301
+ "(#4) = (#1) ? (#2) : (#3);" },
1302
+ { "triop", "select", "uint16",
1303
+ "(#4) = (#1) ? (#2) : (#3);" },
1304
+ { "triop", "select", "int32",
1305
+ "(#4) = (#1) ? (#2) : (#3);" },
1306
+ { "triop", "select", "uint32",
1307
+ "(#4) = (#1) ? (#2) : (#3);" },
1308
+ { "triop", "select", "int64",
1309
+ "(#4) = (#1) ? (#2) : (#3);" },
1310
+ { "triop", "select", "uint64",
1311
+ "(#4) = (#1) ? (#2) : (#3);" },
1312
+ { "triop", "select", "float32",
1313
+ "(#4) = (#1) ? (#2) : (#3);" },
1314
+ { "triop", "select", "float64",
1315
+ "(#4) = (#1) ? (#2) : (#3);" },
1316
+ { "triop", "select", "boolean",
1317
+ "(#4) = (#1) ? (#2) : (#3);" },
1318
+ { "triop", "select", "cmplx64",
1319
+ "(#4) = (#1) ? (#2) : (#3);" },
1320
+ { "triop", "select", "cmplx128",
1321
+ "(#4) = (#1) ? (#2) : (#3);" },
1041
1322
  { "binop", "power", "int8",
1042
1323
  "(#3) = op_powi_<type>((#1), (#2));" },
1043
1324
  { "binop", "power", "uint8",
@@ -1082,9 +1363,319 @@ static const ca_kernel_body_t ca_kernel_bodies[] = {
1082
1363
  "(#3) = fmaxf((#1), (#2)) + log1pf(expf(-fabsf((#1) - (#2))));" },
1083
1364
  { "binop", "logaddexp", "float64",
1084
1365
  "(#3) = fmax((#1), (#2)) + log1p(exp(-fabs((#1) - (#2))));" },
1366
+ { "moncmp", "is_nan", "int8",
1367
+ "(#2) = 0;" },
1368
+ { "moncmp", "is_nan", "uint8",
1369
+ "(#2) = 0;" },
1370
+ { "moncmp", "is_nan", "int16",
1371
+ "(#2) = 0;" },
1372
+ { "moncmp", "is_nan", "uint16",
1373
+ "(#2) = 0;" },
1374
+ { "moncmp", "is_nan", "int32",
1375
+ "(#2) = 0;" },
1376
+ { "moncmp", "is_nan", "uint32",
1377
+ "(#2) = 0;" },
1378
+ { "moncmp", "is_nan", "int64",
1379
+ "(#2) = 0;" },
1380
+ { "moncmp", "is_nan", "uint64",
1381
+ "(#2) = 0;" },
1382
+ { "moncmp", "is_nan", "float32",
1383
+ "(#2) = isnan(#1);" },
1384
+ { "moncmp", "is_nan", "float64",
1385
+ "(#2) = isnan(#1);" },
1386
+ { "moncmp", "is_nan", "cmplx64",
1387
+ "(#2) = (isnan(creal(#1)) || isnan(cimag(#1)));" },
1388
+ { "moncmp", "is_nan", "cmplx128",
1389
+ "(#2) = (isnan(creal(#1)) || isnan(cimag(#1)));" },
1390
+ { "moncmp", "is_inf", "int8",
1391
+ "(#2) = 0;" },
1392
+ { "moncmp", "is_inf", "uint8",
1393
+ "(#2) = 0;" },
1394
+ { "moncmp", "is_inf", "int16",
1395
+ "(#2) = 0;" },
1396
+ { "moncmp", "is_inf", "uint16",
1397
+ "(#2) = 0;" },
1398
+ { "moncmp", "is_inf", "int32",
1399
+ "(#2) = 0;" },
1400
+ { "moncmp", "is_inf", "uint32",
1401
+ "(#2) = 0;" },
1402
+ { "moncmp", "is_inf", "int64",
1403
+ "(#2) = 0;" },
1404
+ { "moncmp", "is_inf", "uint64",
1405
+ "(#2) = 0;" },
1406
+ { "moncmp", "is_inf", "float32",
1407
+ "(#2) = isinf(#1);" },
1408
+ { "moncmp", "is_inf", "float64",
1409
+ "(#2) = isinf(#1);" },
1410
+ { "moncmp", "is_inf", "cmplx64",
1411
+ "(#2) = (isinf(creal(#1)) || isinf(cimag(#1)));" },
1412
+ { "moncmp", "is_inf", "cmplx128",
1413
+ "(#2) = (isinf(creal(#1)) || isinf(cimag(#1)));" },
1414
+ { "moncmp", "is_finite", "int8",
1415
+ "(#2) = 1;" },
1416
+ { "moncmp", "is_finite", "uint8",
1417
+ "(#2) = 1;" },
1418
+ { "moncmp", "is_finite", "int16",
1419
+ "(#2) = 1;" },
1420
+ { "moncmp", "is_finite", "uint16",
1421
+ "(#2) = 1;" },
1422
+ { "moncmp", "is_finite", "int32",
1423
+ "(#2) = 1;" },
1424
+ { "moncmp", "is_finite", "uint32",
1425
+ "(#2) = 1;" },
1426
+ { "moncmp", "is_finite", "int64",
1427
+ "(#2) = 1;" },
1428
+ { "moncmp", "is_finite", "uint64",
1429
+ "(#2) = 1;" },
1430
+ { "moncmp", "is_finite", "float32",
1431
+ "(#2) = isfinite(#1);" },
1432
+ { "moncmp", "is_finite", "float64",
1433
+ "(#2) = isfinite(#1);" },
1434
+ { "moncmp", "is_finite", "cmplx64",
1435
+ "(#2) = (isfinite(creal(#1)) && isfinite(cimag(#1)));" },
1436
+ { "moncmp", "is_finite", "cmplx128",
1437
+ "(#2) = (isfinite(creal(#1)) && isfinite(cimag(#1)));" },
1438
+ { "moncmp", "is_invalid", "int8",
1439
+ "(#2) = 0;" },
1440
+ { "moncmp", "is_invalid", "uint8",
1441
+ "(#2) = 0;" },
1442
+ { "moncmp", "is_invalid", "int16",
1443
+ "(#2) = 0;" },
1444
+ { "moncmp", "is_invalid", "uint16",
1445
+ "(#2) = 0;" },
1446
+ { "moncmp", "is_invalid", "int32",
1447
+ "(#2) = 0;" },
1448
+ { "moncmp", "is_invalid", "uint32",
1449
+ "(#2) = 0;" },
1450
+ { "moncmp", "is_invalid", "int64",
1451
+ "(#2) = 0;" },
1452
+ { "moncmp", "is_invalid", "uint64",
1453
+ "(#2) = 0;" },
1454
+ { "moncmp", "is_invalid", "float32",
1455
+ "(#2) = (!isfinite(#1));" },
1456
+ { "moncmp", "is_invalid", "float64",
1457
+ "(#2) = (!isfinite(#1));" },
1458
+ { "moncmp", "is_invalid", "boolean",
1459
+ "(#2) = 0;" },
1460
+ { "moncmp", "is_invalid", "cmplx64",
1461
+ "(#2) = (!isfinite(creal(#1)) || !isfinite(cimag(#1)));" },
1462
+ { "moncmp", "is_invalid", "cmplx128",
1463
+ "(#2) = (!isfinite(creal(#1)) || !isfinite(cimag(#1)));" },
1464
+ { "moncmp", "signbit", "int8",
1465
+ "(#2) = ((#1) < 0);" },
1466
+ { "moncmp", "signbit", "uint8",
1467
+ "(#2) = 0;" },
1468
+ { "moncmp", "signbit", "int16",
1469
+ "(#2) = ((#1) < 0);" },
1470
+ { "moncmp", "signbit", "uint16",
1471
+ "(#2) = 0;" },
1472
+ { "moncmp", "signbit", "int32",
1473
+ "(#2) = ((#1) < 0);" },
1474
+ { "moncmp", "signbit", "uint32",
1475
+ "(#2) = 0;" },
1476
+ { "moncmp", "signbit", "int64",
1477
+ "(#2) = ((#1) < 0);" },
1478
+ { "moncmp", "signbit", "uint64",
1479
+ "(#2) = 0;" },
1480
+ { "moncmp", "signbit", "float32",
1481
+ "(#2) = signbit(#1);" },
1482
+ { "moncmp", "signbit", "float64",
1483
+ "(#2) = signbit(#1);" },
1484
+ { "bincmp", "feq", "float32",
1485
+ "\n <type> f1a = fabs((float64_t) #1);\n <type> f2a = fabs((float64_t) #2);\n <type> fmax = (f1a > f2a) ? f1a : f2a;\n (#3) = ( fabs(((float64_t) #1)-( (float64_t) #2)) <= fmax * <epsilon> ) ? 1 : 0;\n " },
1486
+ { "bincmp", "feq", "float64",
1487
+ "\n <type> f1a = fabs((float64_t) #1);\n <type> f2a = fabs((float64_t) #2);\n <type> fmax = (f1a > f2a) ? f1a : f2a;\n (#3) = ( fabs(((float64_t) #1)-( (float64_t) #2)) <= fmax * <epsilon> ) ? 1 : 0;\n " },
1488
+ { "bincmp", "eq", "int8",
1489
+ "(#3) = ( (#1) == (#2) );" },
1490
+ { "bincmp", "eq", "uint8",
1491
+ "(#3) = ( (#1) == (#2) );" },
1492
+ { "bincmp", "eq", "int16",
1493
+ "(#3) = ( (#1) == (#2) );" },
1494
+ { "bincmp", "eq", "uint16",
1495
+ "(#3) = ( (#1) == (#2) );" },
1496
+ { "bincmp", "eq", "int32",
1497
+ "(#3) = ( (#1) == (#2) );" },
1498
+ { "bincmp", "eq", "uint32",
1499
+ "(#3) = ( (#1) == (#2) );" },
1500
+ { "bincmp", "eq", "int64",
1501
+ "(#3) = ( (#1) == (#2) );" },
1502
+ { "bincmp", "eq", "uint64",
1503
+ "(#3) = ( (#1) == (#2) );" },
1504
+ { "bincmp", "eq", "float32",
1505
+ "(#3) = ( (#1) == (#2) );" },
1506
+ { "bincmp", "eq", "float64",
1507
+ "(#3) = ( (#1) == (#2) );" },
1508
+ { "bincmp", "eq", "boolean",
1509
+ "(#3) = ( (#1) == (#2) );" },
1510
+ { "bincmp", "eq", "cmplx64",
1511
+ "(#3) = (#1) == (#2);" },
1512
+ { "bincmp", "eq", "cmplx128",
1513
+ "(#3) = (#1) == (#2);" },
1514
+ { "bincmp", "ne", "int8",
1515
+ "(#3) = ( (#1) != (#2) );" },
1516
+ { "bincmp", "ne", "uint8",
1517
+ "(#3) = ( (#1) != (#2) );" },
1518
+ { "bincmp", "ne", "int16",
1519
+ "(#3) = ( (#1) != (#2) );" },
1520
+ { "bincmp", "ne", "uint16",
1521
+ "(#3) = ( (#1) != (#2) );" },
1522
+ { "bincmp", "ne", "int32",
1523
+ "(#3) = ( (#1) != (#2) );" },
1524
+ { "bincmp", "ne", "uint32",
1525
+ "(#3) = ( (#1) != (#2) );" },
1526
+ { "bincmp", "ne", "int64",
1527
+ "(#3) = ( (#1) != (#2) );" },
1528
+ { "bincmp", "ne", "uint64",
1529
+ "(#3) = ( (#1) != (#2) );" },
1530
+ { "bincmp", "ne", "float32",
1531
+ "(#3) = ( (#1) != (#2) );" },
1532
+ { "bincmp", "ne", "float64",
1533
+ "(#3) = ( (#1) != (#2) );" },
1534
+ { "bincmp", "ne", "boolean",
1535
+ "(#3) = ( (#1) != (#2) );" },
1536
+ { "bincmp", "ne", "cmplx64",
1537
+ "(#3) = (#1) != (#2);" },
1538
+ { "bincmp", "ne", "cmplx128",
1539
+ "(#3) = (#1) != (#2);" },
1540
+ { "bincmp", "gt", "int8",
1541
+ "(#3) = ( (#1) > (#2) );" },
1542
+ { "bincmp", "gt", "uint8",
1543
+ "(#3) = ( (#1) > (#2) );" },
1544
+ { "bincmp", "gt", "int16",
1545
+ "(#3) = ( (#1) > (#2) );" },
1546
+ { "bincmp", "gt", "uint16",
1547
+ "(#3) = ( (#1) > (#2) );" },
1548
+ { "bincmp", "gt", "int32",
1549
+ "(#3) = ( (#1) > (#2) );" },
1550
+ { "bincmp", "gt", "uint32",
1551
+ "(#3) = ( (#1) > (#2) );" },
1552
+ { "bincmp", "gt", "int64",
1553
+ "(#3) = ( (#1) > (#2) );" },
1554
+ { "bincmp", "gt", "uint64",
1555
+ "(#3) = ( (#1) > (#2) );" },
1556
+ { "bincmp", "gt", "float32",
1557
+ "(#3) = ( (#1) > (#2) );" },
1558
+ { "bincmp", "gt", "float64",
1559
+ "(#3) = ( (#1) > (#2) );" },
1560
+ { "bincmp", "gt", "boolean",
1561
+ "(#3) = ( (#1) > (#2) );" },
1562
+ { "bincmp", "lt", "int8",
1563
+ "(#3) = ( (#1) < (#2) );" },
1564
+ { "bincmp", "lt", "uint8",
1565
+ "(#3) = ( (#1) < (#2) );" },
1566
+ { "bincmp", "lt", "int16",
1567
+ "(#3) = ( (#1) < (#2) );" },
1568
+ { "bincmp", "lt", "uint16",
1569
+ "(#3) = ( (#1) < (#2) );" },
1570
+ { "bincmp", "lt", "int32",
1571
+ "(#3) = ( (#1) < (#2) );" },
1572
+ { "bincmp", "lt", "uint32",
1573
+ "(#3) = ( (#1) < (#2) );" },
1574
+ { "bincmp", "lt", "int64",
1575
+ "(#3) = ( (#1) < (#2) );" },
1576
+ { "bincmp", "lt", "uint64",
1577
+ "(#3) = ( (#1) < (#2) );" },
1578
+ { "bincmp", "lt", "float32",
1579
+ "(#3) = ( (#1) < (#2) );" },
1580
+ { "bincmp", "lt", "float64",
1581
+ "(#3) = ( (#1) < (#2) );" },
1582
+ { "bincmp", "lt", "boolean",
1583
+ "(#3) = ( (#1) < (#2) );" },
1584
+ { "bincmp", "ge", "int8",
1585
+ "(#3) = ( (#1) >= (#2) );" },
1586
+ { "bincmp", "ge", "uint8",
1587
+ "(#3) = ( (#1) >= (#2) );" },
1588
+ { "bincmp", "ge", "int16",
1589
+ "(#3) = ( (#1) >= (#2) );" },
1590
+ { "bincmp", "ge", "uint16",
1591
+ "(#3) = ( (#1) >= (#2) );" },
1592
+ { "bincmp", "ge", "int32",
1593
+ "(#3) = ( (#1) >= (#2) );" },
1594
+ { "bincmp", "ge", "uint32",
1595
+ "(#3) = ( (#1) >= (#2) );" },
1596
+ { "bincmp", "ge", "int64",
1597
+ "(#3) = ( (#1) >= (#2) );" },
1598
+ { "bincmp", "ge", "uint64",
1599
+ "(#3) = ( (#1) >= (#2) );" },
1600
+ { "bincmp", "ge", "float32",
1601
+ "(#3) = ( (#1) >= (#2) );" },
1602
+ { "bincmp", "ge", "float64",
1603
+ "(#3) = ( (#1) >= (#2) );" },
1604
+ { "bincmp", "ge", "boolean",
1605
+ "(#3) = ( (#1) >= (#2) );" },
1606
+ { "bincmp", "le", "int8",
1607
+ "(#3) = ( (#1) <= (#2) );" },
1608
+ { "bincmp", "le", "uint8",
1609
+ "(#3) = ( (#1) <= (#2) );" },
1610
+ { "bincmp", "le", "int16",
1611
+ "(#3) = ( (#1) <= (#2) );" },
1612
+ { "bincmp", "le", "uint16",
1613
+ "(#3) = ( (#1) <= (#2) );" },
1614
+ { "bincmp", "le", "int32",
1615
+ "(#3) = ( (#1) <= (#2) );" },
1616
+ { "bincmp", "le", "uint32",
1617
+ "(#3) = ( (#1) <= (#2) );" },
1618
+ { "bincmp", "le", "int64",
1619
+ "(#3) = ( (#1) <= (#2) );" },
1620
+ { "bincmp", "le", "uint64",
1621
+ "(#3) = ( (#1) <= (#2) );" },
1622
+ { "bincmp", "le", "float32",
1623
+ "(#3) = ( (#1) <= (#2) );" },
1624
+ { "bincmp", "le", "float64",
1625
+ "(#3) = ( (#1) <= (#2) );" },
1626
+ { "bincmp", "le", "boolean",
1627
+ "(#3) = ( (#1) <= (#2) );" },
1628
+ { "bincmp", "is_close", "int8",
1629
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1630
+ { "bincmp", "is_close", "uint8",
1631
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1632
+ { "bincmp", "is_close", "int16",
1633
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1634
+ { "bincmp", "is_close", "uint16",
1635
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1636
+ { "bincmp", "is_close", "int32",
1637
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1638
+ { "bincmp", "is_close", "uint32",
1639
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1640
+ { "bincmp", "is_close", "int64",
1641
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1642
+ { "bincmp", "is_close", "uint64",
1643
+ "(#3) = (fabs((double)(#1) - (double)(#2)) <= tol) ? 1 : 0;" },
1644
+ { "bincmp", "is_close", "float32",
1645
+ "(#3) = (fabs((#1) - (#2)) <= tol) ? 1 : 0;" },
1646
+ { "bincmp", "is_close", "float64",
1647
+ "(#3) = (fabs((#1) - (#2)) <= tol) ? 1 : 0;" },
1648
+ { "bincmp", "is_close", "cmplx64",
1649
+ "(#3) = (cabs((#1) - (#2)) <= tol) ? 1 : 0;" },
1650
+ { "bincmp", "is_close", "cmplx128",
1651
+ "(#3) = (cabs((#1) - (#2)) <= tol) ? 1 : 0;" },
1652
+ { "bincmp", "is_equiv", "int8",
1653
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1654
+ { "bincmp", "is_equiv", "uint8",
1655
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1656
+ { "bincmp", "is_equiv", "int16",
1657
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1658
+ { "bincmp", "is_equiv", "uint16",
1659
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1660
+ { "bincmp", "is_equiv", "int32",
1661
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1662
+ { "bincmp", "is_equiv", "uint32",
1663
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1664
+ { "bincmp", "is_equiv", "int64",
1665
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1666
+ { "bincmp", "is_equiv", "uint64",
1667
+ "\n double a = (double)(#1), b = (double)(#2);\n double aa = fabs(a), ab = fabs(b);\n double m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs(a - b) / m <= tol) ) ? 1 : 0;\n " },
1668
+ { "bincmp", "is_equiv", "float32",
1669
+ "\n <type> aa = fabs((#1)), ab = fabs((#2));\n <type> m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs((#1) - (#2)) / m <= tol) ) ? 1 : 0;\n " },
1670
+ { "bincmp", "is_equiv", "float64",
1671
+ "\n <type> aa = fabs((#1)), ab = fabs((#2));\n <type> m = (aa > ab) ? aa : ab;\n (#3) = ( (#1) == (#2) || (m > 0 && fabs((#1) - (#2)) / m <= tol) ) ? 1 : 0;\n " },
1672
+ { "bincmp", "is_equiv", "cmplx64",
1673
+ "\n double aa = cabs((#1)), ab = cabs((#2));\n double m = (aa > ab) ? aa : ab;\n (#3) = ( m > 0 && cabs((#1) - (#2)) / m <= tol ) ? 1 : 0;\n " },
1674
+ { "bincmp", "is_equiv", "cmplx128",
1675
+ "\n double aa = cabs((#1)), ab = cabs((#2));\n double m = (aa > ab) ? aa : ab;\n (#3) = ( m > 0 && cabs((#1) - (#2)) / m <= tol ) ? 1 : 0;\n " },
1085
1676
  };
1086
1677
 
1087
- static const int ca_kernel_bodies_count = 527;
1678
+ static const int ca_kernel_bodies_count = 823;
1088
1679
 
1089
1680
  /* CArray.__kernel_body__(kind, name, data_type) -> String, or nil where
1090
1681
  this operation has no body at that data type. */
@@ -1109,15 +1700,25 @@ rb_ca_s_kernel_body (VALUE klass, VALUE rkind, VALUE rname, VALUE rtype)
1109
1700
  return Qnil;
1110
1701
  }
1111
1702
 
1703
+ /* CArray.__kernel_helpers__ -> String: the C a body above may call
1704
+ beyond the standard library, for the caller to put ahead of it. */
1705
+ static const char ca_kernel_helpers[] =
1706
+ "\n/* x raised to a non-negative power, by binary exponentiation. The power\n is unsigned so that the magnitude of INT64_MIN is representable. */\n#define op_powi_magnitude(type) \\\nstatic inline type \\\nop_powi_mag_## type (type x, uint64_t p) \\\n{ \\\n type r=1; \\\n\\\n switch(p) { \\\n case 2: return x*x; \\\n case 3: return x*x*x; \\\n case 0: return 1; \\\n case 1: return x; \\\n } \\\n while (p) { \\\n if ( p & 1 ) r *= x; \\\n x *= x; \\\n p >>= 1; \\\n } \\\n return r; \\\n}\n\n/* An integer to a negative power is 1/x^|p| in integer division, which is\n decided by x alone: 0 has no reciprocal, 1 and -1 keep their magnitude,\n anything larger truncates to 0. Answering it that way, rather than by\n computing x^|p|, keeps a power that overflows -- 2 ** -64 -- from wrapping\n to a zero divisor. */\n#define op_powi(type) \\\nop_powi_magnitude(type) \\\nstatic inline type \\\nop_powi_## type (type x, int64_t p) \\\n{ \\\n if ( p < 0 ) { \\\n if ( x == 0 ) ca_zerodiv(); \\\n if ( x == 1 ) return 1; \\\n if ( x == (type) -1 ) return ( p % 2 ) ? x : 1; \\\n return 0; \\\n } \\\n return op_powi_mag_## type(x, (uint64_t) p); \\\n}\n\n/* An unsigned x is never -1; (type) -1 is its largest value. */\n#define op_powi_u(type) \\\nop_powi_magnitude(type) \\\nstatic inline type \\\nop_powi_## type (type x, int64_t p) \\\n{ \\\n if ( p < 0 ) { \\\n if ( x == 0 ) ca_zerodiv(); \\\n return ( x == 1 ) ? 1 : 0; \\\n } \\\n return op_powi_mag_## type(x, (uint64_t) p); \\\n}\n\n#define op_powi_fc(type) \\\nop_powi_magnitude(type) \\\nstatic inline type \\\nop_powi_## type (type x, int64_t p) \\\n{ \\\n if ( p < 0 ) { \\\n return 1 / op_powi_mag_## type(x, (uint64_t) 0 - (uint64_t) p); \\\n } \\\n return op_powi_mag_## type(x, (uint64_t) p); \\\n}\n\nop_powi(int8_t)\nop_powi_u(uint8_t)\nop_powi(int16_t)\nop_powi_u(uint16_t)\nop_powi(int32_t)\nop_powi_u(uint32_t)\nop_powi(int64_t)\nop_powi_u(uint64_t)\nop_powi_fc(float32_t)\nop_powi_fc(float64_t)\n\n";
1707
+
1708
+ static VALUE
1709
+ rb_ca_s_kernel_helpers (VALUE klass)
1710
+ {
1711
+ return rb_str_new_cstr(ca_kernel_helpers);
1712
+ }
1713
+
1112
1714
  void
1113
1715
  Init_carray_kernels (void)
1114
1716
  {
1115
1717
  Init_carray_kernels_reduce_aggregate();
1116
1718
  Init_carray_kernels_reduce_extreme();
1117
- Init_carray_kernels_reduce_cumulative();
1118
1719
  Init_carray_kernels_reduce_boolean();
1119
1720
  Init_carray_kernels_reduce_variance();
1120
- Init_carray_kernels_map();
1721
+ Init_carray_kernels_reduce_cumulative();
1121
1722
  Init_carray_kernels_scan();
1122
1723
  Init_carray_kernels_sort();
1123
1724
  Init_carray_kernels_search();
@@ -1128,4 +1729,6 @@ Init_carray_kernels (void)
1128
1729
  Init_carray_kernels_bincmp();
1129
1730
  rb_define_singleton_method(rb_cCArray, "__kernel_body__",
1130
1731
  rb_ca_s_kernel_body, 3);
1732
+ rb_define_singleton_method(rb_cCArray, "__kernel_helpers__",
1733
+ rb_ca_s_kernel_helpers, 0);
1131
1734
  }