本文整理汇总了Python中tdasm.Tdasm.register_macro方法的典型用法代码示例。如果您正苦于以下问题:Python Tdasm.register_macro方法的具体用法?Python Tdasm.register_macro怎么用?Python Tdasm.register_macro使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tdasm.Tdasm
的用法示例。
在下文中一共展示了Tdasm.register_macro方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
code += lst_inst2[l] + "\n"
for l in range(len(lst_inst2), len(lst_inst1)):
code += lst_inst1[l] + "\n"
return code
def arth128_32(tokens):
return arth_mix(tokens, 128, 32)
def arth32_128(tokens):
return arth_mix(tokens, 32, 128)
def arth128_128(tokens):
return arth_mix(tokens, 128, 128)
def arth32_32(tokens):
return arth_mix(tokens, 32, 32)
if __name__ == "__main__":
asm = Tdasm()
asm.register_macro("arth128", arth128)
asm.register_macro("arth32", arth32)
mc = asm.assemble(ASM_CODE)
run = Runtime()
ds = run.load("test", mc)
run.run("test")
print(ds["rez"])
示例2: create_assembler
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
def create_assembler(self):
assembler = Tdasm()
assembler.register_macro('eq128', arithmetic128)
assembler.register_macro('eq32', arithmetic32)
assembler.register_macro('broadcast', broadcast)
assembler.register_macro('if', macro_if)
assembler.register_macro('dot', dot_product)
assembler.register_macro('normalization', normalization)
assembler.register_macro('cross', cross_product)
return assembler
示例3: get_asm
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
def get_asm():
from renmas.macros import eq32, eq128, eq32_32, eq32_128, eq128_128, eq128_32
from renmas.macros import dot_product, macro_if, broadcast
global assembler
if assembler is None:
assembler = Tdasm()
assembler.register_macro("eq128", eq128)
assembler.register_macro("eq32", eq32)
assembler.register_macro("eq128_32", eq128_32)
assembler.register_macro("eq32_128", eq32_128)
assembler.register_macro("eq128_128", eq128_128)
assembler.register_macro("eq32_32", eq32_32)
assembler.register_macro("dot", dot_product)
assembler.register_macro("if", macro_if)
assembler.register_macro("broadcast", broadcast)
return assembler
示例4: create_assembler
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
def create_assembler():
assembler = Tdasm()
assembler.register_macro('mov', mov)
assembler.register_macro('lea', lea)
assembler.register_macro('eq128', arithmetic128)
assembler.register_macro('eq32', arithmetic32)
assembler.register_macro('broadcast', broadcast)
assembler.register_macro('if', macro_if)
assembler.register_macro('dot', dot_product)
assembler.register_macro('normalization', normalization)
assembler.register_macro('cross', cross_product)
assembler.register_macro('generate_one', generate_one)
assembler.register_macro('push', push)
assembler.register_macro('pop', pop)
assembler.register_macro('sqrtss', sqrtss)
return assembler
示例5: Tdasm
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
float v3[4] = 1.0, 5.5, 1.0, 2.0
float v4[4] = 1.0, 5.5, 1.0, 2.0
float v5[4] = 1.0, 5.5, 1.0, 2.0
float v6[4] = 1.0, 5.5, 1.0, 2.0
float v7[4]
#CODE
macro eq128 xmm3 = v3
macro eq128 xmm2 = v2
macro eq128 xmm5 = v1 - xmm3
macro eq128_128 v7 = xmm3 * v3, v6 = v1 + v2
#END
"""
if __name__ == "__main__":
asm = Tdasm()
asm.register_macro("eq128", eq128)
asm.register_macro("eq32", eq32)
asm.register_macro("eq128_32", eq128_32)
asm.register_macro("eq32_32", eq32_32)
asm.register_macro("eq128_128", eq128_128)
asm.register_macro("dot", dot_product)
asm.register_macro("if", macro_if)
mc = asm.assemble(ASM)
mc.print_machine_code()
runtime = Runtime()
ds = runtime.load("test", mc)
runtime.run("test")
print(ds["v6"])
print(ds["v7"])
示例6: _create_assembler
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
def _create_assembler(self):
assembler = Tdasm()
self._macro_call = macro_call = MacroCall()
assembler.register_macro('call', macro_call.macro_call)
assembler.register_macro('eq128', arithmetic128)
assembler.register_macro('eq32', arithmetic32)
assembler.register_macro('broadcast', broadcast)
assembler.register_macro('if', macro_if)
assembler.register_macro('dot', dot_product)
assembler.register_macro('normalization', normalization)
assembler.register_macro('cross', cross_product)
self._macro_spectrum = MacroSpectrum(self)
assembler.register_macro('spectrum', self._macro_spectrum.macro_spectrum)
return assembler
示例7: TestTrigs
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
class TestTrigs(unittest.TestCase):
def setUp(self):
self.runtime = Runtime()
self.macro_call = MacroCall()
self.macro_call.set_runtimes([self.runtime])
self.assembler = Tdasm()
self.assembler.register_macro('call', self.macro_call.macro_call)
def check_seq(self, seq1, seq2, precision):
for x, y in zip(seq1, seq2):
self.assertAlmostEqual(x, y, precision)
def ss_test(self, func_name, func, precision=3, negative=True):
mc = self.assembler.assemble(asm_code(func_name))
ds = self.runtime.load('test_fun', mc)
for x in range(100):
if negative:
num = (random() - 0.5) * 2
else:
num = random()
ds["v1"] = (num, num, num, num)
self.runtime.run("test_fun")
rez_asm = ds["v1"][0]
self.assertAlmostEqual(rez_asm, func(num), precision)
def ps_test(self, func_name, func, precision=3, negative=True):
mc = self.assembler.assemble(asm_code(func_name))
ds = self.runtime.load('test_fun', mc)
for x in range(100):
if negative:
num1, num2, num3, num4 = [(random() - 0.5)*2 for i in range(4)]
else:
num1, num2, num3, num4 = random(), random(), random(), random()
ds["v1"] = (num1, num2, num3, num4)
self.runtime.run("test_fun")
rez_asm = ds["v1"]
self.check_seq(rez_asm, [func(num1), func(num2), func(num3), func(num4)], precision)
def test_sin(self):
self.ss_test('fast_sin_ss', sin)
def test_sin_ps(self):
self.ps_test('fast_sin_ps', sin)
def test_cos(self):
self.ss_test('fast_cos_ss', cos)
def test_cos_ps(self):
self.ps_test('fast_cos_ps', cos)
def test_exp(self):
self.ss_test('fast_exp_ss', exp)
def test_exp_ps(self):
self.ps_test('fast_exp_ps', exp)
def test_atan(self):
self.ss_test('fast_atan_ss', atan)
def test_atan_ps(self):
self.ps_test('fast_atan_ps', atan)
def test_asin(self):
self.ss_test('fast_asin_ss', asin)
def test_asin_ps(self):
self.ps_test('fast_asin_ps', asin)
def test_acos(self): # FIXME function calculate wrong result for negative numbers
self.ss_test('fast_acos_ss', acos, precision=2, negative=False)
def test_acos_ps(self):
self.ps_test('fast_acos_ps', acos, precision=2)
def test_tan(self):
self.ss_test('fast_tan_ss', tan)
def test_tan_ps(self):
self.ps_test('fast_tan_ps', tan)
def test_log(self):
self.ss_test('fast_log_ss', log, negative=False)
def test_log_ps(self):
self.ps_test('fast_log_ps', log, negative=False)
def test_pow_ss(self):
mc = self.assembler.assemble(asm_code('fast_pow_ss'))
ds = self.runtime.load('test_fun', mc)
for x in range(100):
num = random()
ds["v1"] = (num, num, num, num)
num2 = (random() - 0.5) * 2
ds["v2"] = (num2, num2, num2, num2)
self.runtime.run("test_fun")
rez_asm = ds["v1"][0]
self.assertAlmostEqual(rez_asm, pow(num, num2), 2)
#.........这里部分代码省略.........
示例8: Runtime
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import register_macro [as 别名]
code = """
#DATA
float v1[4]
float v2[4]
#CODE
movaps xmm0, oword [v1]
movaps xmm1, oword [v2]
"""
code += "macro call " + func_name + """
movaps oword [v1], xmm0
movaps oword [v2], xmm6
#END
"""
return code
runtime = Runtime()
macro_call = MacroCall()
macro_call.set_runtimes([runtime])
assembler = Tdasm()
assembler.register_macro('call', macro_call.macro_call)
assembler.assemble(asm_code('fast_sin_ps'))
assembler.assemble(asm_code('fast_cos_ps'))
start = time.clock()
runtime = Runtime()
macro_call.set_runtimes([runtime])
end = time.clock()
print(end-start)