authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-11-02 22:57:10-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-11-02 23:00:10-04:00
log085f6fd8f729423158b6f7a5f8e6f50f78fef18f
tree3765fe467ab9f75b70591eb9fab4d798aac97284
parent4537c1b8b6575c853ceaa7ab329e8b84d946249d

cbe: use wrapping for left shifts


2 files changed, 19 insertions(+), 18 deletions(-)

lib/include/zig.h+18-17
...@@ -279,24 +279,21 @@ zig_extern void *memset (void *, int, zig_usize);...@@ -279,24 +279,21 @@ zig_extern void *memset (void *, int, zig_usize);
279 static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##RhsType rhs) { \279 static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##RhsType rhs) { \
280 return lhs operator rhs; \280 return lhs operator rhs; \
281 }281 }
282#define zig_int_operators(w) \282#define zig_int_basic_operator(Type, operation, operator) \
283 zig_int_operator(u##w, u##w, and, &) \283 zig_int_operator(Type, Type, operation, operator)
284 zig_int_operator(i##w, i##w, and, &) \284#define zig_int_shift_operator(Type, operation, operator) \
285 zig_int_operator(u##w, u##w, or, |) \285 zig_int_operator(Type, u8, operation, operator)
286 zig_int_operator(i##w, i##w, or, |) \
287 zig_int_operator(u##w, u##w, xor, ^) \
288 zig_int_operator(i##w, i##w, xor, ^) \
289 zig_int_operator(u##w, u8, shl, <<) \
290 zig_int_operator(i##w, u8, shl, <<) \
291 zig_int_operator(u##w, u8, shr, >>) \
292 zig_int_operator(u##w, u##w, div_floor, /) \
293 zig_int_operator(u##w, u##w, mod, %)
294zig_int_operators(8)
295zig_int_operators(16)
296zig_int_operators(32)
297zig_int_operators(64)
298
299#define zig_int_helpers(w) \286#define zig_int_helpers(w) \
287 zig_int_basic_operator(u##w, and, &) \
288 zig_int_basic_operator(i##w, and, &) \
289 zig_int_basic_operator(u##w, or, |) \
290 zig_int_basic_operator(i##w, or, |) \
291 zig_int_basic_operator(u##w, xor, ^) \
292 zig_int_basic_operator(i##w, xor, ^) \
293 zig_int_shift_operator(u##w, shl, <<) \
294 zig_int_shift_operator(i##w, shl, <<) \
295 zig_int_shift_operator(u##w, shr, >>) \
296\
300 static inline zig_i##w zig_shr_i##w(zig_i##w lhs, zig_u8 rhs) { \297 static inline zig_i##w zig_shr_i##w(zig_i##w lhs, zig_u8 rhs) { \
301 zig_i##w sign_mask = lhs < zig_as_i##w(0) ? -zig_as_i##w(1) : zig_as_i##w(0); \298 zig_i##w sign_mask = lhs < zig_as_i##w(0) ? -zig_as_i##w(1) : zig_as_i##w(0); \
302 return ((lhs ^ sign_mask) >> rhs) ^ sign_mask; \299 return ((lhs ^ sign_mask) >> rhs) ^ sign_mask; \
...@@ -319,10 +316,14 @@ zig_int_operators(64)...@@ -319,10 +316,14 @@ zig_int_operators(64)
319 return (val & zig_as_u##w(1) << (bits - zig_as_u8(1))) != 0 \316 return (val & zig_as_u##w(1) << (bits - zig_as_u8(1))) != 0 \
320 ? val | zig_minInt(i##w, bits) : val & zig_maxInt(i##w, bits); \317 ? val | zig_minInt(i##w, bits) : val & zig_maxInt(i##w, bits); \
321 } \318 } \
319\
320 zig_int_basic_operator(u##w, div_floor, /) \
322\321\
323 static inline zig_i##w zig_div_floor_i##w(zig_i##w lhs, zig_i##w rhs) { \322 static inline zig_i##w zig_div_floor_i##w(zig_i##w lhs, zig_i##w rhs) { \
324 return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < zig_as_i##w(0)); \323 return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < zig_as_i##w(0)); \
325 } \324 } \
325\
326 zig_int_basic_operator(u##w, mod, %) \
326\327\
327 static inline zig_i##w zig_mod_i##w(zig_i##w lhs, zig_i##w rhs) { \328 static inline zig_i##w zig_mod_i##w(zig_i##w lhs, zig_i##w rhs) { \
328 zig_i##w rem = lhs % rhs; \329 zig_i##w rem = lhs % rhs; \
src/codegen/c.zig+1-1
...@@ -2434,7 +2434,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO...@@ -2434,7 +2434,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
2434 .bool_or, .bit_or => try airBinOp(f, inst, "|", "or", .None),2434 .bool_or, .bit_or => try airBinOp(f, inst, "|", "or", .None),
2435 .xor => try airBinOp(f, inst, "^", "xor", .None),2435 .xor => try airBinOp(f, inst, "^", "xor", .None),
2436 .shr, .shr_exact => try airBinBuiltinCall(f, inst, "shr", .None),2436 .shr, .shr_exact => try airBinBuiltinCall(f, inst, "shr", .None),
2437 .shl, => try airBinBuiltinCall(f, inst, "shl", .None),2437 .shl, => try airBinBuiltinCall(f, inst, "shlw", .Bits),
2438 .shl_exact => try airBinOp(f, inst, "<<", "shl", .None),2438 .shl_exact => try airBinOp(f, inst, "<<", "shl", .None),
2439 .not => try airNot (f, inst),2439 .not => try airNot (f, inst),
24402440