From 87925db8fba1feda192e0ce576f32bd276eca14a Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 20 Aug 2011 07:48:23 +0000 Subject: [PATCH] * fixed 64 bit shl/shr/sar operations: the second argument of the operation is 32 bit, not 64 bit (both in the compiler and in the JVM) * request a 64 rather than a 32 bit shift operation from tjvmshlshrnode if the result is 64 bit (rather than in case shift value is 64 bit, since as described above that never happens) git-svn-id: branches/jvmbackend@18337 - --- compiler/jvm/hlcgcpu.pas | 39 ++++++++++++++++++++++++++++++++++----- compiler/jvm/njvmmat.pas | 2 +- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/compiler/jvm/hlcgcpu.pas b/compiler/jvm/hlcgcpu.pas index 736c9b6c6a..98304d2d35 100644 --- a/compiler/jvm/hlcgcpu.pas +++ b/compiler/jvm/hlcgcpu.pas @@ -356,8 +356,15 @@ implementation if TOpCG2LAsmOp[op]=A_None then internalerror(2010120533); list.concat(taicpu.op_none(TOpCG2LAsmOp[op])); - if op<>OP_NEG then - decstack(list,2); + case op of + OP_NOT: + ; + { the second argument here is an int rather than a long } + OP_SHL,OP_SHR,OP_SAR: + decstack(list,1); + else + decstack(list,2); + end; end; else internalerror(2010120531); @@ -381,7 +388,15 @@ implementation else begin maybepreparedivu32(list,op,size,trunc32); - a_load_const_stack(list,size,a,R_INTREGISTER); + case op of + OP_NEG,OP_NOT: + internalerror(2011010801); + OP_SHL,OP_SHR,OP_SAR: + { the second argument here is an int rather than a long } + a_load_const_stack(list,s32inttype,a,R_INTREGISTER); + else + a_load_const_stack(list,size,a,R_INTREGISTER); + end; a_op_stack(list,op,size,trunc32); end; end; @@ -391,8 +406,22 @@ implementation trunc32: boolean; begin maybepreparedivu32(list,op,size,trunc32); - if not(op in [OP_NEG,OP_NOT]) then - a_load_reg_stack(list,size,reg); + case op of + OP_NEG,OP_NOT: + ; + OP_SHL,OP_SHR,OP_SAR: + if not is_64bitint(size) then + a_load_reg_stack(list,size,reg) + else + begin + { the second argument here is an int rather than a long } + if getsubreg(reg)=R_SUBQ then + internalerror(2011010802); + a_load_reg_stack(list,s32inttype,reg) + end + else + a_load_reg_stack(list,size,reg); + end; a_op_stack(list,op,size,trunc32); end; diff --git a/compiler/jvm/njvmmat.pas b/compiler/jvm/njvmmat.pas index 86eb4c3e10..c173c5e7ee 100644 --- a/compiler/jvm/njvmmat.pas +++ b/compiler/jvm/njvmmat.pas @@ -144,7 +144,7 @@ implementation op:=OP_SHL else op:=OP_SHR; - thlcgjvm(hlcg).a_op_loc_stack(current_asmdata.CurrAsmList,op,right.resultdef,right.location); + thlcgjvm(hlcg).a_op_loc_stack(current_asmdata.CurrAsmList,op,resultdef,right.location); thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register); end;