From patchwork Mon Oct 12 17:01:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 529233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D4B431400CB for ; Tue, 13 Oct 2015 04:01:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=sBC7du87; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=tUx0Np3haEIUZuWldOI47HVPWFnXQGGOrRfio7YVtTyqF0 1YdWOeZddP1lyTIhkzjGqoJmUQkQ9Cam3TcePs8hoFq5s1xC7AlARVGkMU7xEPfj 32vvoGTW0ANDXPFUsT6sYJnOlLdmtGoKWuAt2CNLJMrANI4t3v/96fCYGKapc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=TzEzKgE+8J0QZzlC827APKXJfYQ=; b=sBC7du87o5Myi2qI7Kim j6PAFHReEt4PEOkh2rpb4sF4WPTkF9b49/1ouVCbKoxDWO3YUp8C9KosPLrVRYYx jt/C7VdoOvIIwp4SiB7XmgTUoubCJYEmVTPtiD8TQ4DlnQTUimSAavK9Y0Btd10B xMe++jzKv1mkBVzKkjZCMwM= Received: (qmail 103619 invoked by alias); 12 Oct 2015 17:01:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 103605 invoked by uid 89); 12 Oct 2015 17:01:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-vk0-f47.google.com Received: from mail-vk0-f47.google.com (HELO mail-vk0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 12 Oct 2015 17:01:30 +0000 Received: by vkat63 with SMTP id t63so89690888vka.1 for ; Mon, 12 Oct 2015 10:01:27 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.31.138.72 with SMTP id m69mr18914284vkd.66.1444669287751; Mon, 12 Oct 2015 10:01:27 -0700 (PDT) Received: by 10.103.40.68 with HTTP; Mon, 12 Oct 2015 10:01:27 -0700 (PDT) Date: Mon, 12 Oct 2015 19:01:27 +0200 Message-ID: Subject: [PATCH, sparc]: Use ROUND_UP and ROUND_DOWN macros From: Uros Bizjak To: "gcc-patches@gcc.gnu.org" Two functional changes I'd like to point out: /* ALIGN FRAMES on double word boundaries */ -#define SPARC_STACK_ALIGN(LOC) \ - (TARGET_ARCH64 ? (((LOC)+15) & ~15) : (((LOC)+7) & ~7)) +#define SPARC_STACK_ALIGN(LOC) ROUND_UP ((LOC), UNITS_PER_WORD * 2) The one above uses UNITS_PER_WORD in stack alignment calculation /* Always preserve double-word alignment. */ - offset = (offset + 8) & -8; + offset = ROUND_UP (offset, 8); The one above looks like off-by-one bug, but this needs a confirmation. 2015-10-12 Uros Bizjak * config/sparc/sparc.h (SPARC_STACK_ALIGN): Implement using ROUND_UP macro and UNITS_PER_WORD * 2. * config/sparc/sparc.c (sparc_compute_frame_size): Use ROUND_UP and ROUND_DOWN macros where applicable. (function_arg_record_value, function_arg_record_value_1) (function_arg_record_value_1): Ditto. (emit_save_or_restore_regs): Use ROUND_UP to preserve offset alignment to double-word. (sparc_gimplify_va_arg): Use ROUND_UP ro calculate rsize. (sparc_emit_probe_stack_range): Use ROUND_DOWN to calculate rounded_size. Tested by building a crosscompiler to sparc-linux-gnu. Due to the two above changes, can someone please bootstrap and regression test this patch properly on sparc targets? OK for mainline if bootstrap+regtest show no problems? Uros. Index: config/sparc/sparc.c =================================================================== --- config/sparc/sparc.c (revision 228726) +++ config/sparc/sparc.c (working copy) @@ -4981,11 +4981,11 @@ sparc_compute_frame_size (HOST_WIDE_INT size, int else { /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */ - apparent_frame_size = (size - STARTING_FRAME_OFFSET + 7) & -8; + apparent_frame_size = ROUND_UP (size - STARTING_FRAME_OFFSET, 8); apparent_frame_size += n_global_fp_regs * 4; /* We need to add the size of the outgoing argument area. */ - frame_size = apparent_frame_size + ((args_size + 7) & -8); + frame_size = apparent_frame_size + ROUND_UP (args_size, 8); /* And that of the register window save area. */ frame_size += FIRST_PARM_OFFSET (cfun->decl); @@ -5116,7 +5116,7 @@ sparc_emit_probe_stack_range (HOST_WIDE_INT first, /* Step 1: round SIZE to the previous multiple of the interval. */ - rounded_size = size & -PROBE_INTERVAL; + rounded_size = ROUND_DOWN (size, PROBE_INTERVAL); emit_move_insn (g4, GEN_INT (rounded_size)); @@ -5317,7 +5317,7 @@ emit_save_or_restore_regs (unsigned int low, unsig emit_move_insn (gen_rtx_REG (mode, regno), mem); /* Always preserve double-word alignment. */ - offset = (offset + 8) & -8; + offset = ROUND_UP (offset, 8); } } @@ -6439,8 +6439,8 @@ function_arg_record_value_1 (const_tree type, HOST unsigned int startbit, endbit; int intslots, this_slotno; - startbit = parms->intoffset & -BITS_PER_WORD; - endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD; + startbit = ROUND_DOWN (parms->intoffset, BITS_PER_WORD); + endbit = ROUND_UP (bitpos, BITS_PER_WORD); intslots = (endbit - startbit) / BITS_PER_WORD; this_slotno = parms->slotno + parms->intoffset @@ -6495,8 +6495,8 @@ function_arg_record_value_3 (HOST_WIDE_INT bitpos, intoffset = parms->intoffset; parms->intoffset = -1; - startbit = intoffset & -BITS_PER_WORD; - endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD; + startbit = ROUND_DOWN (intoffset, BITS_PER_WORD); + endbit = ROUND_UP (bitpos, BITS_PER_WORD); intslots = (endbit - startbit) / BITS_PER_WORD; this_slotno = parms->slotno + intoffset / BITS_PER_WORD; @@ -6669,8 +6669,8 @@ function_arg_record_value (const_tree type, machin unsigned int startbit, endbit; int intslots, this_slotno; - startbit = parms.intoffset & -BITS_PER_WORD; - endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD; + startbit = ROUND_DOWN (parms.intoffset, BITS_PER_WORD); + endbit = ROUND_UP (typesize*BITS_PER_UNIT, BITS_PER_WORD); intslots = (endbit - startbit) / BITS_PER_WORD; this_slotno = slotno + parms.intoffset / BITS_PER_WORD; @@ -7451,7 +7451,7 @@ sparc_gimplify_va_arg (tree valist, tree type, gim { indirect = false; size = int_size_in_bytes (type); - rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD; + rsize = ROUND_UP (size, UNITS_PER_WORD); align = 0; if (TARGET_ARCH64) Index: config/sparc/sparc.h =================================================================== --- config/sparc/sparc.h (revision 228726) +++ config/sparc/sparc.h (working copy) @@ -510,8 +510,7 @@ extern enum cmodel sparc_cmodel; #define SPARC_STACK_BOUNDARY_HACK (TARGET_ARCH64 && TARGET_STACK_BIAS) /* ALIGN FRAMES on double word boundaries */ -#define SPARC_STACK_ALIGN(LOC) \ - (TARGET_ARCH64 ? (((LOC)+15) & ~15) : (((LOC)+7) & ~7)) +#define SPARC_STACK_ALIGN(LOC) ROUND_UP ((LOC), UNITS_PER_WORD * 2) /* Allocation boundary (in *bits*) for the code of a function. */ #define FUNCTION_BOUNDARY 32