• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisão1d61b032265e69317f42e8019e072506f11890c5 (tree)
Hora2019-12-11 19:44:19
AutorAlan Modra <amodra@gmai...>
CommiterAlan Modra

Mensagem de Log

Remove more shifts for sign/zero extension

cpu/
* epiphany.cpu (f-sdisp11): Don't sign extend with shifts.
* lm32.cpu (f-branch, f-vall): Likewise.
* m32.cpu (f-lab-8-16): Likewise.
opcodes/
* arc-dis.c (BITS): Don't truncate high bits with shifts.
* nios2-dis.c (nios2_print_insn_arg): Don't sign extend with shifts.
* tic54x-dis.c (print_instruction): Likewise.
* tilegx-opc.c (parse_insn_tilegx): Likewise.
* tilepro-opc.c (parse_insn_tilepro): Likewise.
* visium-dis.c (disassem_class0): Likewise.
* pdp11-dis.c (sign_extend): Likewise.
(SIGN_BITS): Delete.
* epiphany-ibld.c: Regenerate.
* lm32-ibld.c: Regenerate.
* m32c-ibld.c: Regenerate.

Mudança Sumário

Diff

--- a/cpu/ChangeLog
+++ b/cpu/ChangeLog
@@ -1,5 +1,11 @@
11 2019-12-11 Alan Modra <amodra@gmail.com>
22
3+ * epiphany.cpu (f-sdisp11): Don't sign extend with shifts.
4+ * lm32.cpu (f-branch, f-vall): Likewise.
5+ * m32.cpu (f-lab-8-16): Likewise.
6+
7+2019-12-11 Alan Modra <amodra@gmail.com>
8+
39 * epiphany.cpu (f-simm8, f-simm24): Use multiply rather than
410 shift left to avoid UB on left shift of negative values.
511
--- a/cpu/epiphany.cpu
+++ b/cpu/epiphany.cpu
@@ -228,10 +228,11 @@
228228 (set (ifield f-disp3) (and SI (ifield f-sdisp11) 7)))
229229 (sequence () ;decode
230230 (set (ifield f-sdisp11)
231- (sra SI (sll SI (or SI (sll (ifield f-disp8) 3)
232- (ifield f-disp3))
233- 21)
234- 21)))
231+ (sub SI (xor (and (or (sll (ifield f-disp8) 3)
232+ (ifield f-disp3))
233+ #x7ff)
234+ #x400)
235+ #x400)))
235236 )
236237
237238 (dnmf f-imm16 "Short immediate for move/add/sub" () UINT (f-imm8 f-imm-27-8)
--- a/cpu/lm32.cpu
+++ b/cpu/lm32.cpu
@@ -128,11 +128,15 @@
128128
129129 (df f-branch "branch offset field" (PCREL-ADDR) 15 16 INT
130130 ((value pc) (sra SI (sub SI value pc) 2))
131- ((value pc) (add SI pc (sra SI (sll SI value 16) 14)))
131+ ((value pc) (add SI pc (sub (xor (sll (and value #xffff) 2)
132+ #x20000)
133+ #x20000)))
132134 )
133135 (df f-call "call offset field" (PCREL-ADDR) 25 26 INT
134136 ((value pc) (sra SI (sub SI value pc) 2))
135- ((value pc) (add SI pc (sra SI (sll SI value 6) 4)))
137+ ((value pc) (add SI pc (sub (xor (sll (and value #x3ffffff) 2)
138+ #x8000000)
139+ #x8000000)))
136140 )
137141
138142
--- a/cpu/m32c.cpu
+++ b/cpu/m32c.cpu
@@ -956,9 +956,12 @@
956956 )
957957 (df f-lab-8-16 "16 bit pc relative signed offset" (PCREL-ADDR SIGN-OPT all-isas) 8 16 UINT
958958 ((value pc) (or SI (sll (and (sub value (add pc 1)) #xff) 8)
959- (srl (and (sub value (add pc 1)) #xffff) 8)))
960- ((value pc) (add SI (or (srl (and value #xffff) 8)
961- (sra (sll (and value #xff) 24) 16)) (add pc 1)))
959+ (srl (and (sub value (add pc 1)) #xff00) 8)))
960+ ((value pc) (add SI (sub (xor (or (srl (and value #xff00) 8)
961+ (sll (and value #xff) 8))
962+ #x8000)
963+ #x8000)
964+ (add pc 1)))
962965 )
963966 (df f-lab-8-24 "24 bit absolute" (all-isas ABS-ADDR) 8 24 UINT
964967 ((value pc) (or SI
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,19 @@
11 2019-12-11 Alan Modra <amodra@gmail.com>
22
3+ * arc-dis.c (BITS): Don't truncate high bits with shifts.
4+ * nios2-dis.c (nios2_print_insn_arg): Don't sign extend with shifts.
5+ * tic54x-dis.c (print_instruction): Likewise.
6+ * tilegx-opc.c (parse_insn_tilegx): Likewise.
7+ * tilepro-opc.c (parse_insn_tilepro): Likewise.
8+ * visium-dis.c (disassem_class0): Likewise.
9+ * pdp11-dis.c (sign_extend): Likewise.
10+ (SIGN_BITS): Delete.
11+ * epiphany-ibld.c: Regenerate.
12+ * lm32-ibld.c: Regenerate.
13+ * m32c-ibld.c: Regenerate.
14+
15+2019-12-11 Alan Modra <amodra@gmail.com>
16+
317 * ns32k-dis.c (sign_extend): Correct last patch.
418
519 2019-12-11 Alan Modra <amodra@gmail.com>
--- a/opcodes/arc-dis.c
+++ b/opcodes/arc-dis.c
@@ -137,8 +137,7 @@ static bfd_boolean print_hex = FALSE;
137137 (info->endian == BFD_ENDIAN_LITTLE ? bfd_getm32 (bfd_getl32 (buf)) \
138138 : bfd_getb32 (buf))
139139
140-#define BITS(word,s,e) (((word) << (sizeof (word) * 8 - 1 - e)) >> \
141- (s + (sizeof (word) * 8 - 1 - e)))
140+#define BITS(word,s,e) (((word) >> (s)) & ((1ull << ((e) - (s)) << 1) - 1))
142141 #define OPCODE_32BIT_INSN(word) (BITS ((word), 27, 31))
143142
144143 /* Functions implementation. */
--- a/opcodes/epiphany-ibld.c
+++ b/opcodes/epiphany-ibld.c
@@ -1092,7 +1092,7 @@ epiphany_cgen_extract_operand (CGEN_CPU_DESC cd,
10921092 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_disp8);
10931093 if (length <= 0) break;
10941094 {
1095- FLD (f_sdisp11) = ((SI) (((((((FLD (f_disp8)) << (3))) | (FLD (f_disp3)))) << (21))) >> (21));
1095+ FLD (f_sdisp11) = ((((((((((FLD (f_disp8)) << (3))) | (FLD (f_disp3)))) & (2047))) ^ (1024))) - (1024));
10961096 }
10971097 }
10981098 break;
--- a/opcodes/lm32-ibld.c
+++ b/opcodes/lm32-ibld.c
@@ -680,7 +680,7 @@ lm32_cgen_extract_operand (CGEN_CPU_DESC cd,
680680 {
681681 long value;
682682 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 16, 32, total_length, pc, & value);
683- value = ((pc) + (((SI) (((value) << (16))) >> (14))));
683+ value = ((pc) + (((((((((value) & (65535))) << (2))) ^ (131072))) - (131072))));
684684 fields->f_branch = value;
685685 }
686686 break;
@@ -688,7 +688,7 @@ lm32_cgen_extract_operand (CGEN_CPU_DESC cd,
688688 {
689689 long value;
690690 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 25, 26, 32, total_length, pc, & value);
691- value = ((pc) + (((SI) (((value) << (6))) >> (4))));
691+ value = ((pc) + (((((((((value) & (67108863))) << (2))) ^ (134217728))) - (134217728))));
692692 fields->f_call = value;
693693 }
694694 break;
--- a/opcodes/m32c-ibld.c
+++ b/opcodes/m32c-ibld.c
@@ -1489,7 +1489,7 @@ m32c_cgen_insert_operand (CGEN_CPU_DESC cd,
14891489 case M32C_OPERAND_LAB_8_16 :
14901490 {
14911491 long value = fields->f_lab_8_16;
1492- value = ((((((((value) - (((pc) + (1))))) & (255))) << (8))) | (((USI) (((((value) - (((pc) + (1))))) & (65535))) >> (8))));
1492+ value = ((((((((value) - (((pc) + (1))))) & (255))) << (8))) | (((USI) (((((value) - (((pc) + (1))))) & (65280))) >> (8))));
14931493 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGN_OPT)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 16, 32, total_length, buffer);
14941494 }
14951495 break;
@@ -2654,7 +2654,7 @@ m32c_cgen_extract_operand (CGEN_CPU_DESC cd,
26542654 {
26552655 long value;
26562656 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 16, 32, total_length, pc, & value);
2657- value = ((((((USI) (((value) & (65535))) >> (8))) | (((SI) (((((value) & (255))) << (24))) >> (16))))) + (((pc) + (1))));
2657+ value = ((((((((((USI) (((value) & (65280))) >> (8))) | (((((value) & (255))) << (8))))) ^ (32768))) - (32768))) + (((pc) + (1))));
26582658 fields->f_lab_8_16 = value;
26592659 }
26602660 break;
--- a/opcodes/nios2-dis.c
+++ b/opcodes/nios2-dis.c
@@ -554,10 +554,10 @@ nios2_print_insn_arg (const char *argptr,
554554 switch (op->format)
555555 {
556556 case iw_i_type:
557- s = (int32_t) (GET_IW_I_IMM16 (opcode) << 16) >> 16;
557+ s = ((GET_IW_I_IMM16 (opcode) & 0xffff) ^ 0x8000) - 0x8000;
558558 break;
559559 case iw_F2I16_type:
560- s = (int32_t) (GET_IW_F2I16_IMM16 (opcode) << 16) >> 16;
560+ s = ((GET_IW_F2I16_IMM16 (opcode) & 0xffff) ^ 0x8000) - 0x8000;
561561 break;
562562 default:
563563 bad_opcode (op);
@@ -570,10 +570,10 @@ nios2_print_insn_arg (const char *argptr,
570570 switch (op->format)
571571 {
572572 case iw_F2X4I12_type:
573- s = (int32_t) (GET_IW_F2X4I12_IMM12 (opcode) << 20) >> 20;
573+ s = ((GET_IW_F2X4I12_IMM12 (opcode) & 0xfff) ^ 0x800) - 0x800;
574574 break;
575575 case iw_F1X4I12_type:
576- s = (int32_t) (GET_IW_F1X4I12_IMM12 (opcode) << 20) >> 20;
576+ s = ((GET_IW_F1X4I12_IMM12 (opcode) & 0xfff) ^ 0x800) - 0x800;
577577 break;
578578 default:
579579 bad_opcode (op);
@@ -673,10 +673,10 @@ nios2_print_insn_arg (const char *argptr,
673673 switch (op->format)
674674 {
675675 case iw_i_type:
676- o = (int32_t) (GET_IW_I_IMM16 (opcode) << 16) >> 16;
676+ o = ((GET_IW_I_IMM16 (opcode) & 0xffff) ^ 0x8000) - 0x8000;
677677 break;
678678 case iw_F2I16_type:
679- o = (int32_t) (GET_IW_F2I16_IMM16 (opcode) << 16) >> 16;
679+ o = ((GET_IW_F2I16_IMM16 (opcode) & 0xffff) ^ 0x8000) - 0x8000;
680680 break;
681681 default:
682682 bad_opcode (op);
@@ -690,7 +690,7 @@ nios2_print_insn_arg (const char *argptr,
690690 switch (op->format)
691691 {
692692 case iw_I10_type:
693- o = (int32_t) (GET_IW_I10_IMM10 (opcode) << 22) >> 21;
693+ o = (((GET_IW_I10_IMM10 (opcode) & 0x3ff) ^ 0x400) - 0x400) << 1;
694694 break;
695695 default:
696696 bad_opcode (op);
@@ -704,7 +704,7 @@ nios2_print_insn_arg (const char *argptr,
704704 switch (op->format)
705705 {
706706 case iw_T1I7_type:
707- o = (int32_t) (GET_IW_T1I7_IMM7 (opcode) << 25) >> 24;
707+ o = (((GET_IW_T1I7_IMM7 (opcode) & 0x7f) ^ 0x40) - 0x40) << 1;
708708 break;
709709 default:
710710 bad_opcode (op);
--- a/opcodes/pdp11-dis.c
+++ b/opcodes/pdp11-dis.c
@@ -31,8 +31,7 @@
3131 #define F info->stream
3232
3333 /* Sign-extend a 16-bit number in an int. */
34-#define SIGN_BITS (8 * sizeof (int) - 16)
35-#define sign_extend(x) (((x) << SIGN_BITS) >> SIGN_BITS)
34+#define sign_extend(x) ((((x) & 0xffff) ^ 0x8000) - 0x8000)
3635
3736 static int
3837 read_word (bfd_vma memaddr, int *word, disassemble_info *info)
--- a/opcodes/tic54x-dis.c
+++ b/opcodes/tic54x-dis.c
@@ -394,8 +394,7 @@ print_instruction (disassemble_info *info,
394394 break;
395395 }
396396 case OP_k5:
397- sprintf (operand[i], "#%d",
398- (int) (((signed char) opcode & 0x1F) << 3) >> 3);
397+ sprintf (operand[i], "#%d", ((opcode & 0x1F) ^ 0x10) - 0x10);
399398 info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
400399 break;
401400 case OP_k8u:
--- a/opcodes/tilegx-opc.c
+++ b/opcodes/tilegx-opc.c
@@ -8102,8 +8102,8 @@ parse_insn_tilegx (tilegx_bundle_bits bits,
81028102 if (op->is_signed)
81038103 {
81048104 /* Sign-extend the operand. */
8105- int shift = (int)((sizeof(int) * 8) - op->num_bits);
8106- raw_opval = (raw_opval << shift) >> shift;
8105+ unsigned int sign = 1u << (op->num_bits - 1);
8106+ raw_opval = ((raw_opval & (sign + sign - 1)) ^ sign) - sign;
81078107 }
81088108
81098109 /* Adjust PC-relative scaled branch offsets. */
--- a/opcodes/tilepro-opc.c
+++ b/opcodes/tilepro-opc.c
@@ -10220,8 +10220,8 @@ parse_insn_tilepro (tilepro_bundle_bits bits,
1022010220 if (op->is_signed)
1022110221 {
1022210222 /* Sign-extend the operand. */
10223- int shift = (int)((sizeof(int) * 8) - op->num_bits);
10224- opval = (opval << shift) >> shift;
10223+ unsigned int sign = 1u << (op->num_bits - 1);
10224+ opval = ((opval & (sign + sign - 1)) ^ sign) - sign;
1022510225 }
1022610226
1022710227 /* Adjust PC-relative scaled branch offsets. */
--- a/opcodes/visium-dis.c
+++ b/opcodes/visium-dis.c
@@ -94,7 +94,7 @@ disassem_class0 (disassemble_info *info, unsigned int ins)
9494 /* BRR instruction. */
9595 {
9696 unsigned cbf = (ins >> 27) & 0x000f;
97- int displacement = ((int) (ins << 16)) >> 16;
97+ int displacement = ((ins & 0xffff) ^ 0x8000) - 0x8000;
9898
9999 if (ins == 0)
100100 (*info->fprintf_func) (info->stream, "nop");