Hello! Attached patch introduces a couple of asm_fprintf extensions to simplify handling of word-mode operands.
2017-07-26 Uros Bizjak <ubiz...@gmail.com> * config/i386/i386.h (ASM_PRINTF_EXTENSIONS): New macro. (ASM_OUTPUT_REG_PUSH): Rewrite with new operand modifiers. (ASM_OUTPUT_REG_POP): Ditto. * config/i386/i386.c (ix86_asm_output_function_label): Use fputs instead of asm_fprintf to output pure string. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Uros.
Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 250563) +++ config/i386/i386.c (working copy) @@ -8777,8 +8777,8 @@ ix86_asm_output_function_label (FILE *asm_out_file if (TARGET_64BIT) { /* leaq [%rsp + 0], %rsp */ - asm_fprintf (asm_out_file, ASM_BYTE - "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n"); + fputs (ASM_BYTE "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n", + asm_out_file); } else { @@ -8785,8 +8785,7 @@ ix86_asm_output_function_label (FILE *asm_out_file /* movl.s %edi, %edi push %ebp movl.s %esp, %ebp */ - asm_fprintf (asm_out_file, ASM_BYTE - "0x8b, 0xff, 0x55, 0x8b, 0xec\n"); + fputs (ASM_BYTE "0x8b, 0xff, 0x55, 0x8b, 0xec\n", asm_out_file); } } } Index: config/i386/i386.h =================================================================== --- config/i386/i386.h (revision 250563) +++ config/i386/i386.h (working copy) @@ -2196,29 +2196,33 @@ extern int const svr4_dbx_register_map[FIRST_PSEUD #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ asm_preferred_eh_data_format ((CODE), (GLOBAL)) -/* This is how to output an insn to push a register on the stack. - It need not be very fast code. */ +/* These are a couple of extensions to the formats accepted + by asm_fprintf: + %z prints out opcode suffix for word-mode instruction + %r prints out word-mode name for reg_names[arg] */ +#define ASM_FPRINTF_EXTENSIONS(FILE, ARGS, P) \ + case 'z': \ + fputc (TARGET_64BIT ? 'q' : 'l', (FILE)); \ + break; \ + \ + case 'r': \ + { \ + unsigned int regno = va_arg ((ARGS), int); \ + if (LEGACY_INT_REGNO_P (regno)) \ + fputc (TARGET_64BIT ? 'r' : 'e', (FILE)); \ + fputs (reg_names[regno], (FILE)); \ + break; \ + } -#define ASM_OUTPUT_REG_PUSH(FILE, REGNO) \ -do { \ - if (TARGET_64BIT) \ - asm_fprintf ((FILE), "\tpush{q}\t%%r%s\n", \ - reg_names[(REGNO)] + (REX_INT_REGNO_P (REGNO) != 0)); \ - else \ - asm_fprintf ((FILE), "\tpush{l}\t%%e%s\n", reg_names[(REGNO)]); \ -} while (0) +/* This is how to output an insn to push a register on the stack. */ -/* This is how to output an insn to pop a register from the stack. - It need not be very fast code. */ +#define ASM_OUTPUT_REG_PUSH(FILE, REGNO) \ + asm_fprintf ((FILE), "\tpush%z\t%%%r\n", (REGNO)) +/* This is how to output an insn to pop a register from the stack. */ + #define ASM_OUTPUT_REG_POP(FILE, REGNO) \ -do { \ - if (TARGET_64BIT) \ - asm_fprintf ((FILE), "\tpop{q}\t%%r%s\n", \ - reg_names[(REGNO)] + (REX_INT_REGNO_P (REGNO) != 0)); \ - else \ - asm_fprintf ((FILE), "\tpop{l}\t%%e%s\n", reg_names[(REGNO)]); \ -} while (0) + asm_fprintf ((FILE), "\tpop%z\t%%%r\n", (REGNO)) /* This is how to output an element of a case-vector that is absolute. */