Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmable Label & Jump #11

Closed
Constellation opened this issue Mar 4, 2014 · 13 comments
Closed

Programmable Label & Jump #11

Constellation opened this issue Mar 4, 2014 · 13 comments

Comments

@Constellation
Copy link
Contributor

declarative な label だけではなく, programmable な Label & Jump の concept と実装を提案します.

例えば, V8 assembler のように,

void AsmSmallProcedure(Label* bailout) {
    asm(...);
    asm(...);
    cmp(...);
    je(bailout);  // bind
    ...;
}

Label bailout;
AsmSmallProcedure(&bailout);
...
bind(&bailout);  // bind jump target here.

このようにすることで, asm fragments の module 化や, label の取り回しが便利になり,
例えば, iv/lv5/breaker がやってるように https://github.com/Constellation/iv/blob/master/iv/lv5/breaker/compiler.h#L2966
unique な文字列を生成してというようなやり方よりもより label の取り回しが簡単になるのではないかと考えています. このようにすることで, Label を宣言的でなく扱うことができ, 何かの動的な入力から動的にコードを出力したい場合, 特に JIT compiler にとっては非常に便利です.

また同時に, JSC Macro Assembler のように Jump というものも同時に提案します.

Jump AsmSmallProcedure() {
    asm(...);
    asm(...);
    cmp(...);
    Jump jump = je();
    ...;
    return jump;
}

Jump jump = AsmSmallProcedure();
...
link(&jump);  // link jump target here.

みたいにして記述することができると, 非常に取り回しが便利になるのではないでしょうか.

Label と Jump を組み合わせて,

Jump AsmSmallProcedure() {
    asm(...);
    asm(...);
    cmp(...);
    Jump jump = je();
    ...;
    return jump;
}

jmp(".start");
// unreachable

Label label;
// reach here later
bind(&label);
...

L(".start");
Jump jump = AsmSmallProcedure();
...
link(&jump, &label);  // link jump target to label

というようなことができれば, 現在の declarative な label に加えて, programmable な label や jump というのが実現できるのではないかと考えています.

gen.link(&jump, &label)gen.link(&jump) とするか, jump.link(gen, label) のようにするかについては不明です.

@herumi
Copy link
Owner

herumi commented Mar 8, 2014

bindは一度しかできないという制約を入れるのはありでしょうか。
また二つ目のJmpについてですが、Labelがコピー可能であれば

Label AsmSmallProcedure()
{
  Label label;
  je(label);
  return label;
}

Label label1;
bind(&label1);

Label label2 = AsmSmallProcedure();

link(label2, label1); // 空labelへのlinkは一度だけという制約を入れるかも。

とすることで同等の機能が実現できるという理解はあってますか。

@Constellation
Copy link
Contributor Author

bindは一度しかできないという制約を入れるのはありでしょうか。

ありだと思います.

また二つ目のJmpについてですが、Labelがコピー可能であれば

link(label2, label1); が, je の jump 先を label1 へ向けるという semantics を持つのであれば, 同等です.

@herumi
Copy link
Owner

herumi commented Mar 8, 2014

ありがとうございます。ではその方向で実装を考えてみようと思います。制約はAutoGrowでないときに過去のラベルを全て保持しておかないといけなくなりそうなことから入れようかと思ってます。

@herumi
Copy link
Owner

herumi commented Mar 16, 2014

実装してみました。link(label2, label1)はassignL(dstLabel, srcLabel);として定義しました(dstLabelのjmp先をsrcLabelと同じにするという挙動)。

@Constellation
Copy link
Contributor Author

ありがとうございます!! 試してみますですー.

@herumi
Copy link
Owner

herumi commented Mar 16, 2014

不具合、改善要望ありましたらお願いします。

@herumi herumi closed this as completed Mar 16, 2014
@Constellation
Copy link
Contributor Author

@miura1729 may also benefit from this new feature :)

iv/aero change Constellation/iv@c20c577
iv/lv5/breaker change Constellation/iv@baddc45

@Constellation
Copy link
Contributor Author

iv/aero change is now heavily tested by iv/lv5 test cases including

  • SunSpider
  • V8-suite
  • iv_unit_tests (including tests for iv/aero)
  • lv5_unit_tests (lv5 engine regression tests)
  • Test262 (11648 tests)

And currently there's no regression. Great!
https://travis-ci.org/Constellation/iv/jobs/20920736

@herumi
Copy link
Owner

herumi commented Mar 17, 2014

いきなりヘビーに使っていただいてありがとうございます&今まで面倒くさいやり方しかできなくてすいませんでした。

@herumi
Copy link
Owner

herumi commented Mar 19, 2014

ラベルにリファレンスカウンタを入れて参照回数が0になったら定義済みラベルのリストから削除するようにしてみました。
502f65a

小さいコードでは殆ど関係ないと思いますが、ある程度ステップ数が大きくてラベルが局所的なものが多いコードではこの修正はあったほうがうれしいでしょうか。
以前、std::mapよりもstd::unordered_mapの方がよくなるパターンがあると仰っていたので…。

@herumi herumi reopened this Mar 19, 2014
@Constellation
Copy link
Contributor Author

おおお, 確かに, local といったスコープがないので label が際限なく増えるのはまずいですね, ありがとうございます, 早速試してみます.

@Constellation
Copy link
Contributor Author

rich_label branch のものの実装に入れ替え, test が全て通るのを確認しました!

@herumi
Copy link
Owner

herumi commented Mar 20, 2014

確認ありがとうございました。
inLocalLabel(), outLocalLabel()で挟んだラベルも同様の処理ができますね(今頃気がついた)。対応しておきます。

@herumi herumi closed this as completed May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants