|
@@ -178,13 +178,7 @@ uses
|
|
|
|
|
|
procedure g_reference_loc(list: TAsmList; def: tdef; const fromloc: tlocation; out toloc: tlocation); override;
|
|
procedure g_reference_loc(list: TAsmList; def: tdef; const fromloc: tlocation; out toloc: tlocation); override;
|
|
|
|
|
|
- { this routine expects that all values are already massaged into the
|
|
|
|
- required form (sign bits xor'ed for gt/lt comparisons for OS_32/OS_64,
|
|
|
|
- see http://stackoverflow.com/questions/4068973/c-performing-signed-comparison-in-unsigned-variables-without-casting ) }
|
|
|
|
procedure a_cmp_stack_stack(list : TAsmlist; size: tdef; cmp_op: topcmp);
|
|
procedure a_cmp_stack_stack(list : TAsmlist; size: tdef; cmp_op: topcmp);
|
|
- { these 2 routines perform the massaging expected by the previous one }
|
|
|
|
- procedure maybe_adjust_cmp_stackval(list : TAsmlist; size: tdef; cmp_op: topcmp);
|
|
|
|
- function maybe_adjust_cmp_constval(size: tdef; cmp_op: topcmp; a: tcgint): tcgint;
|
|
|
|
{ truncate/sign extend after performing operations on values < 32 bit
|
|
{ truncate/sign extend after performing operations on values < 32 bit
|
|
that may have overflowed outside the range }
|
|
that may have overflowed outside the range }
|
|
procedure maybe_adjust_op_result(list: TAsmList; op: TOpCg; size: tdef);
|
|
procedure maybe_adjust_op_result(list: TAsmList; op: TOpCg; size: tdef);
|
|
@@ -631,16 +625,14 @@ implementation
|
|
tmpref:=ref;
|
|
tmpref:=ref;
|
|
if tmpref.base<>NR_EVAL_STACK_BASE then
|
|
if tmpref.base<>NR_EVAL_STACK_BASE then
|
|
a_load_ref_stack(list,size,tmpref,prepare_stack_for_ref(list,tmpref,false));
|
|
a_load_ref_stack(list,size,tmpref,prepare_stack_for_ref(list,tmpref,false));
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
- a_load_const_stack(list,size,maybe_adjust_cmp_constval(size,cmp_op,a),def2regtyp(size));
|
|
|
|
|
|
+ a_load_const_stack(list,size,a,def2regtyp(size));
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure thlcgwasm.a_cmp_const_reg_stack(list: TAsmList; size: tdef; cmp_op: topcmp; a: tcgint; reg: tregister);
|
|
procedure thlcgwasm.a_cmp_const_reg_stack(list: TAsmList; size: tdef; cmp_op: topcmp; a: tcgint; reg: tregister);
|
|
begin
|
|
begin
|
|
a_load_reg_stack(list,size,reg);
|
|
a_load_reg_stack(list,size,reg);
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
- a_load_const_stack(list,size,maybe_adjust_cmp_constval(size,cmp_op,a),def2regtyp(size));
|
|
|
|
|
|
+ a_load_const_stack(list,size,a,def2regtyp(size));
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -650,7 +642,6 @@ implementation
|
|
begin
|
|
begin
|
|
tmpref:=ref;
|
|
tmpref:=ref;
|
|
a_load_reg_stack(list,size,reg);
|
|
a_load_reg_stack(list,size,reg);
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
if tmpref.base<>NR_EVAL_STACK_BASE then
|
|
if tmpref.base<>NR_EVAL_STACK_BASE then
|
|
a_load_ref_stack(list,size,tmpref,prepare_stack_for_ref(list,tmpref,false))
|
|
a_load_ref_stack(list,size,tmpref,prepare_stack_for_ref(list,tmpref,false))
|
|
else begin
|
|
else begin
|
|
@@ -658,7 +649,6 @@ implementation
|
|
//list.concat(taicpu.op_none(a_swap));
|
|
//list.concat(taicpu.op_none(a_swap));
|
|
Internalerror(2019083003);
|
|
Internalerror(2019083003);
|
|
end;
|
|
end;
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -669,18 +659,14 @@ implementation
|
|
tmpref:=ref;
|
|
tmpref:=ref;
|
|
if tmpref.base<>NR_EVAL_STACK_BASE then
|
|
if tmpref.base<>NR_EVAL_STACK_BASE then
|
|
a_load_ref_stack(list,size,ref,prepare_stack_for_ref(list,tmpref,false));
|
|
a_load_ref_stack(list,size,ref,prepare_stack_for_ref(list,tmpref,false));
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
a_load_reg_stack(list,size,reg);
|
|
a_load_reg_stack(list,size,reg);
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure thlcgwasm.a_cmp_reg_reg_stack(list: TAsmList; size: tdef; cmp_op: topcmp; reg1, reg2: tregister);
|
|
procedure thlcgwasm.a_cmp_reg_reg_stack(list: TAsmList; size: tdef; cmp_op: topcmp; reg1, reg2: tregister);
|
|
begin
|
|
begin
|
|
a_load_reg_stack(list,size,reg2);
|
|
a_load_reg_stack(list,size,reg2);
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
a_load_reg_stack(list,size,reg1);
|
|
a_load_reg_stack(list,size,reg1);
|
|
- maybe_adjust_cmp_stackval(list,size,cmp_op);
|
|
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
a_cmp_stack_stack(list,size,cmp_op);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -912,44 +898,6 @@ implementation
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
- procedure thlcgwasm.maybe_adjust_cmp_stackval(list: TAsmlist; size: tdef; cmp_op: topcmp);
|
|
|
|
- begin
|
|
|
|
- { use cmp_op because eventually that's what indicates the
|
|
|
|
- signed/unsigned character of the operation, not the size... }
|
|
|
|
- if (cmp_op in [OC_EQ,OC_NE,OC_LT,OC_LTE,OC_GT,OC_GTE]) or
|
|
|
|
- (def2regtyp(size)<>R_INTREGISTER) then
|
|
|
|
- exit;
|
|
|
|
- { http://stackoverflow.com/questions/4068973/c-performing-signed-comparison-in-unsigned-variables-without-casting }
|
|
|
|
- case def_cgsize(size) of
|
|
|
|
- OS_32,OS_S32:
|
|
|
|
- a_op_const_stack(list,OP_XOR,size,cardinal($80000000));
|
|
|
|
- OS_64,OS_S64:
|
|
|
|
- a_op_const_stack(list,OP_XOR,size,tcgint($8000000000000000));
|
|
|
|
- else
|
|
|
|
- ;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- function thlcgwasm.maybe_adjust_cmp_constval(size: tdef; cmp_op: topcmp; a: tcgint): tcgint;
|
|
|
|
- begin
|
|
|
|
- result:=a;
|
|
|
|
- { use cmp_op because eventually that's what indicates the
|
|
|
|
- signed/unsigned character of the operation, not the size... }
|
|
|
|
- if (cmp_op in [OC_EQ,OC_NE,OC_LT,OC_LTE,OC_GT,OC_GTE]) or
|
|
|
|
- (def2regtyp(size)<>R_INTREGISTER) then
|
|
|
|
- exit;
|
|
|
|
- case def_cgsize(size) of
|
|
|
|
- OS_32,OS_S32:
|
|
|
|
- result:=a xor cardinal($80000000);
|
|
|
|
- OS_64,OS_S64:
|
|
|
|
-{$push}{$r-}
|
|
|
|
- result:=a xor tcgint($8000000000000000);
|
|
|
|
-{$pop}
|
|
|
|
- else
|
|
|
|
- ;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
procedure thlcgwasm.maybe_adjust_op_result(list: TAsmList; op: TOpCg; size: tdef);
|
|
procedure thlcgwasm.maybe_adjust_op_result(list: TAsmList; op: TOpCg; size: tdef);
|
|
const
|
|
const
|
|
overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
|
|
overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
|