Commit 31f8a0b8
31f8a0b858c1Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #240 from mame/pr/poly-int-bit-extract
fix(codegen): bit-extraction on poly-typed int receiver
Details
- Commit
- 31f8a0b858c1
- Parent
- 15f7e5f356d7
- Merge parent
- 2165f0b4b844
spinel_codegen.rbmodifiedView file
@@ -21673,6 +21673,21 @@
2167321673
end2167421674
tmp = new_temp2167521675
emit(" " + ret_ct + " " + tmp + " = " + ret_def + ";")21676+
# `int[i]` (bit-extraction) on a poly receiver. When a CPU21677+
# register / scratch ivar is widened to sp_RbVal but still21678+
# carries an int value, `pc[8]` (the page-bit test in branch21679+
# instructions etc.) must compile to `(pc >> 8) & 1`, not to21680+
# the array dispatch in the SP_TAG_OBJ block below — which21681+
# would silently leave the result at nil and miscount cycles.21682+
if mname == "[]" && arg_compiled.length >= 121683+
a0_int = arg_compiled[0]21684+
if arg_types.length > 0 && arg_types[0] == "poly"21685+
a0_int = "(" + a0_int + ").v.i"21686+
end21687+
bit = "((" + recv_tmp + ".v.i >> (" + a0_int + ")) & 1)"21688+
brhs = is_poly_ret == 1 ? "sp_box_int(" + bit + ")" : bit21689+
emit(" if (" + recv_tmp + ".tag == SP_TAG_INT) " + tmp + " = " + brhs + ";")21690+
end2167621691
emit(" if (" + recv_tmp + ".tag == SP_TAG_OBJ) {")2167721692
# User-class dispatch2167821693
i = 0test/poly_int_bit_index.rbaddedView file
Loading diff…
test/poly_int_bit_index.rb.expectedaddedView file
Loading diff…