authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-03 01:18:23-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-05 02:59:01-05:00
log93d696e84ef17a32d5c2f1520a295ebcda968e91
tree7494db8b659f454b31025c4a3660e98c06860d34
parenta8f4ac2b94e7945a5a1623547f258f5f32f12674

CBE: implement some big integer and vector unary operations


5 files changed, 460 insertions(+), 23 deletions(-)

lib/zig.h+414-8
...@@ -1919,7 +1919,7 @@ static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) {...@@ -1919,7 +1919,7 @@ static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) {
19191919
1920/* ========================== Big Integer Support =========================== */1920/* ========================== Big Integer Support =========================== */
19211921
1922static inline uint16_t zig_big_bytes(uint16_t bits) {1922static inline uint16_t zig_int_bytes(uint16_t bits) {
1923 uint16_t bytes = (bits + CHAR_BIT - 1) / CHAR_BIT;1923 uint16_t bytes = (bits + CHAR_BIT - 1) / CHAR_BIT;
1924 uint16_t alignment = 16;1924 uint16_t alignment = 16;
1925 while (alignment / 2 >= bytes) alignment /= 2;1925 while (alignment / 2 >= bytes) alignment /= 2;
...@@ -1931,7 +1931,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign...@@ -1931,7 +1931,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign
1931 const uint8_t *rhs_bytes = rhs;1931 const uint8_t *rhs_bytes = rhs;
1932 uint16_t byte_offset = 0;1932 uint16_t byte_offset = 0;
1933 bool do_signed = is_signed;1933 bool do_signed = is_signed;
1934 uint16_t remaining_bytes = zig_big_bytes(bits);1934 uint16_t remaining_bytes = zig_int_bytes(bits);
19351935
1936#if zig_little_endian1936#if zig_little_endian
1937 byte_offset = remaining_bytes;1937 byte_offset = remaining_bytes;
...@@ -1965,7 +1965,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign...@@ -1965,7 +1965,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign
1965 remaining_bytes -= 128 / CHAR_BIT;1965 remaining_bytes -= 128 / CHAR_BIT;
19661966
1967#if zig_big_endian1967#if zig_big_endian
1968 byte_offset -= 128 / CHAR_BIT;1968 byte_offset += 128 / CHAR_BIT;
1969#endif1969#endif
1970 }1970 }
19711971
...@@ -1994,7 +1994,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign...@@ -1994,7 +1994,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign
1994 remaining_bytes -= 64 / CHAR_BIT;1994 remaining_bytes -= 64 / CHAR_BIT;
19951995
1996#if zig_big_endian1996#if zig_big_endian
1997 byte_offset -= 64 / CHAR_BIT;1997 byte_offset += 64 / CHAR_BIT;
1998#endif1998#endif
1999 }1999 }
20002000
...@@ -2023,7 +2023,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign...@@ -2023,7 +2023,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign
2023 remaining_bytes -= 32 / CHAR_BIT;2023 remaining_bytes -= 32 / CHAR_BIT;
20242024
2025#if zig_big_endian2025#if zig_big_endian
2026 byte_offset -= 32 / CHAR_BIT;2026 byte_offset += 32 / CHAR_BIT;
2027#endif2027#endif
2028 }2028 }
20292029
...@@ -2052,7 +2052,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign...@@ -2052,7 +2052,7 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign
2052 remaining_bytes -= 16 / CHAR_BIT;2052 remaining_bytes -= 16 / CHAR_BIT;
20532053
2054#if zig_big_endian2054#if zig_big_endian
2055 byte_offset -= 16 / CHAR_BIT;2055 byte_offset += 16 / CHAR_BIT;
2056#endif2056#endif
2057 }2057 }
20582058
...@@ -2081,13 +2081,368 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign...@@ -2081,13 +2081,368 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign
2081 remaining_bytes -= 8 / CHAR_BIT;2081 remaining_bytes -= 8 / CHAR_BIT;
20822082
2083#if zig_big_endian2083#if zig_big_endian
2084 byte_offset -= 8 / CHAR_BIT;2084 byte_offset += 8 / CHAR_BIT;
2085#endif2085#endif
2086 }2086 }
20872087
2088 return 0;2088 return 0;
2089}2089}
20902090
2091static inline uint16_t zig_clz_big(const void *val, bool is_signed, uint16_t bits) {
2092 const uint8_t *val_bytes = val;
2093 uint16_t byte_offset = 0;
2094 uint16_t remaining_bytes = zig_int_bytes(bits);
2095 uint16_t skip_bits = remaining_bytes * 8 - bits;
2096 uint16_t total_lz = 0;
2097 uint16_t limb_lz;
2098 (void)is_signed;
2099
2100#if zig_little_endian
2101 byte_offset = remaining_bytes;
2102#endif
2103
2104 while (remaining_bytes >= 128 / CHAR_BIT) {
2105#if zig_little_endian
2106 byte_offset -= 128 / CHAR_BIT;
2107#endif
2108
2109 {
2110 zig_u128 val_limb;
2111
2112 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2113 limb_lz = zig_clz_u128(val_limb, 128 - skip_bits);
2114 }
2115
2116 total_lz += limb_lz;
2117 if (limb_lz < 128 - skip_bits) return total_lz;
2118 skip_bits = 0;
2119 remaining_bytes -= 128 / CHAR_BIT;
2120
2121#if zig_big_endian
2122 byte_offset += 128 / CHAR_BIT;
2123#endif
2124 }
2125
2126 while (remaining_bytes >= 64 / CHAR_BIT) {
2127#if zig_little_endian
2128 byte_offset -= 64 / CHAR_BIT;
2129#endif
2130
2131 {
2132 uint64_t val_limb;
2133
2134 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2135 limb_lz = zig_clz_u64(val_limb, 64 - skip_bits);
2136 }
2137
2138 total_lz += limb_lz;
2139 if (limb_lz < 64 - skip_bits) return total_lz;
2140 skip_bits = 0;
2141 remaining_bytes -= 64 / CHAR_BIT;
2142
2143#if zig_big_endian
2144 byte_offset += 64 / CHAR_BIT;
2145#endif
2146 }
2147
2148 while (remaining_bytes >= 32 / CHAR_BIT) {
2149#if zig_little_endian
2150 byte_offset -= 32 / CHAR_BIT;
2151#endif
2152
2153 {
2154 uint32_t val_limb;
2155
2156 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2157 limb_lz = zig_clz_u32(val_limb, 32 - skip_bits);
2158 }
2159
2160 total_lz += limb_lz;
2161 if (limb_lz < 32 - skip_bits) return total_lz;
2162 skip_bits = 0;
2163 remaining_bytes -= 32 / CHAR_BIT;
2164
2165#if zig_big_endian
2166 byte_offset += 32 / CHAR_BIT;
2167#endif
2168 }
2169
2170 while (remaining_bytes >= 16 / CHAR_BIT) {
2171#if zig_little_endian
2172 byte_offset -= 16 / CHAR_BIT;
2173#endif
2174
2175 {
2176 uint16_t val_limb;
2177
2178 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2179 limb_lz = zig_clz_u16(val_limb, 16 - skip_bits);
2180 }
2181
2182 total_lz += limb_lz;
2183 if (limb_lz < 16 - skip_bits) return total_lz;
2184 skip_bits = 0;
2185 remaining_bytes -= 16 / CHAR_BIT;
2186
2187#if zig_big_endian
2188 byte_offset += 16 / CHAR_BIT;
2189#endif
2190 }
2191
2192 while (remaining_bytes >= 8 / CHAR_BIT) {
2193#if zig_little_endian
2194 byte_offset -= 8 / CHAR_BIT;
2195#endif
2196
2197 {
2198 uint8_t val_limb;
2199
2200 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2201 limb_lz = zig_clz_u8(val_limb, 8 - skip_bits);
2202 }
2203
2204 total_lz += limb_lz;
2205 if (limb_lz < 8 - skip_bits) return total_lz;
2206 skip_bits = 0;
2207 remaining_bytes -= 8 / CHAR_BIT;
2208
2209#if zig_big_endian
2210 byte_offset += 8 / CHAR_BIT;
2211#endif
2212 }
2213
2214 return total_lz;
2215}
2216
2217static inline uint16_t zig_ctz_big(const void *val, bool is_signed, uint16_t bits) {
2218 const uint8_t *val_bytes = val;
2219 uint16_t byte_offset = 0;
2220 uint16_t remaining_bytes = zig_int_bytes(bits);
2221 uint16_t total_tz = 0;
2222 uint16_t limb_tz;
2223 (void)is_signed;
2224
2225#if zig_big_endian
2226 byte_offset = remaining_bytes;
2227#endif
2228
2229 while (remaining_bytes >= 128 / CHAR_BIT) {
2230#if zig_big_endian
2231 byte_offset -= 128 / CHAR_BIT;
2232#endif
2233
2234 {
2235 zig_u128 val_limb;
2236
2237 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2238 limb_tz = zig_ctz_u128(val_limb, 128);
2239 }
2240
2241 total_tz += limb_tz;
2242 if (limb_tz < 128) return total_tz;
2243 remaining_bytes -= 128 / CHAR_BIT;
2244
2245#if zig_little_endian
2246 byte_offset += 128 / CHAR_BIT;
2247#endif
2248 }
2249
2250 while (remaining_bytes >= 64 / CHAR_BIT) {
2251#if zig_big_endian
2252 byte_offset -= 64 / CHAR_BIT;
2253#endif
2254
2255 {
2256 uint64_t val_limb;
2257
2258 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2259 limb_tz = zig_ctz_u64(val_limb, 64);
2260 }
2261
2262 total_tz += limb_tz;
2263 if (limb_tz < 64) return total_tz;
2264 remaining_bytes -= 64 / CHAR_BIT;
2265
2266#if zig_little_endian
2267 byte_offset += 64 / CHAR_BIT;
2268#endif
2269 }
2270
2271 while (remaining_bytes >= 32 / CHAR_BIT) {
2272#if zig_big_endian
2273 byte_offset -= 32 / CHAR_BIT;
2274#endif
2275
2276 {
2277 uint32_t val_limb;
2278
2279 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2280 limb_tz = zig_ctz_u32(val_limb, 32);
2281 }
2282
2283 total_tz += limb_tz;
2284 if (limb_tz < 32) return total_tz;
2285 remaining_bytes -= 32 / CHAR_BIT;
2286
2287#if zig_little_endian
2288 byte_offset += 32 / CHAR_BIT;
2289#endif
2290 }
2291
2292 while (remaining_bytes >= 16 / CHAR_BIT) {
2293#if zig_big_endian
2294 byte_offset -= 16 / CHAR_BIT;
2295#endif
2296
2297 {
2298 uint16_t val_limb;
2299
2300 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2301 limb_tz = zig_ctz_u16(val_limb, 16);
2302 }
2303
2304 total_tz += limb_tz;
2305 if (limb_tz < 16) return total_tz;
2306 remaining_bytes -= 16 / CHAR_BIT;
2307
2308#if zig_little_endian
2309 byte_offset += 16 / CHAR_BIT;
2310#endif
2311 }
2312
2313 while (remaining_bytes >= 8 / CHAR_BIT) {
2314#if zig_big_endian
2315 byte_offset -= 8 / CHAR_BIT;
2316#endif
2317
2318 {
2319 uint8_t val_limb;
2320
2321 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2322 limb_tz = zig_ctz_u8(val_limb, 8);
2323 }
2324
2325 total_tz += limb_tz;
2326 if (limb_tz < 8) return total_tz;
2327 remaining_bytes -= 8 / CHAR_BIT;
2328
2329#if zig_little_endian
2330 byte_offset += 8 / CHAR_BIT;
2331#endif
2332 }
2333
2334 return total_tz;
2335}
2336
2337static inline uint16_t zig_popcount_big(const void *val, bool is_signed, uint16_t bits) {
2338 const uint8_t *val_bytes = val;
2339 uint16_t byte_offset = 0;
2340 uint16_t remaining_bytes = zig_int_bytes(bits);
2341 uint16_t total_pc = 0;
2342 (void)is_signed;
2343
2344#if zig_big_endian
2345 byte_offset = remaining_bytes;
2346#endif
2347
2348 while (remaining_bytes >= 128 / CHAR_BIT) {
2349#if zig_big_endian
2350 byte_offset -= 128 / CHAR_BIT;
2351#endif
2352
2353 {
2354 zig_u128 val_limb;
2355
2356 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2357 total_pc += zig_popcount_u128(val_limb, 128);
2358 }
2359
2360 remaining_bytes -= 128 / CHAR_BIT;
2361
2362#if zig_little_endian
2363 byte_offset += 128 / CHAR_BIT;
2364#endif
2365 }
2366
2367 while (remaining_bytes >= 64 / CHAR_BIT) {
2368#if zig_big_endian
2369 byte_offset -= 64 / CHAR_BIT;
2370#endif
2371
2372 {
2373 uint64_t val_limb;
2374
2375 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2376 total_pc += zig_popcount_u64(val_limb, 64);
2377 }
2378
2379 remaining_bytes -= 64 / CHAR_BIT;
2380
2381#if zig_little_endian
2382 byte_offset += 64 / CHAR_BIT;
2383#endif
2384 }
2385
2386 while (remaining_bytes >= 32 / CHAR_BIT) {
2387#if zig_big_endian
2388 byte_offset -= 32 / CHAR_BIT;
2389#endif
2390
2391 {
2392 uint32_t val_limb;
2393
2394 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2395 total_pc += zig_popcount_u32(val_limb, 32);
2396 }
2397
2398 remaining_bytes -= 32 / CHAR_BIT;
2399
2400#if zig_little_endian
2401 byte_offset += 32 / CHAR_BIT;
2402#endif
2403 }
2404
2405 while (remaining_bytes >= 16 / CHAR_BIT) {
2406#if zig_big_endian
2407 byte_offset -= 16 / CHAR_BIT;
2408#endif
2409
2410 {
2411 uint16_t val_limb;
2412
2413 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2414 total_pc = zig_popcount_u16(val_limb, 16);
2415 }
2416
2417 remaining_bytes -= 16 / CHAR_BIT;
2418
2419#if zig_little_endian
2420 byte_offset += 16 / CHAR_BIT;
2421#endif
2422 }
2423
2424 while (remaining_bytes >= 8 / CHAR_BIT) {
2425#if zig_big_endian
2426 byte_offset -= 8 / CHAR_BIT;
2427#endif
2428
2429 {
2430 uint8_t val_limb;
2431
2432 memcpy(&val_limb, &val_bytes[byte_offset], sizeof(val_limb));
2433 total_pc = zig_popcount_u8(val_limb, 8);
2434 }
2435
2436 remaining_bytes -= 8 / CHAR_BIT;
2437
2438#if zig_little_endian
2439 byte_offset += 8 / CHAR_BIT;
2440#endif
2441 }
2442
2443 return total_pc;
2444}
2445
2091/* ========================= Floating Point Support ========================= */2446/* ========================= Floating Point Support ========================= */
20922447
2093#if _MSC_VER2448#if _MSC_VER
...@@ -2742,7 +3097,7 @@ zig_msvc_atomics_128op(u128, max)...@@ -2742,7 +3097,7 @@ zig_msvc_atomics_128op(u128, max)
2742 uint32_t index = 0; \3097 uint32_t index = 0; \
2743 const uint8_t *lhs_ptr = lhs; \3098 const uint8_t *lhs_ptr = lhs; \
2744 const uint8_t *rhs_ptr = rhs; \3099 const uint8_t *rhs_ptr = rhs; \
2745 uint16_t elem_bytes = zig_big_bytes(elem_bits); \3100 uint16_t elem_bytes = zig_int_bytes(elem_bits); \
2746 \3101 \
2747 while (index < len) { \3102 while (index < len) { \
2748 result[index] = zig_cmp_big(lhs_ptr, rhs_ptr, is_signed, elem_bits) operator 0; \3103 result[index] = zig_cmp_big(lhs_ptr, rhs_ptr, is_signed, elem_bits) operator 0; \
...@@ -2758,6 +3113,57 @@ zig_cmp_vec(le, <=)...@@ -2758,6 +3113,57 @@ zig_cmp_vec(le, <=)
2758zig_cmp_vec(gt, > )3113zig_cmp_vec(gt, > )
2759zig_cmp_vec(ge, >=)3114zig_cmp_vec(ge, >=)
27603115
3116static inline void zig_clz_vec(void *result, const void *val, uint32_t len, bool is_signed, uint16_t elem_bits) {
3117 uint32_t index = 0;
3118 const uint8_t *val_ptr = val;
3119 uint16_t elem_bytes = zig_int_bytes(elem_bits);
3120
3121 while (index < len) {
3122 uint16_t lz = zig_clz_big(val_ptr, is_signed, elem_bits);
3123 if (elem_bits <= 128) {
3124 ((uint8_t *)result)[index] = (uint8_t)lz;
3125 } else {
3126 ((uint16_t *)result)[index] = lz;
3127 }
3128 val_ptr += elem_bytes;
3129 index += 1;
3130 }
3131}
3132
3133static inline void zig_ctz_vec(void *result, const void *val, uint32_t len, bool is_signed, uint16_t elem_bits) {
3134 uint32_t index = 0;
3135 const uint8_t *val_ptr = val;
3136 uint16_t elem_bytes = zig_int_bytes(elem_bits);
3137
3138 while (index < len) {
3139 uint16_t tz = zig_ctz_big(val_ptr, is_signed, elem_bits);
3140 if (elem_bits <= 128) {
3141 ((uint8_t *)result)[index] = (uint8_t)tz;
3142 } else {
3143 ((uint16_t *)result)[index] = tz;
3144 }
3145 val_ptr += elem_bytes;
3146 index += 1;
3147 }
3148}
3149
3150static inline void zig_popcount_vec(void *result, const void *val, uint32_t len, bool is_signed, uint16_t elem_bits) {
3151 uint32_t index = 0;
3152 const uint8_t *val_ptr = val;
3153 uint16_t elem_bytes = zig_int_bytes(elem_bits);
3154
3155 while (index < len) {
3156 uint16_t pc = zig_popcount_big(val_ptr, is_signed, elem_bits);
3157 if (elem_bits <= 128) {
3158 ((uint8_t *)result)[index] = (uint8_t)pc;
3159 } else {
3160 ((uint16_t *)result)[index] = pc;
3161 }
3162 val_ptr += elem_bytes;
3163 index += 1;
3164 }
3165}
3166
2761/* ======================== Special Case Intrinsics ========================= */3167/* ======================== Special Case Intrinsics ========================= */
27623168
2763#if (_MSC_VER && _M_X64) || defined(__x86_64__)3169#if (_MSC_VER && _M_X64) || defined(__x86_64__)
src/codegen/c.zig+40-11
...@@ -2844,7 +2844,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -2844,7 +2844,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
2844 .cmp_vector => blk: {2844 .cmp_vector => blk: {
2845 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;2845 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
2846 const extra = f.air.extraData(Air.VectorCmp, ty_pl.payload).data;2846 const extra = f.air.extraData(Air.VectorCmp, ty_pl.payload).data;
2847 break :blk try cmpBuiltinCall(f, inst, extra, extra.compareOperator(), .operator, .bits);2847 break :blk try airCmpBuiltinCall(f, inst, extra, extra.compareOperator(), .operator, .bits,);
2848 },2848 },
2849 .cmp_lt_errors_len => try airCmpLtErrorsLen(f, inst),2849 .cmp_lt_errors_len => try airCmpLtErrorsLen(f, inst),
28502850
...@@ -3837,9 +3837,16 @@ fn airCmpOp(f: *Function, inst: Air.Inst.Index, operator: std.math.CompareOperat...@@ -3837,9 +3837,16 @@ fn airCmpOp(f: *Function, inst: Air.Inst.Index, operator: std.math.CompareOperat
3837 const target = f.object.dg.module.getTarget();3837 const target = f.object.dg.module.getTarget();
3838 const operand_bits = operand_ty.bitSize(target);3838 const operand_bits = operand_ty.bitSize(target);
3839 if (operand_ty.isInt() and operand_bits > 64)3839 if (operand_ty.isInt() and operand_bits > 64)
3840 return cmpBuiltinCall(f, inst, bin_op, operator, .cmp, if (operand_bits > 128) .bits else .none);3840 return airCmpBuiltinCall(
3841 f,
3842 inst,
3843 bin_op,
3844 operator,
3845 .cmp,
3846 if (operand_bits > 128) .bits else .none,
3847 );
3841 if (operand_ty.isRuntimeFloat())3848 if (operand_ty.isRuntimeFloat())
3842 return cmpBuiltinCall(f, inst, bin_op, operator, .operator, .none);3849 return airCmpBuiltinCall(f, inst, bin_op, operator, .operator, .none);
38433850
3844 const inst_ty = f.air.typeOfIndex(inst);3851 const inst_ty = f.air.typeOfIndex(inst);
3845 const lhs = try f.resolveInst(bin_op.lhs);3852 const lhs = try f.resolveInst(bin_op.lhs);
...@@ -3876,9 +3883,16 @@ fn airEquality(...@@ -3876,9 +3883,16 @@ fn airEquality(
3876 const target = f.object.dg.module.getTarget();3883 const target = f.object.dg.module.getTarget();
3877 const operand_bits = operand_ty.bitSize(target);3884 const operand_bits = operand_ty.bitSize(target);
3878 if (operand_ty.isInt() and operand_bits > 64)3885 if (operand_ty.isInt() and operand_bits > 64)
3879 return cmpBuiltinCall(f, inst, bin_op, operator, .cmp, if (operand_bits > 128) .bits else .none);3886 return airCmpBuiltinCall(
3887 f,
3888 inst,
3889 bin_op,
3890 operator,
3891 .cmp,
3892 if (operand_bits > 128) .bits else .none,
3893 );
3880 if (operand_ty.isRuntimeFloat())3894 if (operand_ty.isRuntimeFloat())
3881 return cmpBuiltinCall(f, inst, bin_op, operator, .operator, .none);3895 return airCmpBuiltinCall(f, inst, bin_op, operator, .operator, .none);
38823896
3883 const lhs = try f.resolveInst(bin_op.lhs);3897 const lhs = try f.resolveInst(bin_op.lhs);
3884 const rhs = try f.resolveInst(bin_op.rhs);3898 const rhs = try f.resolveInst(bin_op.rhs);
...@@ -5969,14 +5983,25 @@ fn airUnBuiltinCall(...@@ -5969,14 +5983,25 @@ fn airUnBuiltinCall(
5969 const inst_ty = f.air.typeOfIndex(inst);5983 const inst_ty = f.air.typeOfIndex(inst);
5970 const operand_ty = f.air.typeOf(ty_op.operand);5984 const operand_ty = f.air.typeOf(ty_op.operand);
59715985
5986 const inst_cty = try f.typeToCType(inst_ty, .complete);
5987 const ref_ret = switch (inst_cty.tag()) {
5988 else => false,
5989 .array, .vector => true,
5990 };
5991
5972 const writer = f.object.writer();5992 const writer = f.object.writer();
5973 const local = try f.allocLocal(inst, inst_ty);5993 const local = try f.allocLocal(inst, inst_ty);
5974 try f.writeCValue(writer, local, .Other);5994 if (!ref_ret) {
5975 try writer.writeAll(" = zig_");5995 try f.writeCValue(writer, local, .Other);
5976 try writer.writeAll(operation);5996 try writer.writeAll(" = ");
5977 try writer.writeByte('_');5997 }
5998 try writer.print("zig_{s}_", .{operation});
5978 try f.object.dg.renderTypeForBuiltinFnName(writer, operand_ty);5999 try f.object.dg.renderTypeForBuiltinFnName(writer, operand_ty);
5979 try writer.writeByte('(');6000 try writer.writeByte('(');
6001 if (ref_ret) {
6002 try f.writeCValue(writer, local, .FunctionArgument);
6003 try writer.writeAll(", ");
6004 }
5980 try f.writeCValue(writer, operand, .FunctionArgument);6005 try f.writeCValue(writer, operand, .FunctionArgument);
5981 try f.object.dg.renderBuiltinInfo(writer, operand_ty, info);6006 try f.object.dg.renderBuiltinInfo(writer, operand_ty, info);
5982 try writer.writeAll(");\n");6007 try writer.writeAll(");\n");
...@@ -6019,7 +6044,7 @@ fn airBinBuiltinCall(...@@ -6019,7 +6044,7 @@ fn airBinBuiltinCall(
6019 return local;6044 return local;
6020}6045}
60216046
6022fn cmpBuiltinCall(6047fn airCmpBuiltinCall(
6023 f: *Function,6048 f: *Function,
6024 inst: Air.Inst.Index,6049 inst: Air.Inst.Index,
6025 data: anytype,6050 data: anytype,
...@@ -6034,7 +6059,11 @@ fn cmpBuiltinCall(...@@ -6034,7 +6059,11 @@ fn cmpBuiltinCall(
6034 const rhs = try f.resolveInst(data.rhs);6059 const rhs = try f.resolveInst(data.rhs);
6035 try reap(f, inst, &.{ data.lhs, data.rhs });6060 try reap(f, inst, &.{ data.lhs, data.rhs });
60366061
6037 const ref_ret = inst_ty.tag() != .bool;6062 const inst_cty = try f.typeToCType(inst_ty, .complete);
6063 const ref_ret = switch (inst_cty.tag()) {
6064 else => false,
6065 .array, .vector => true,
6066 };
60386067
6039 const writer = f.object.writer();6068 const writer = f.object.writer();
6040 const local = try f.allocLocal(inst, inst_ty);6069 const local = try f.allocLocal(inst, inst_ty);
test/behavior/bugs/10147.zig-1
...@@ -6,7 +6,6 @@ test "test calling @clz on both vector and scalar inputs" {...@@ -6,7 +6,6 @@ test "test calling @clz on both vector and scalar inputs" {
6 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO6 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
7 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO7 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
9 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
10 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO9 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1110
12 var x: u32 = 0x1;11 var x: u32 = 0x1;
test/behavior/math.zig+6-2
...@@ -100,7 +100,6 @@ test "@clz vectors" {...@@ -100,7 +100,6 @@ test "@clz vectors" {
100 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO100 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
101 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO101 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
102 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO102 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
103 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
104 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO103 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
105104
106 try testClzVectors();105 try testClzVectors();
...@@ -163,7 +162,6 @@ test "@ctz vectors" {...@@ -163,7 +162,6 @@ test "@ctz vectors" {
163 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO162 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
164 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO163 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
165 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO164 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
166 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
167 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO165 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
168166
169 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {167 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
...@@ -1562,6 +1560,12 @@ test "signed zeros are represented properly" {...@@ -1562,6 +1560,12 @@ test "signed zeros are represented properly" {
1562 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO1560 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1563 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1561 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
15641562
1563 if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and
1564 builtin.zig_backend == .stage2_c)
1565 {
1566 return error.SkipZigTest;
1567 }
1568
1565 const S = struct {1569 const S = struct {
1566 fn doTheTest() !void {1570 fn doTheTest() !void {
1567 try testOne(f16);1571 try testOne(f16);
test/behavior/popcount.zig-1
...@@ -67,7 +67,6 @@ fn testPopCountIntegers() !void {...@@ -67,7 +67,6 @@ fn testPopCountIntegers() !void {
67}67}
6868
69test "@popCount vectors" {69test "@popCount vectors" {
70 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
71 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO70 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
72 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO71 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
73 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO72 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO