Project: Added -O2 to the CFLAGS and fixed some compiler warnings
This commit is contained in:
parent
783a8bac23
commit
893e44f20a
2
Makefile
2
Makefile
@ -24,6 +24,8 @@ else
|
|||||||
Q =
|
Q =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-O2
|
||||||
|
|
||||||
ifeq "${PROFILING}" "1"
|
ifeq "${PROFILING}" "1"
|
||||||
CFLAGS += -pg
|
CFLAGS += -pg
|
||||||
LDFLAGS += -pg
|
LDFLAGS += -pg
|
||||||
|
42
cpu.c
42
cpu.c
@ -49,11 +49,11 @@ int decode(struct simdata_t *simdata){
|
|||||||
case 0x14:
|
case 0x14:
|
||||||
case 0x15:
|
case 0x15:
|
||||||
switch(opcode){
|
switch(opcode){
|
||||||
case 0x01: case 0x11: simdata->exec_data->COND=NONE; break;
|
case 0x01: case 0x11: simdata->exec_data->COND=COND_NONE; break;
|
||||||
case 0x02: case 0x12: simdata->exec_data->COND=ZERO; break;
|
case 0x02: case 0x12: simdata->exec_data->COND=COND_ZERO; break;
|
||||||
case 0x03: case 0x13: simdata->exec_data->COND=NZERO; break;
|
case 0x03: case 0x13: simdata->exec_data->COND=COND_NZERO; break;
|
||||||
case 0x04: case 0x14: simdata->exec_data->COND=CARRY; break;
|
case 0x04: case 0x14: simdata->exec_data->COND=COND_CARRY; break;
|
||||||
case 0x05: case 0x15: simdata->exec_data->COND=NCARRY; break;
|
case 0x05: case 0x15: simdata->exec_data->COND=COND_NCARRY; break;
|
||||||
default: return 1;
|
default: return 1;
|
||||||
}
|
}
|
||||||
simdata->exec_data->out_op->OP_ADDR=IMMEDIATE;
|
simdata->exec_data->out_op->OP_ADDR=IMMEDIATE;
|
||||||
@ -262,11 +262,11 @@ int exec(struct simdata_t *simdata){
|
|||||||
case CALL:
|
case CALL:
|
||||||
case JUMP:
|
case JUMP:
|
||||||
switch(simdata->exec_data->COND){
|
switch(simdata->exec_data->COND){
|
||||||
case NONE: condition=1; break;
|
case COND_NONE: condition=1; break;
|
||||||
case ZERO: condition=simdata->registers->FLAGS&1; break;
|
case COND_ZERO: condition=simdata->registers->FLAGS&1; break;
|
||||||
case NZERO: condition=!(simdata->registers->FLAGS&1); break;
|
case COND_NZERO: condition=!(simdata->registers->FLAGS&1); break;
|
||||||
case CARRY: condition=simdata->registers->FLAGS&2; break;
|
case COND_CARRY: condition=simdata->registers->FLAGS&2; break;
|
||||||
case NCARRY: condition=!(simdata->registers->FLAGS&2); break;
|
case COND_NCARRY: condition=!(simdata->registers->FLAGS&2); break;
|
||||||
}
|
}
|
||||||
if(condition){
|
if(condition){
|
||||||
if(simdata->exec_data->EXEC_ACTION==CALL){
|
if(simdata->exec_data->EXEC_ACTION==CALL){
|
||||||
@ -314,26 +314,26 @@ int exec(struct simdata_t *simdata){
|
|||||||
result = simdata->registers->GPR[simdata->exec_data->in_op1->data]>>1;
|
result = simdata->registers->GPR[simdata->exec_data->in_op1->data]>>1;
|
||||||
break;
|
break;
|
||||||
case ALU_FDIV:
|
case ALU_FDIV:
|
||||||
*(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data])/
|
result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data])/
|
||||||
*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]);
|
uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data]));
|
||||||
break;
|
break;
|
||||||
case ALU_FMUL:
|
case ALU_FMUL:
|
||||||
*(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data])*
|
result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data])*
|
||||||
*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data]);
|
uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data]));
|
||||||
break;
|
break;
|
||||||
case ALU_FADD:
|
case ALU_FADD:
|
||||||
*(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data])+
|
result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data])+
|
||||||
*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]);
|
uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data]));
|
||||||
break;
|
break;
|
||||||
case ALU_FSUB:
|
case ALU_FSUB:
|
||||||
*(float*)&result = *(float*)(&simdata->registers->GPR[simdata->exec_data->in_op2->data])-
|
result = ieee754_float_to_uint32(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op2->data])-
|
||||||
*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]);
|
uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data]));
|
||||||
break;
|
break;
|
||||||
case ALU_FSIN:
|
case ALU_FSIN:
|
||||||
*(float*)&result = sinf(*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]));
|
result = ieee754_float_to_uint32(sinf(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data])));
|
||||||
break;
|
break;
|
||||||
case ALU_FCOS:
|
case ALU_FCOS:
|
||||||
*(float*)&result = cosf(*(float*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data]));
|
result = ieee754_float_to_uint32(cosf(uint32_to_ieee754_float(simdata->registers->GPR[simdata->exec_data->in_op1->data])));
|
||||||
break;
|
break;
|
||||||
case ALU_DEC:
|
case ALU_DEC:
|
||||||
*(uint32_t*)&result = *(uint32_t*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data])-1;
|
*(uint32_t*)&result = *(uint32_t*)(&simdata->registers->GPR[simdata->exec_data->in_op1->data])-1;
|
||||||
@ -485,7 +485,7 @@ int cpu_simdata_malloc(struct simdata_t *simdata){
|
|||||||
simdata->exec_data=malloc_exec_data();
|
simdata->exec_data=malloc_exec_data();
|
||||||
simdata->registers=malloc(sizeof(struct registers_t));
|
simdata->registers=malloc(sizeof(struct registers_t));
|
||||||
simdata->registers->PC=0x00000000;
|
simdata->registers->PC=0x00000000;
|
||||||
simdata->registers->SP&=0x00FFFFFF; //intentionally leave it uninitialised but within the legal range
|
simdata->registers->SP=0;
|
||||||
if((simdata->fetch_data!=NULL)&&(simdata->decode_data!=NULL)&&(simdata->exec_data!=NULL))
|
if((simdata->fetch_data!=NULL)&&(simdata->decode_data!=NULL)&&(simdata->exec_data!=NULL))
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
|
10
cpu.h
10
cpu.h
@ -55,11 +55,11 @@ struct exec_op_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum COND_t{
|
enum COND_t{
|
||||||
NONE,
|
COND_NONE,
|
||||||
ZERO,
|
COND_ZERO,
|
||||||
NZERO,
|
COND_NZERO,
|
||||||
CARRY,
|
COND_CARRY,
|
||||||
NCARRY
|
COND_NCARRY
|
||||||
};
|
};
|
||||||
|
|
||||||
struct exec_data_t {
|
struct exec_data_t {
|
||||||
|
11
gui.c
11
gui.c
@ -417,7 +417,7 @@ int update_general_memdump(struct simdata_t *simdata){
|
|||||||
uint32_t ADDRESS=(simdata->registers->PC-n*usable_height/2)&0x00FFFFFF;
|
uint32_t ADDRESS=(simdata->registers->PC-n*usable_height/2)&0x00FFFFFF;
|
||||||
|
|
||||||
uint32_t color_addr;
|
uint32_t color_addr;
|
||||||
int have_color;
|
int have_color=0;
|
||||||
for(int h=0;h<usable_height;h++){
|
for(int h=0;h<usable_height;h++){
|
||||||
wmove(general_memdump,h+2,2+(width-12)%2);
|
wmove(general_memdump,h+2,2+(width-12)%2);
|
||||||
wattroff(general_memdump,A_BOLD);
|
wattroff(general_memdump,A_BOLD);
|
||||||
@ -597,6 +597,7 @@ void braille_frame_buffer_line(uint8_t *buffer,int buffer_width,int buffer_heigh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int update_general_terminal_output(struct simdata_t *simdata){
|
int update_general_terminal_output(struct simdata_t *simdata){
|
||||||
int width,height;
|
int width,height;
|
||||||
werase(general_terminal_output);
|
werase(general_terminal_output);
|
||||||
@ -630,19 +631,19 @@ int update_general_terminal_output(struct simdata_t *simdata){
|
|||||||
vstate++;
|
vstate++;
|
||||||
break;
|
break;
|
||||||
case 1: /*x of start*/
|
case 1: /*x of start*/
|
||||||
x0=*(float*)&c;
|
x0=uint32_to_ieee754_float(c);
|
||||||
vstate++;
|
vstate++;
|
||||||
break;
|
break;
|
||||||
case 2: /*y of start*/
|
case 2: /*y of start*/
|
||||||
y0=*(float*)&c;
|
y0=uint32_to_ieee754_float(c);
|
||||||
vstate++;
|
vstate++;
|
||||||
break;
|
break;
|
||||||
case 3: /*x of end*/
|
case 3: /*x of end*/
|
||||||
x1=*(float*)&c;
|
x1=uint32_to_ieee754_float(c);
|
||||||
vstate++;
|
vstate++;
|
||||||
break;
|
break;
|
||||||
case 4: /*y of end*/
|
case 4: /*y of end*/
|
||||||
y1=*(float*)&c;
|
y1=uint32_to_ieee754_float(c);
|
||||||
float min_dim=(vfb_width>vfb_height)?vfb_height:vfb_width;
|
float min_dim=(vfb_width>vfb_height)?vfb_height:vfb_width;
|
||||||
int xoff=0,yoff=0;
|
int xoff=0,yoff=0;
|
||||||
x0*=1.25;
|
x0*=1.25;
|
||||||
|
19
simdata.c
19
simdata.c
@ -85,3 +85,22 @@ void free_simdata(struct simdata_t *p){
|
|||||||
free(p->terminal_output);
|
free(p->terminal_output);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined ( __STDC_IEC_559__ )
|
||||||
|
union U32FLOAT_RETURN{
|
||||||
|
float f;
|
||||||
|
uint32_t u;
|
||||||
|
};
|
||||||
|
float uint32_to_ieee754_float(uint32_t in){
|
||||||
|
union U32FLOAT_RETURN ret;
|
||||||
|
ret.u=in;
|
||||||
|
return ret.f;
|
||||||
|
}
|
||||||
|
uint32_t ieee754_float_to_uint32(float in){
|
||||||
|
union U32FLOAT_RETURN ret;
|
||||||
|
ret.f=in;
|
||||||
|
return ret.u;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error Your libc/compiler/architecture doesnt support IEEE 457/IEC 559 Please write a software alternative here
|
||||||
|
#endif
|
||||||
|
@ -40,6 +40,8 @@ void free_simdata(struct simdata_t *);
|
|||||||
int add_to_instr_list(struct instr_list_t **addr_of_toadd,uint32_t address);
|
int add_to_instr_list(struct instr_list_t **addr_of_toadd,uint32_t address);
|
||||||
void free_instr_list(struct instr_list_t **addr_of_tofree);
|
void free_instr_list(struct instr_list_t **addr_of_tofree);
|
||||||
int terminal_output(uint32_t c,struct simdata_t *simdata);
|
int terminal_output(uint32_t c,struct simdata_t *simdata);
|
||||||
|
float uint32_to_ieee754_float(uint32_t in);
|
||||||
|
uint32_t ieee754_float_to_uint32(float in);
|
||||||
|
|
||||||
enum GUI_CPU_STATE_t{
|
enum GUI_CPU_STATE_t{
|
||||||
GUI_CPU_RUNNING,
|
GUI_CPU_RUNNING,
|
||||||
|
Loading…
Reference in New Issue
Block a user