mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 23:44:08 +00:00
Create test_z_inst.c
Added examples folder Added test code to test basic instructions like add , sub and msr This code is in processes of further expansion and tuning
This commit is contained in:
parent
45553891da
commit
1d960f2286
80
dynasm/Examples/test_z_inst.c
Normal file
80
dynasm/Examples/test_z_inst.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include "../dynasm/dasm_proto.h"
|
||||||
|
#include "../dynasm/dasm_s390x.h"
|
||||||
|
|
||||||
|
//DynASM directives.
|
||||||
|
|.arch s390x
|
||||||
|
|.actionlist actions
|
||||||
|
|
||||||
|
/* Instructio modes
|
||||||
|
mode 0 : RR Mode
|
||||||
|
mode 1 : I Mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *jitcode(dasm_State **state);
|
||||||
|
void add(dasm_State * , int);
|
||||||
|
void sub(dasm_State * , int);
|
||||||
|
void mul(dasm_State * , int);
|
||||||
|
|
||||||
|
void *jitcode(dasm_State **state)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
int dasm_status = dasm_link(state, &size);
|
||||||
|
assert(dasm_status == DASM_S_OK);
|
||||||
|
|
||||||
|
void *ret = (int *)calloc(10,sizeof(int));
|
||||||
|
dasm_encode(state, ret);
|
||||||
|
dasm_free(state);
|
||||||
|
|
||||||
|
return (int *)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(dasm_State *state)
|
||||||
|
{
|
||||||
|
dasm_State ** Dst = &state;
|
||||||
|
|
||||||
|
| ar r2,r3
|
||||||
|
| br r14
|
||||||
|
}
|
||||||
|
|
||||||
|
void sub(dasm_State *state)
|
||||||
|
{
|
||||||
|
dasm_State **Dst = &state;
|
||||||
|
|
||||||
|
| sr r2,r3
|
||||||
|
| br r14
|
||||||
|
}
|
||||||
|
|
||||||
|
void mul(dasm_State *state)
|
||||||
|
{
|
||||||
|
dasm_State **Dst = &state;
|
||||||
|
|
||||||
|
| msr r2 , r3
|
||||||
|
| br r14
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
dasm_State *state;
|
||||||
|
dasm_State **Dst = &state;
|
||||||
|
int num1 , num2;
|
||||||
|
int *ret;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
int* (*fptr)(int , int) = jitcode(&state);
|
||||||
|
|
||||||
|
num1 = atoi(argv[1]);
|
||||||
|
num2 = atoi(argv[2]);
|
||||||
|
|
||||||
|
dasm_init(&state, 1);
|
||||||
|
dasm_setup(&state, actions);
|
||||||
|
|
||||||
|
/* Call respective test function */
|
||||||
|
sub(state);
|
||||||
|
|
||||||
|
ret = fptr(num1 , num2);
|
||||||
|
printf("The value is %d\n" ,ret);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user