本文整理汇总了Python中tdasm.Tdasm.assemble方法的典型用法代码示例。如果您正苦于以下问题:Python Tdasm.assemble方法的具体用法?Python Tdasm.assemble怎么用?Python Tdasm.assemble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tdasm.Tdasm
的用法示例。
在下文中一共展示了Tdasm.assemble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def __init__(self):
asm = Tdasm()
m = asm.assemble(MEMCPY)
self.r = Runtime()
self.ds = self.r.load("memcpy", m)
m2 = asm.assemble(BLTRGBA)
self.ds2 = self.r.load("bltrgba", m2)
m3 = asm.assemble(BLTFLOATRGBA)
self.ds3 = self.r.load("bltfloatrgba", m3)
示例2: test_pow_ps
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_pow_ps(self):
asm = Tdasm()
mc = asm.assemble(POW_CODE_PS)
runtime = Runtime()
load_math_func("fast_pow_ps", runtime)
ds = runtime.load("pow_ps", mc)
for x in range(1000):
num1 = random.random() * 3
num2 = random.random() * 3
num3 = random.random() * 3
num4 = random.random() * 3
num5 = random.random() * 3
num6 = random.random() * 3
num7 = random.random() * 3
num8 = random.random() * 3
ds["v1"] = (num1, num2, num3, num4)
ds["v2"] = (num5, num6, num7, num8)
runtime.run("pow_ps")
rez_asm = ds["v1"]
rez_py1 = math.pow(num1, num5)
rez_py2 = math.pow(num2, num6)
rez_py3 = math.pow(num3, num7)
rez_py4 = math.pow(num4, num8)
self.assertAlmostEqual(rez_asm[0], rez_py1, 1)
self.assertAlmostEqual(rez_asm[1], rez_py2, 1)
self.assertAlmostEqual(rez_asm[2], rez_py3, 1)
self.assertAlmostEqual(rez_asm[3], rez_py4, 1)
示例3: prepare
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def prepare(self, runtimes):
self._load_color_funcs(runtimes)
if self.loader:
self.loader(runtimes)
for s in self._shaders:
s.prepare(runtimes)
self._runtimes = runtimes
asm = Tdasm()
name = 'shader' + str(id(self))
for fun in self._functions:
fun_name, fun_label, avx, bit = fun
load_asm_function(fun_name, fun_label, runtimes, avx, bit)
ds = []
for r in runtimes:
if not r.global_exists(self._name):
if self._name in self._mc_cache:
ds.append(r.load(name, self._mc_cache[self._name]))
else:
mc = asm.assemble(self._code, self._func)
self._mc_cache[self._name] = mc
ds.append(r.load(name, mc))
if ds:
self._ds = ds
示例4: test_sincos_ps
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_sincos_ps(self):
asm = Tdasm()
mc = asm.assemble(SINCOS_CODE_PS)
runtime = Runtime()
load_math_func("fast_sincos_ps", runtime)
ds = runtime.load("sincos_ps", mc)
for x in range(1000):
num1 = random.random() * 2000
num2 = random.random() * 2000
num3 = random.random() * 2000
num4 = random.random() * 2000
ds["v1"] = (num1, num2, num3, num4)
runtime.run("sincos_ps")
rez_asm_sin = ds["v1"]
rez_asm_cos = ds["v2"]
rez_py1_sin = math.sin(num1)
rez_py2_sin = math.sin(num2)
rez_py3_sin = math.sin(num3)
rez_py4_sin = math.sin(num4)
rez_py1_cos = math.cos(num1)
rez_py2_cos = math.cos(num2)
rez_py3_cos = math.cos(num3)
rez_py4_cos = math.cos(num4)
self.assertAlmostEqual(rez_asm_sin[0], rez_py1_sin, 3)
self.assertAlmostEqual(rez_asm_sin[1], rez_py2_sin, 3)
self.assertAlmostEqual(rez_asm_sin[2], rez_py3_sin, 3)
self.assertAlmostEqual(rez_asm_sin[3], rez_py4_sin, 3)
self.assertAlmostEqual(rez_asm_cos[0], rez_py1_cos, 3)
self.assertAlmostEqual(rez_asm_cos[1], rez_py2_cos, 3)
self.assertAlmostEqual(rez_asm_cos[2], rez_py3_cos, 3)
self.assertAlmostEqual(rez_asm_cos[3], rez_py4_cos, 3)
示例5: compile
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def compile(self, shaders=[]):
stms = parse(self._code)
cgen = CodeGenerator()
asm, ret_type = cgen.generate_code(
stms, args=self._args, is_func=self._is_func, name=self._name, func_args=self._func_args, shaders=shaders
)
self._asm_code = asm
self._ret_type = ret_type
asm = Tdasm()
self._mc = asm.assemble(self._asm_code, self._is_func)
示例6: create_float_image
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def create_float_image(runtime):
img = renmas.gui.ImageFloatRGBA(150, 150)
img.set_pixel_asm(runtime, "set_pixel")
asm = Tdasm()
mc = asm.assemble(ASM)
runtime.load("write", mc)
runtime.run("write")
return img
示例7: test_log
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_log(self):
asm = Tdasm()
mc = asm.assemble(LOG_CODE)
runtime = Runtime()
load_math_func("fast_log_ss", runtime)
ds = runtime.load("log", mc)
for x in range(1000):
num = random.random()
ds["x"] = num
runtime.run("log")
rez_asm = ds["x"]
rez_py = math.log(num)
self.assertAlmostEqual(rez_asm, rez_py, 3)
示例8: test_atan
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_atan(self):
asm = Tdasm()
mc = asm.assemble(ATAN_CODE)
runtime = Runtime()
load_math_func("fast_atan_ss", runtime)
ds = runtime.load("atan", mc)
for x in range(1000):
num = random.random() * 2000
ds["x"] = num
runtime.run("atan")
rez_asm = ds["x"]
rez_py = math.atan(num)
self.assertAlmostEqual(rez_asm, rez_py, 3)
示例9: test_exp
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_exp(self):
asm = Tdasm()
mc = asm.assemble(EXP_CODE)
runtime = Runtime()
load_math_func("fast_exp_ss", runtime)
ds = runtime.load("exp", mc)
for x in range(1000):
num = random.random() * 4
ds["x"] = num
runtime.run("exp")
rez_asm = ds["x"]
rez_py = math.exp(num)
self.assertAlmostEqual(rez_asm, rez_py, 2)
示例10: compile
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def compile(self, shaders=[], color_mgr=None):
stms = parse(self._code)
cgen = CodeGenerator()
asm, ret_type, fns = cgen.generate_code(stms, args=self._args,
is_func=self._is_func,
name=self._name,
func_args=self._func_args,
shaders=shaders,
color_mgr=color_mgr)
self._asm_code = asm
self._ret_type = ret_type
self._ext_functions = fns
asm = Tdasm()
self._mc = asm.assemble(self._asm_code, naked=self._is_func,
ia32=not cgen.BIT64)
示例11: set_pixel_asm
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def set_pixel_asm(self, runtime, label):
bits = platform.architecture()[0]
if bits == "64bit": ecx = "rcx"
else: ecx = "ecx"
if util.AVX:
line = "vmovaps oword [" + ecx + "], xmm0"
else:
line = "movaps oword [" + ecx + "], xmm0"
bits = platform.architecture()[0]
if bits == "64bit":
l1 = "uint64 ptr_buffer"
l2 = "mov rcx, qword [ptr_buffer]"
l3 = "add rcx, rax"
else:
l1 = "uint32 ptr_buffer"
l2 = "mov ecx, dword [ptr_buffer]"
l3 = "add ecx, eax"
asm_code = """
#DATA
"""
asm_code += l1 + """
uint32 pitch
#CODE
; eax = x , ebx = y, value = xmm0
"""
asm_code += "global " + label + ": \n"
asm_code += """
imul ebx, dword [pitch]
imul eax , eax, 16
"""
asm_code += l2 + """
add eax, ebx
"""
asm_code += l3 + "\n"
asm_code += line + """
ret
"""
asm = Tdasm()
mc = asm.assemble(asm_code, True)
name = "ImageFloatRGBA" + str(hash(self))
self.ds = runtime.load(name, mc)
self.ds["ptr_buffer"] = self.pixels.ptr()
self.ds["pitch"] = self.pitch
示例12: test_pow
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_pow(self):
asm = Tdasm()
mc = asm.assemble(POW_CODE)
runtime = Runtime()
load_math_func("fast_pow_ss", runtime)
ds = runtime.load("pow", mc)
for x in range(1000):
num = random.random() * 3
num1 = random.random() * 3
ds["x"] = num
ds["y"] = num1
runtime.run("pow")
rez_asm = ds["x"]
rez_py = math.pow(num, num1)
self.assertAlmostEqual(rez_asm, rez_py, 1)
示例13: __init__
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
class Structures:
def __init__(self, renderer):
self.tdasm = Tdasm()
self.renderer = renderer
self._line1 = "struct spectrum \n"
self._line3 = "end struct \n"
def get_struct(self, name):
if name in structures:
return structures[name]
elif name == "spectrum":
if self.renderer.spectral_rendering:
line2 = "float values[" + str(self.renderer.nspectrum_samples) + "] \n"
else:
line2 = "float values[4] \n"
return self._line1 + line2 + self._line3
elif name == "hitpoint":
if self.renderer.spectral_rendering:
line2 = "float values[" + str(self.renderer.nspectrum_samples) + "] \n"
else:
line2 = "float values[4] \n"
spec = self._line1 + line2 + self._line3
return spec + HITPOINT
return None
def get_compiled_struct(self, name):
if name in structures:
asm_code = """ #DATA
"""
asm_code += self.get_struct(name)
asm_code += """
#CODE
#END
"""
mc = self.tdasm.assemble(asm_code)
return mc.get_struct(name)
return None
def structs(self, names):
code = ""
for name in names:
struct = self.get_struct(name)
if struct is None:
raise ValueError("Structure " + str(name) + " doesn't exist!")
code += struct
return code
示例14: test_sincos
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_sincos(self):
asm = Tdasm()
mc = asm.assemble(SINCOS_CODE)
runtime = Runtime()
load_math_func("fast_sincos_ss", runtime)
ds = runtime.load("sincos", mc)
for x in range(1000):
num = random.random() * 2000
ds["x"] = num
runtime.run("sincos")
rez_asm1 = ds["x"]
rez_asm2 = ds["y"]
rez_py1, rez_py2 = math.sin(num), math.cos(num)
self.assertAlmostEqual(rez_asm1, rez_py1, 3)
self.assertAlmostEqual(rez_asm2, rez_py2, 3)
示例15: test_log_ps
# 需要导入模块: from tdasm import Tdasm [as 别名]
# 或者: from tdasm.Tdasm import assemble [as 别名]
def test_log_ps(self):
asm = Tdasm()
mc = asm.assemble(LOG_CODE_PS)
runtime = Runtime()
load_math_func("fast_log_ps", runtime)
ds = runtime.load("log_ps", mc)
for x in range(1000):
num1 = random.random()
num2 = random.random()
num3 = random.random()
num4 = random.random()
ds["v1"] = (num1, num2, num3, num4)
runtime.run("log_ps")
rez_asm = ds["v1"]
rez_py1 = math.log(num1)
rez_py2 = math.log(num2)
rez_py3 = math.log(num3)
rez_py4 = math.log(num4)
self.assertAlmostEqual(rez_asm[0], rez_py1, 3)
self.assertAlmostEqual(rez_asm[1], rez_py2, 3)
self.assertAlmostEqual(rez_asm[2], rez_py3, 3)
self.assertAlmostEqual(rez_asm[3], rez_py4, 3)