[erlang-patches] [PATCH] Modify pp_arm to decode imm8m constants

Johan Bengtsson <>
Tue Apr 6 21:41:17 CEST 2010


On Tue, 2010-04-06 at 08:14 +0200, Mikael Pettersson wrote:
> Johan Bengtsson writes:
>  > Improve readability by decoding imm8m constants before printing them.
>  > 
>  > Signed-off-by: Johan Bengtsson <>
>  > ---
>  >  lib/hipe/arm/hipe_arm_pp.erl |    8 +++++++-
>  >  1 files changed, 7 insertions(+), 1 deletions(-)
>  > 
>  > diff --git a/lib/hipe/arm/hipe_arm_pp.erl b/lib/hipe/arm/hipe_arm_pp.erl
>  > index 7ce8421..a98f8fc 100644
>  > --- a/lib/hipe/arm/hipe_arm_pp.erl
>  > +++ b/lib/hipe/arm/hipe_arm_pp.erl
>  > @@ -246,6 +246,12 @@ stop_suffix(StOp) ->
>  >      'strb' -> "b"
>  >    end.
>  >  
>  > +imm8m_decode(Value, 0) ->
>  > +  Value;
>  > +imm8m_decode(Value, Rot) ->
>  > +  (Value bsr (2 * Rot)) bor (Value bsl (2 * (16 - Rot))).
>  > +
>  > +
> 
> One newline too many here.
> 
>  >  pp_temp(Dev, Temp=#arm_temp{reg=Reg, type=Type}) ->
>  >    case hipe_arm:temp_is_precoloured(Temp) of
>  >      true ->
>  > @@ -292,7 +298,7 @@ pp_am1(Dev, Am1) ->
>  >  	  io:format(Dev, "#~w", [Imm5])
>  >        end;
>  >      {Imm8,Imm4} ->
>  > -      io:format(Dev, "#~w, 2*~w", [Imm8,Imm4])
>  > +      io:format(Dev, "#~s", [to_hex(imm8m_decode(Imm8, Imm4))])
>  >    end.
>  >  
>  >  pp_am2(Dev, #am2{src=Src,sign=Sign,offset=Am2Offset}) ->
> 
> Please show a before/after diff for the output of pp_arm on some small
> function, preferably one using an immediate with a non-zero rotate.

For the attached file the difference is

--- test2-before.txt	2010-04-06 08:27:06.000000000 +0200
+++ test2-after.txt	2010-04-06 08:27:35.000000000 +0200
@@ -30,28 +30,28 @@
 	.global test2_knas_1
 test2_knas_1:
 .test2_knas_1_12:
-	sub r10, r10, #4, 2*0
+	sub r10, r10, #0x4
 	str r14, [r10,#0]
 .test2_knas_1_11:
 	mov r1, r1
 .test2_knas_1_6:
-	and r0, r1, #15, 2*0
-	cmp r0, #15, 2*0
+	and r0, r1, #0xf
+	cmp r0, #0xf
 	bne .test2_knas_1_3
 .test2_knas_1_5:
 	mov r4, r1, asr #4
-	mov r0, #255, 2*12
+	mov r0, #0xff00
 	smull r3, r2, r4, r0
 	mov r0, r3, asr #31
 	cmp r0, r2
 	bne .test2_knas_1_3
 .test2_knas_1_4:
-	add r0, r3, #15, 2*0
+	add r0, r3, #0xf
 	mov r0, r0
 .test2_knas_1_2:
 	mov r0, r0
 	ldr r14, [r10,#0]
-	add r10, r10, #4, 2*0
+	add r10, r10, #0x4
 	mov r15, r14
 .test2_knas_1_3:
 	mov r1, r1



-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.erl
Type: text/x-erlang
Size: 65 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20100406/c1f4437c/attachment.bin>


More information about the erlang-patches mailing list