Example program#

Example program:

from copapy import value
from copapy.backend import Store, compile_to_dag, stencil_db_from_package
from copapy._binwrite import Command

input = value(9.0)

result = input ** 2 / 3.3 + 5

arch = 'native'
sdb = stencil_db_from_package(arch)
dw, _ = compile_to_dag([Store(result)], sdb)

# Instruct runner to dump patched code to a file:
dw.write_com(Command.DUMP_CODE)

dw.to_file('build/runner/test.copapy')

arm64#

build/runner/test.copapy.bin:     file format binary


Disassembly of section .data:

0000000000010000 <.data>:
   10000:	a9b77bfd 	stp	x29, x30, [sp, #-144]!
   10004:	52800000 	mov	w0, #0x0                   	// #0
   10008:	910003fd 	mov	x29, sp
   1000c:	390043ff 	strb	wzr, [sp, #16]
   10010:	b0000002 	adrp	x2, 0x11000
   10014:	2a0103e0 	mov	w0, w1
   10018:	bd400c40 	ldr	s0, [x2, #12]
   1001c:	b0000000 	adrp	x0, 0x11000
   10020:	bd400c01 	ldr	s1, [x0, #12]
   10024:	1e210800 	fmul	s0, s0, s1
   10028:	b0000000 	adrp	x0, 0x11000
   1002c:	bd400001 	ldr	s1, [x0]
   10030:	1e211800 	fdiv	s0, s0, s1
   10034:	b0000000 	adrp	x0, 0x11000
   10038:	b9400800 	ldr	w0, [x0, #8]
   1003c:	1e220001 	scvtf	s1, w0
   10040:	1e202820 	fadd	s0, s1, s0
   10044:	b0000001 	adrp	x1, 0x11000
   10048:	bd000420 	str	s0, [x1, #4]
   1004c:	52800020 	mov	w0, #0x1                   	// #1
   10050:	a8c97bfd 	ldp	x29, x30, [sp], #144
   10054:	d65f03c0 	ret

armv6#

build/runner/test.copapy.bin:     file format binary


Disassembly of section .data:

00010000 <.data>:
   10000:	e52de004 	push	{lr}		@ (str lr, [sp, #-4]!)
   10004:	e3a00000 	mov	r0, #0
   10008:	e24dd084 	sub	sp, sp, #132	@ 0x84
   1000c:	e5cd0000 	strb	r0, [sp]
   10010:	e3043000 	movw	r3, #16384	@ 0x4000
   10014:	e3443100 	movt	r3, #16640	@ 0x4100
   10018:	e1a00001 	mov	r0, r1
   1001c:	ed930a00 	vldr	s0, [r3]
   10020:	e3043000 	movw	r3, #16384	@ 0x4000
   10024:	e3443100 	movt	r3, #16640	@ 0x4100
   10028:	edd30a00 	vldr	s1, [r3]
   1002c:	ee200a20 	vmul.f32	s0, s0, s1
   10030:	e304300c 	movw	r3, #16396	@ 0x400c
   10034:	e3443100 	movt	r3, #16640	@ 0x4100
   10038:	edd30a00 	vldr	s1, [r3]
   1003c:	ee800a20 	vdiv.f32	s0, s0, s1
   10040:	e3043004 	movw	r3, #16388	@ 0x4004
   10044:	e3443100 	movt	r3, #16640	@ 0x4100
   10048:	e5930000 	ldr	r0, [r3]
   1004c:	ee070a90 	vmov	s15, r0
   10050:	eef87ae7 	vcvt.f32.s32	s15, s15
   10054:	ee370a80 	vadd.f32	s0, s15, s0
   10058:	e3043008 	movw	r3, #16392	@ 0x4008
   1005c:	e3443100 	movt	r3, #16640	@ 0x4100
   10060:	ed830a00 	vstr	s0, [r3]
   10064:	e3a00001 	mov	r0, #1
   10068:	e28dd084 	add	sp, sp, #132	@ 0x84
   1006c:	e49df004 	pop	{pc}		@ (ldr pc, [sp], #4)

armv7#

build/runner/test.copapy.bin:     file format binary


Disassembly of section .data:

00010000 <.data>:
   10000:	e52de004 	push	{lr}		@ (str lr, [sp, #-4]!)
   10004:	e3a00000 	mov	r0, #0
   10008:	e24dd084 	sub	sp, sp, #132	@ 0x84
   1000c:	e5cd0000 	strb	r0, [sp]
   10010:	e3043008 	movw	r3, #16392	@ 0x4008
   10014:	e3443100 	movt	r3, #16640	@ 0x4100
   10018:	e1a00001 	mov	r0, r1
   1001c:	ed930a00 	vldr	s0, [r3]
   10020:	e3043008 	movw	r3, #16392	@ 0x4008
   10024:	e3443100 	movt	r3, #16640	@ 0x4100
   10028:	edd30a00 	vldr	s1, [r3]
   1002c:	ee200a20 	vmul.f32	s0, s0, s1
   10030:	e3043004 	movw	r3, #16388	@ 0x4004
   10034:	e3443100 	movt	r3, #16640	@ 0x4100
   10038:	edd30a00 	vldr	s1, [r3]
   1003c:	ee800a20 	vdiv.f32	s0, s0, s1
   10040:	e3043000 	movw	r3, #16384	@ 0x4000
   10044:	e3443100 	movt	r3, #16640	@ 0x4100
   10048:	e5930000 	ldr	r0, [r3]
   1004c:	ee070a90 	vmov	s15, r0
   10050:	eef87ae7 	vcvt.f32.s32	s15, s15
   10054:	ee370a80 	vadd.f32	s0, s15, s0
   10058:	e304300c 	movw	r3, #16396	@ 0x400c
   1005c:	e3443100 	movt	r3, #16640	@ 0x4100
   10060:	ed830a00 	vstr	s0, [r3]
   10064:	e3a00001 	mov	r0, #1
   10068:	e28dd084 	add	sp, sp, #132	@ 0x84
   1006c:	e49df004 	pop	{pc}		@ (ldr pc, [sp], #4)

x86_64#

build/runner/test.copapy.bin:     file format binary


Disassembly of section .data:

0000000000010000 <.data>:
   10000:	48 81 ec 88 00 00 00 	sub    $0x88,%rsp
   10007:	31 ff                	xor    %edi,%edi
   10009:	c6 04 24 00          	movb   $0x0,(%rsp)
   1000d:	f3 0f 10 05 eb 0f 00 	movss  0xfeb(%rip),%xmm0        # 0x11000
   10014:	00 
   10015:	89 f7                	mov    %esi,%edi
   10017:	f3 0f 10 0d e1 0f 00 	movss  0xfe1(%rip),%xmm1        # 0x11000
   1001e:	00 
   1001f:	f3 0f 59 c1          	mulss  %xmm1,%xmm0
   10023:	f3 0f 10 0d e1 0f 00 	movss  0xfe1(%rip),%xmm1        # 0x1100c
   1002a:	00 
   1002b:	f3 0f 5e c1          	divss  %xmm1,%xmm0
   1002f:	8b 3d cf 0f 00 00    	mov    0xfcf(%rip),%edi        # 0x11004
   10035:	0f 28 c8             	movaps %xmm0,%xmm1
   10038:	66 0f ef c0          	pxor   %xmm0,%xmm0
   1003c:	f3 0f 2a c7          	cvtsi2ss %edi,%xmm0
   10040:	f3 0f 58 c1          	addss  %xmm1,%xmm0
   10044:	f3 0f 11 05 bc 0f 00 	movss  %xmm0,0xfbc(%rip)        # 0x11008
   1004b:	00 
   1004c:	b8 01 00 00 00       	mov    $0x1,%eax
   10051:	48 81 c4 88 00 00 00 	add    $0x88,%rsp
   10058:	c3                   	ret