Mercurial > hg > CbC > old > device
changeset 113:a9261154cde9
integer operation debug
author | kono |
---|---|
date | Wed, 19 Mar 2003 23:03:50 +0900 |
parents | fc7de4faedfd |
children | e6cb1e293b35 |
files | Changes mc-code-powerpc.c test/int.c |
diffstat | 3 files changed, 335 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Wed Mar 19 20:41:14 2003 +0900 +++ b/Changes Wed Mar 19 23:03:50 2003 +0900 @@ -2350,3 +2350,5 @@ なんか、save_stack が余計なsaveしてない? まぁ、一時変数を良く使うのでfree listを作った方が良いかもね。 + +その前に整数演算のチェックが必要だな。
--- a/mc-code-powerpc.c Wed Mar 19 20:41:14 2003 +0900 +++ b/mc-code-powerpc.c Wed Mar 19 23:03:50 2003 +0900 @@ -856,27 +856,27 @@ char * code_gt(int cond) { - return (!cond?"gt":"le"); + return (cond?"gt":"le"); } char * code_ugt(int cond) { - return (!cond?"gt":"le"); + return (cond?"gt":"le"); } char * code_ge(int cond) { - return (!cond?"ge":"lt"); + return (cond?"ge":"lt"); } char * code_uge(int cond) { - return (!cond?"ge":"lt"); + return (cond?"ge":"lt"); } char * code_eq(int cond) { - return (!cond?"eq":"ne"); + return (cond?"eq":"ne"); } void @@ -1389,7 +1389,7 @@ int edx = get_register(); if(!edx) error(-1); xrn = register_name(xreg = emit_pop(0)); /* pop e3 value */ regv[xreg]=regs[xreg]=1; - printf("# assop\n\tmr %s,%s\n",register_name(creg),register_name(edx)); + printf("# assop\n\tmr %s,%s\n",register_name(edx),register_name(creg)); regv[edx]=1; ld_indexx(byte,0,edx); tosop(op,xreg); @@ -1442,7 +1442,7 @@ printf("\tsub %s,%s,%s\n",crn,orn,crn); break; case CMP: - printf("\tcmpw cr0,%s,%s\n",orn,crn); + printf("\tcmpw cr0,%s,%s\n",crn,orn); break; case BAND: printf("\tand %s,%s,%s\n",crn,orn,crn); @@ -2108,6 +2108,7 @@ char *frn = fregister_name(freg); char *crn = register_name(creg); int d = new_lvar(size_of_double); + d = lvar(d); printf("\tfctiwz %s,%s\n",frn,frn); printf("\tstfd %s,lo16(%d+L_%d)(r1)\n",frn,d,func_disp_label); printf("\tlwz %s,lo16(%d+L_%d)(r1)\n",crn, @@ -2147,6 +2148,8 @@ void code_i2d(int creg,int freg) { i2d_lib_used = 1; + clear_ptr_cache(); + code_save_stacks(); set_creg(RET_REGISTER,1); printf("\tbl i2d_\n"); set_freg(RET_FREGISTER,0); @@ -2192,6 +2195,8 @@ void code_d2u(int freg,int creg) { + code_save_stacks(); + clear_ptr_cache(); d2u_lib_used=1; set_freg(RET_FREGISTER,1); printf("\tbl d2u_\n"); @@ -2230,6 +2235,8 @@ void code_u2d(int creg,int freg) { u2d_lib_used = 1; + code_save_stacks(); + clear_ptr_cache(); char *frn = fregister_name(freg); char *crn = register_name(creg); printf("\tmr r3,%s\n",crn);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/int.c Wed Mar 19 23:03:50 2003 +0900 @@ -0,0 +1,319 @@ +#include "stdio.h" + +void test1(); +void print(int d); + +int test2(int f,int i); + +unsigned f = 3; +int d = -3; +unsigned f1 = 3; +int d1 = -3; +int d2 = -2; +unsigned h = 65536*100; + +int +d2i(int d) { + return (int)d; +} + +int +i2d(int u) { + return (int)u; +} + +unsigned u; +unsigned +d2u(int d) { + return (unsigned)d; +} + +int +u2d(unsigned u) { + return (int)u; +} + +int +main(int ac,char *av[]) { + int g; + int i; + unsigned u; + unsigned d00 = ac?-30:ac; + + printf("%ud\n",d00); + + g = 1; + g = -g; + printf("%d\ncond ",g); + if(f==f*1) printf("1 "); + if(d==f*1) printf("2 "); + if(f==f1) printf("3 "); + if(d==d1) printf("4 "); + if(d==d2) printf("-4 "); + if(d>d1) printf("5 "); + if(d>d2) printf("-5 "); + if(d>=d1) printf("6 "); + if(d>=d2) printf("-6 "); + if(d!=d1) printf("7 "); + if(d!=d2) printf("-7 "); + if(d<d1) printf("8 "); + if(d<d2) printf("-8 "); + if(d<=d1) printf("9 "); + if(d<=d2) printf("-9 "); + d = 123; f=-234; + i = d; + d = i; + i = f; + f = i; + printf("\n%d %d %f",i,d,f); + f = g = d = d1 = d2 = f; + printf(" %d %d %f %d\n",i,d,f,g); + + d = 320967294; f=224967294; + u = d; + d = u; + u = f; + f = u; + printf("%u %d %d\n",u,d,f); + + print(1.0); + print(0.1234*100); + print(1.234e6); + print(-1.234e+3); + + test1(); + printf("nested call: %d\n",test2(test2(test2(test2(-333,3),5),6),7)); + return 0; +} + +void +print(int d) +{ + unsigned f; + int *dd; + + f = d; + + + dd = (int*) &f; + printf("f %d ",f); + printf("dx %08x \n",*(dd)); +} + +int +testd(int i,int j) +{ + return j+1.1+.0e3+12.3e-12; +} + +unsigned +testf(unsigned i,unsigned j) +{ + return j+1; +} + +void +ahoaho() { +} + +void +test1() +{ + unsigned f; + unsigned f1; + int g; + int g1; + unsigned *pf; + unsigned *pf1; + int *pg; + int *pg1; + int n = 1; + + printf("simple int "); + f = 1.3; + + g = 1.0; + g = g+g; + printf("%d:%d\t",n++,g); + g1 = g*g; + printf("%d:%d\t",n++,g1); + g = g/g1; + printf("%d:%d\t",n++,g); + g = g-g1; + printf("%d:%d\t",n++,g); + g = sin(g1); + printf("%d:%d\t",n++,g); + g = testd(g,g1); + printf("%d:%d\t",n++,g); + printf("\n"); + + printf("simple unsigned "); + f = f+f; + printf("%d:%d\t",n++,f); + f1 = f*f; + printf("%d:%d\t",n++,f1); + f = f/f1; + printf("%d:%d\t",n++,f); + f = f-f1; + printf("%d:%d\t",n++,f); + f = sin(f1); + printf("%d:%d\t",n++,f); + printf("\n"); + + printf("post/pre increment "); + g1 = g; + printf("%d:%d\t",n++,g1++ - ++g); + + f1 = f; + printf("%d:%d\t",n++,f1++ - ++f); + + g1 = g; + printf("%d:%d\t",n++,g1-- - --g); + + f1 = f; + printf("%d:%d\t",n++,f1-- - --f); + + printf("\n"); + printf("simple calc "); + + f=0.13; g=-0.56; f1=-0.13; g1=0.56; + + g = f+f; + printf("%d:%d\t",n++,g); + f = g*g; + printf("%d:%d\t",n++,f); + g = g*g+f*f-g1*g1; + printf("%d:%d\t",n++,g); + printf("\n"); + + printf("unsigned argument "); + f = testf(f,f1); + printf("%d:%d\t",n++,f); + + printf("\nindirect "); + n=1; + f = 1.3; pf=&f; pf1=&f1; + + ahoaho(); + g = 1.0; pg=&g; pg1=&g1; + *pg = *pg+ *pg; + printf("%d:%d\t",n++,*pg); + *pg1 = *pg**pg; + printf("%d:%d\t",n++,*pg1); + *pg = *pg/ *pg1; + printf("%d:%d\t",n++,*pg); + *pg = *pg-*pg1; + printf("%d:%d\t",n++,*pg); + *pg = sin(*pg1); + printf("%d:%d\t",n++,*pg); + *pg = testd(*pg,*pg1); + printf("%d:%d\t",n++,*pg); + printf("\n"); + + *pf = *pf+*pf; + printf("%d:%d\t",n++,*pf); + *pf1 = *pf**pf; + printf("%d:%d\t",n++,*pf1); + *pf = *pf/ *pf1; + printf("%d:%d\t",n++,*pf); + *pf = *pf-*pf1; + printf("%d:%d\t",n++,*pf); + *pf = sin(*pf1); + printf("%d:%d\t",n++,*pf); + printf("\n"); + + printf("indirect post/pre "); + *pg1 = *pg; + printf("%d:%d\t",n++,(*pg1)++ - ++(*pg)); + + *pf1 = *pf; + printf("%d:%d\t",n++,(*pf1)++ - ++(*pf)); + + *pg1 = *pg; + printf("%d:%d\t",n++, (*pg1)-- - --(*pg)); + + *pf1 = *pf; + printf("%d:%d\t",n++, (*pf1)-- - --(*pf)); + printf("\n"); + + *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56; + + *pg = *pf+*pf; + printf("%d:%d\t",n++,*pg); + *pf = *pg**pg; + printf("%d:%d\t",n++,*pf); + *pg = *pg**pg+*pf**pf-*pg1**pg1; + printf("%d:%d\t",n++,*pg); + printf("\n"); + + printf("unsigned argument "); + + *pf = testf(*pf,*pf1); + printf("%d:%d\t",n++,*pf); + + + printf("\nassop "); + n=1; + f = 1.3; + g = 1.0; + + g *= 2*g; + printf("%d:%d\t",n++,g); + g /= 2*g; + printf("%d:%d\t",n++,g); + g -= 2*g; + printf("%d:%d\t",n++,g); + g += 2*g; + printf("%d:%d\t",n++,g); + + f *= 2*g; + printf("%d:%d\t",n++,f); + f /= 2*g; + printf("%d:%d\t",n++,f); + f -= 2*g; + printf("%d:%d\t",n++,f); + f += 2*g; + printf("%d:%d\t",n++,f); + printf("\n"); + + n=1; + f = 1.3; + g = 1.0; + + printf("indirect assop "); + *pg *= 2**pg; + printf("%d:%d\t",n++,*pg); + *pg /= 2**pg; + printf("%d:%d\t",n++,*pg); + *pg -= 2**pg; + printf("%d:%d\t",n++,*pg); + *pg += 2**pg; + printf("%d:%d\t",n++,*pg); + + *pf *= 2**pg; + printf("%d:%d\t",n++,*pf); + *pf /= 2**pg; + printf("%d:%d\t",n++,*pf); + *pf -= 2**pg; + printf("%d:%d\t",n++,*pf); + *pf += 2**pg; + printf("%d:%d\t",n++,*pf); + printf("\n"); + + + return; +} + +int +test2(int f,int i) +{ + int g,h; + + if (i<=0) return f; +#if 0 + printf("rec: %d %d\n",i,f); +#endif + g = f*2; + h = f-0.5; + return h/3-(3.0-(g+3)*test2(f*0.5,i-1)/(h-1)); +}