I'm trying to write a constructor for the movi20s instruction of the SH-2A core. It is defined as follows:
MOVI20S (long i, long n)
/* MOVI20S #imm, Rn */
{
if (i&0x00080000) ==0) R[n]= (0x000FFFFF & (long) i);
else R[n]=(0xFFF00000 | (long) i);
R[n]<<=8;
PC+=4;
}
So I'd basically like to write something like this:
# MOVI20S #imm20, Rn
# 0000nnnniiii0001 iiiiiiiiiiiiiiii
# imm<<8 → sign extension → Rn
imm20s: "#"imm20Shifted is l_imm20_20_23 & l_imm20_00_16
[ imm20Shifted = sext(((l_imm20_20_23 << 16) | l_imm20_00_16) << 8); ]
{ export *[ram]:4 imm20Shifted; }
:movi20s imm20s, l_rn_24_27
is l_opcode_28_31=0b0000 & l_rn_24_27 & l_opcode_16_19=0b0001 & imm20s
{
l_rn_24_27 = imm20s;
}
But using sext in the action section will not compile... any idea how to use a "complex statement" both in the display section and the semantic section?
Thanks in advance.
Just make another token similar to l_imm20_20_23 but signed
Just make another token similar to l_imm20_20_23 but signed
Thanks for the quick reply, I am making l_imm20_20_23 signed and it still doesn't work ->
define token instr32(32)
l_disp_00_11 = (0, 11)
l_opcode_12_15 = (12, 15)
l_opcode_16_19 = (16, 19)
l_rm_20_23 = (20, 23)
l_rn_24_27 = (24, 27)
l_opcode_28_31 = (28, 31)
l_simm20_00_16 = (0, 16) signed
l_simm20_20_23 = (20, 23) signed
;
...
imm20: "#"value is l_simm20_20_23 & l_simm20_00_16
[ value = sext((l_simm20_20_23 << 16) | l_simm20_00_16); ]
{ export *[ram]:4 value; }
imm20s: "#"value is l_simm20_20_23 & l_simm20_00_16
[ value = sext(((l_simm20_20_23 << 16) | l_simm20_00_16) << 8); ]
{ export *[ram]:4 value; }
# MOVI20 #imm20, Rn 0000nnnniiii0000 iiiiiiiiiiiiiiii imm → sign extension → Rn
:movi20 imm20, l_rn_24_27
is l_opcode_28_31=0b0000 & l_rn_24_27 & l_opcode_16_19=0b0000 & imm20
{
l_rn_24_27 = imm20;
}
# MOVI20S #imm20, Rn 0000nnnniiii0001 iiiiiiiiiiiiiiii imm<<8 → sign extension → Rn
:movi20s imm20s, l_rn_24_27
is l_opcode_28_31=0b0000 & l_rn_24_27 & l_opcode_16_19=0b0001 & imm20s
{
l_rn_24_27 = imm20s;
}
And the compilation result is as follows:
Compiling ./data/languages/sh-2a.slaspec: superh.sinc line 352: no viable alternative on: 'value': [ value = sext((l_simm20_20_23 << 16) | l_simm20_00_16); ] ------^ superh.sinc line 352: no viable alternative on : '|': [ value = sext((l_simm20_20_23 << 16) | l_simm20_00_16); ] ------------------------------------------^ No output produced
Removing sext compiles...
Thanks, seems that sext is not needed at all if the token is signed.
Most helpful comment
Just make another token similar to l_imm20_20_23 but signed