From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26483 invoked by alias); 20 Feb 2014 09:54:50 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 26472 invoked by uid 89); 20 Feb 2014 09:54:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: mailfilter04.hatteland.com Received: from mailfilter04.hatteland.com (HELO mailfilter04.hatteland.com) (213.162.250.23) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 20 Feb 2014 09:54:48 +0000 Received: from mailfilter04.hatteland.com (localhost [127.0.0.1]) by mailfilter04.hatteland.com (Postfix) with ESMTP id E8004FD1B6; Thu, 20 Feb 2014 10:54:44 +0100 (CET) Received: from JHSVMHUB01.netsentral.no (unknown [172.21.1.101]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mailfilter04.hatteland.com (Postfix) with ESMTPS id 4E6AFFD183; Thu, 20 Feb 2014 10:54:29 +0100 (CET) Received: from [192.168.0.65] (172.21.20.11) by e2010.hatteland.com (172.21.1.25) with Microsoft SMTP Server (TLS) id 14.3.174.1; Thu, 20 Feb 2014 10:54:28 +0100 Message-ID: <5305D0D4.6080105@westcontrol.com> Date: Thu, 20 Feb 2014 09:54:00 -0000 From: David Brown User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Cody Rigney , Subject: Re: Compiler optimizing variables in inline assembly References: In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-SW-Source: 2014-02/txt/msg00124.txt.bz2 Hi, I haven't read through the code at all, but I will give you a little general advice. Try to cut the code to the absolute minimum that shows the problem. It makes it easier for you to work with and check, and it makes it easier for other people to examine. Also make sure that the code has no other dependencies such as extra headers - ideally people should be able to compile the code themselves and test it (I realise this is difficult for those who don't have an ARM handy). Code that works without optimisation but fails with optimisation, or that works when you make a variable volatile, is always a bug. Occasionally, it is a bug in the compiler - but most often it is a bug in the code. Either way, it is important to figure out the root cause, and not try to hide it by making things volatile (though that might be a good temporary fix for a compiler bug). I am not familiar with Neon (and not as good as I should be at ARM assembly in general), but it looks to me that you have used specific registers in your inline assembly, and assumed specific registers for compiler use (such as variables). Don't do that. When you have turned off all optimisation, the compiler is consistent about which registers it uses for different purposes - when optimising, it changes register usage in a very unpredictable way. You must be explicit - all data going into your assembly must be declared, as must all data coming out of the assembly. And if you use specific registers, you need to tell the compiler about them (as "clobbers") - and be aware that the compiler might be using those registers for the input or output values. Getting inline assembly right is not easy, and it is often best to work with several small assembly statements rather than large ones - I usually make a "static inline" function around a line or two of inline assembly and then use that function in the code as needed. It can make the result a lot clearer, and makes it easier to mix the C and assembly - the end result is often better than I would make in pure assembly. Finally, is there a good reason why you need inline assembly rather than the neon intrinsics provided by gcc? mvh., David On 19/02/14 20:04, Cody Rigney wrote: > Hi, > > I'm trying to add NEON optimizations to OpenCV's LK optical flow. See > link below. > https://github.com/Itseez/opencv/blob/2.4/modules/video/src/lkpyramid.cpp > > The gcc version could vary since this is an open source project, but > the one I'm currently using is 4.8.1. The target architecture is ARMv7 > w/ NEON. The processor I'm testing on is an ARM > Cortex-A15(big.LITTLE). > > The problem is, in release mode (where optimizations are set) it does > not work properly. However, in debug mode, it works fine. I tracked > down a specific variable(FLT_SCALE) that was being optimized out and > made it volatile and that part worked fine after that. However, I'm > still having incorrect behavior from some other optimization. I'm new > to inline assembly, so I thought maybe I'm doing something wrong > that's not telling the compiler that I'm using a certain variable. > > Below is the code at its current state. Ignore all the comments and > volatiles(for testing this problem) everywhere. It's WIP. I removed > unnecessary functions and code so it would be easier to see. I think > the problem is in the bottom-most asm block because if I do if(false) > to skip it, I don't run into the problem. Thanks. >