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);
279279 static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##RhsType rhs) { \
280280 return lhs operator rhs; \
281281 }
282#define zig_int_operators(w) \
283 zig_int_operator(u##w, u##w, and, &) \
284 zig_int_operator(i##w, i##w, and, &) \
285 zig_int_operator(u##w, u##w, or, |) \
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
282#define zig_int_basic_operator(Type, operation, operator) \
283 zig_int_operator(Type, Type, operation, operator)
284#define zig_int_shift_operator(Type, operation, operator) \
285 zig_int_operator(Type, u8, operation, operator)
299286#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\
300297 static inline zig_i##w zig_shr_i##w(zig_i##w lhs, zig_u8 rhs) { \
301298 zig_i##w sign_mask = lhs < zig_as_i##w(0) ? -zig_as_i##w(1) : zig_as_i##w(0); \
302299 return ((lhs ^ sign_mask) >> rhs) ^ sign_mask; \
......@@ -319,10 +316,14 @@ zig_int_operators(64)
319316 return (val & zig_as_u##w(1) << (bits - zig_as_u8(1))) != 0 \
320317 ? val | zig_minInt(i##w, bits) : val & zig_maxInt(i##w, bits); \
321318 } \
319\
320 zig_int_basic_operator(u##w, div_floor, /) \
322321\
323322 static inline zig_i##w zig_div_floor_i##w(zig_i##w lhs, zig_i##w rhs) { \
324323 return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < zig_as_i##w(0)); \
325324 } \
325\
326 zig_int_basic_operator(u##w, mod, %) \
326327\
327328 static inline zig_i##w zig_mod_i##w(zig_i##w lhs, zig_i##w rhs) { \
328329 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
24342434 .bool_or, .bit_or => try airBinOp(f, inst, "|", "or", .None),
24352435 .xor => try airBinOp(f, inst, "^", "xor", .None),
24362436 .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),
24382438 .shl_exact => try airBinOp(f, inst, "<<", "shl", .None),
24392439 .not => try airNot (f, inst),
24402440