krakjoe / jitfu
JITFu 的存根和源代码
dev-master
2018-04-06 18:59 UTC
This package is auto-updated.
Last update: 2024-09-09 13:06:31 UTC
README
乔JIT-Fu的艺术课!
JIT-Fu 是一个 PHP 扩展,它通过 libjit
提供了面向对象的 API,用于创建 PHP 用户空间的本地指令。
免责声明:上面的大象是艺术家的演绎,实际动物可能存在或不存在...
斐波那契
因为显然,这非常重要...
<?php use JITFU\Context; use JITFU\Type; use JITFU\Signature; use JITFU\Func; use JITFU\Value; $context = new Context(); $integer = Type::of(Type::int); $function = new Func($context, new Signature($integer, [$integer]), function($args) use($integer) { $zero = new Value($this, 0, $integer); $one = new Value($this, 1, $integer); $two = new Value($this, 2, $integer); /* if ($arg == 0) return 0; */ $this->doIf( $this->doEq($args[0], $zero), function() use ($zero) { $this->doReturn($zero); } ); /* if ($arg == 1) return 1; */ $this->doIf( $this->doEq($args[0], $one), function() use($one) { $this->doReturn($one); } ); /* return $function($arg-1) + $function($arg-2); */ $this->doReturn( $this->doAdd( $this->doCall($this, [$this->doSub($args[0], $one)]), $this->doCall($this, [$this->doSub($args[0], $two)]))); }); if (stripos('win', PHP_OS) !== 0) { $function->dump("Fibonacci"); } var_dump($function(40)); /* __invoke with magicalness */ ?>
上面的代码在 Linux 上将产生类似以下输出
[joe@localhost jit]$ time php -dextension=jitfu.so objects.php
function Fibonacci(i1 : int) : int
incoming_reg(i1, rdi)
.L:
i6 = i1 == 0
if i1 != 0 then goto .L0
.L:
return_int(0)
ends_in_dead
.L0:
i7 = i1 == 1
if i1 != 1 then goto .L1
.L:
return_int(1)
ends_in_dead
.L1:
i8 = i1 - 1
outgoing_reg(i8, rdi)
call 0x08215dfd0
.L:
return_reg(i10, rax)
i12 = i1 - 2
outgoing_reg(i12, rdi)
call 0x08215dfd0
.L:
return_reg(i14, rax)
i15 = i10 + i14
return_int(i15)
ends_in_dead
.L:
.L:
end
int(102334155)
real 0m1.001s
user 0m0.997s
sys 0m0.003s
在我的机器上,这比 PHP 快了大约 60 倍。
这个库对编译 Zend 指令集没有用
安装说明
Linux
此扩展正在针对最新的 libjit 源代码开发,即使系统中已有,也建议安装一个新的 libjit 版本
git clone git://git.sv.gnu.org/libjit.git
cd libjit
./auto_gen.sh
./configure --prefix=/opt
make
sudo make install
现在您可以构建 PHP 扩展了
git clone https://github.com/krakjoe/jitfu
cd jitfu
phpize
./configure --with-jitfu=/opt
make
sudo make install
上面的示例会生成 libjit 和 JIT-Fu 的构建
Windows
周一凌晨 1-2 点 UTC 构建master分支的快照。目前只有针对 PHP 5.5 和 5.6 的 VC11 x86 构建可用,这些应该与可以从 windows.php.net 下载的包兼容。捆绑的 libjit 是从修补过的 master 分支使用 MinGW 构建的自包含二进制文件。
- 从 这里 下载适合您的 PHP 安装的相应包。
- 将
php_jitfu.dll
放置在配置的extension_dir
中。 - 将
libjit.dll
放置在出现在您的%PATH%
中的目录中。
注意:Windows 上目前不可用 dump()
方法。在 Windows 上调用这些方法将引发 JITFU\Exception
。
待办事项
- 尽可能多的集成测试
- 其他酷炫的东西,可能吧
- pecl & phpdoc