From e163a2c8135e2782fdef85c1a20da38d2739db52 Mon Sep 17 00:00:00 2001 From: sergei Date: Mon, 10 Mar 2014 23:02:05 +0000 Subject: [PATCH] * MIPS and SPARC: determine whether case expression is in range using a single unsigned comparison (like it is done on other targets). git-svn-id: trunk@27088 - --- compiler/mips/ncpuset.pas | 9 +++++---- compiler/sparc/ncpuset.pas | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/mips/ncpuset.pas b/compiler/mips/ncpuset.pas index ddfa2949c5..cbc7370e54 100644 --- a/compiler/mips/ncpuset.pas +++ b/compiler/mips/ncpuset.pas @@ -91,13 +91,15 @@ var begin opcgsize:=def_cgsize(opsize); + last:=min_; jumpsegment := current_procinfo.aktlocaldata; if not (jumptable_no_range) then begin - { case expr less than min_ => goto elselabel } - cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opcgsize, jmp_lt, aint(min_), hregister, elselabel); + { a <= x <= b <-> unsigned(x-a) <= (b-a) } + cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,opcgsize,aint(min_),hregister); { case expr greater than max_ => goto elselabel } - cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opcgsize, jmp_gt, aint(max_), hregister, elselabel); + cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opcgsize,OC_A,aint(max_)-aint(min_),hregister,elselabel); + min_:=0; end; current_asmdata.getjumplabel(table); indexreg := cg.getaddressregister(current_asmdata.CurrAsmList); @@ -123,7 +125,6 @@ begin { generate jump table } new_section(jumpSegment,sec_rodata,current_procinfo.procdef.mangledname,sizeof(aint)); jumpSegment.concat(Tai_label.Create(table)); - last := min_; genitem(hp); end; diff --git a/compiler/sparc/ncpuset.pas b/compiler/sparc/ncpuset.pas index 4b4940fbdd..4e648fbe9d 100644 --- a/compiler/sparc/ncpuset.pas +++ b/compiler/sparc/ncpuset.pas @@ -90,12 +90,14 @@ unit ncpuset; begin opcgsize:=def_cgsize(opsize); + last:=min_; if not(jumptable_no_range) then begin - { case expr less than min_ => goto elselabel } - cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opcgsize,jmp_lt,aint(min_),hregister,elselabel); - { case expr greater than max_ => goto elselabel } - cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opcgsize,jmp_gt,aint(max_),hregister,elselabel); + { a <= x <= b <-> unsigned(x-a) <= (b-a) } + cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,opcgsize,aint(min_),hregister); + { case expr greater than max_ => goto elselabel } + cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opcgsize,OC_A,aint(max_)-aint(min_),hregister,elselabel); + min_:=0; end; current_asmdata.getjumplabel(table); indexreg:=cg.getaddressregister(current_asmdata.CurrAsmList); @@ -137,7 +139,6 @@ unit ncpuset; current_asmdata.CurrAsmList.concat(taicpu.op_none(A_NOP)); cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_O7); { generate jump table } - last:=min_; cg.a_label(current_asmdata.CurrAsmList,table); genitem(current_asmdata.CurrAsmList,hp); end;