本文整理汇总了Python中tdasm.Tdasm类的典型用法代码示例。如果您正苦于以下问题:Python Tdasm类的具体用法?Python Tdasm怎么用?Python Tdasm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tdasm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _create_struct
def _create_struct(self, shape):
code = " #DATA " + shape.asm_struct() + """
#CODE
#END
"""
mc = Tdasm().assemble(code)
return mc.get_struct(shape.asm_struct_name())
开发者ID:mario007,项目名称:renmas,代码行数:7,代码来源:mgr.py
示例2: test_pow_ps
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)
开发者ID:mario007,项目名称:renmas,代码行数:29,代码来源:test_trigs.py
示例3: _create_struct
def _create_struct(self, struct_def, name):
code = " #DATA \n" + struct_def + """
#CODE
#END
"""
mc = Tdasm().assemble(code)
return mc.get_struct(name)
开发者ID:mario007,项目名称:renmas,代码行数:7,代码来源:arr.py
示例4: prepare
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
开发者ID:mario007,项目名称:renmas,代码行数:28,代码来源:shader.py
示例5: test_sincos_ps
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)
开发者ID:mario007,项目名称:renmas,代码行数:33,代码来源:test_trigs.py
示例6: __init__
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)
开发者ID:mario007,项目名称:renmas,代码行数:9,代码来源:blitter.py
示例7: create_float_image
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
开发者ID:mario007,项目名称:renmas,代码行数:10,代码来源:test_image_asm.py
示例8: compile
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)
开发者ID:mario007,项目名称:renmas,代码行数:10,代码来源:shader.py
示例9: _create_struct
def _create_struct(self, struct_def, name):
code = " #DATA \n" + struct_def + """
#CODE
#END
"""
ia32 = True
bits = platform.architecture()[0]
if bits == '64bit':
ia32 = False
mc = Tdasm().assemble(code, ia32=ia32)
return mc.get_struct(name)
开发者ID:mario007,项目名称:renmas,代码行数:11,代码来源:arr.py
示例10: test_atan
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)
开发者ID:mario007,项目名称:renmas,代码行数:14,代码来源:test_trigs.py
示例11: test_log
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)
开发者ID:mario007,项目名称:renmas,代码行数:14,代码来源:test_trigs.py
示例12: test_exp
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)
开发者ID:mario007,项目名称:renmas,代码行数:14,代码来源:test_trigs.py
示例13: compile
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)
开发者ID:mario007,项目名称:renmas,代码行数:15,代码来源:shader.py
示例14: set_pixel_asm
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
开发者ID:mario007,项目名称:renmas,代码行数:48,代码来源:image.py
示例15: test_pow
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)
开发者ID:mario007,项目名称:renmas,代码行数:16,代码来源:test_trigs.py
示例16: test_sincos
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)
开发者ID:mario007,项目名称:renmas,代码行数:17,代码来源:test_trigs.py
示例17: test_log_ps
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)
开发者ID:mario007,项目名称:renmas,代码行数:24,代码来源:test_trigs.py
示例18: __init__
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
开发者ID:mario007,项目名称:renmas,代码行数:47,代码来源:structures.py
示例19: _blt_floatrgba_code
add dword [sy], 1
add dword [y], 1
jmp _bltrgba
_endblt:
ret
"""
return code
def _blt_floatrgba_code(bgra=True):
bits = platform.architecture()[0]
if bits == '64bit':
return _blt_floatrgba_code64(bgra)
else:
return _blt_floatrgba_code32(bgra)
_asm = Tdasm()
_mc = _asm.assemble(_blt_floatrgba_code())
_runtime = Runtime()
_data_section = _runtime.load("blt_prgba_to_bgra", _mc)
_mc2 = _asm.assemble(_blt_floatrgba_code(bgra=False))
_data_section2 = _runtime.load("blt_prgba_to_rgba", _mc2)
# blt float rgba to byte bgra
def blt_prgba_to_bgra(src, dest):
assert isinstance(src, ImagePRGBA)
assert isinstance(dest, ImageBGRA)
sa, spitch = src.address_info()
da, dpitch = dest.address_info()
开发者ID:mario007,项目名称:renmas,代码行数:31,代码来源:blt_floatrgba.py
示例20: sphere_ds
ds[name+ ".origin"] = (o.x, o.y, o.z, 0.0)
ds[name+ ".dir"] = (d.x, d.y, d.z, 0.0)
def sphere_ds(ds, sphere, name):
o = sphere.origin
ds[name+".origin"] = (o.x, o.y, o.z, 0.0)
ds[name+".radius"] = sphere.radius
ds[name+".mat_index"] = sphere.material
ray = get_ray()
sph = get_sphere()
runtime = Runtime()
sph.isect_asm([runtime], 'ray_sphere_intersection')
asm = Tdasm()
mc = asm.assemble(ASM_CODE)
ds = runtime.load('test', mc)
ray_ds(ds, ray, 'ray1')
sphere_ds(ds, sph, 'sph1')
runtime.run('test')
hp = sph.isect(ray)
if hp:
print(hp.t, ds['hp1.t'])
print(hp.hit_point)
print(ds['hp1.hit'])
print(hp.normal)
开发者ID:mario007,项目名称:renmas,代码行数:31,代码来源:sphere.py
注:本文中的tdasm.Tdasm类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论