🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #49715

Re: Optimization question

#49715
From: David Kastrup
Date: Sat, 01 Jan 1994 17:35
37 lines
2430 bytes
rlk@think.com (Robert L Krawitz) writes:

>Does anyone know how to make gcc NOT optimize this sort of expression:

>	    tempvar = *CURDEV.headaddr >> 16;
>	    tempvar = tempvar << 16;
>	    tempvar |= *CURDEV.patch_head_2 >> 16;
>	    break;

>The optimizer transforms this into various halfword loads and stores,
>but unfortunately the memory that this references is not addressable in
>quantities less than a full word, so the kernel (yup, this is kernel
>code) takes a bus error.

>Yes, it's possible to put temporary variables in, but this code seems to
>be all over the place.  I don't want to turn off optimization altogether
>because this is in an interrupt handler.

>This is gcc 2.3.3 running on a sparc.

First, I find it impressive that gcc optimizes this. Secondly, you might
try declaring CURDEV.headaddr as a pointer to volatile data, as memory
locations of special significance (such as memory mapped I/O) should
be declared usually, so that the comiler knows not to reorder and
reorganize accesses (just like it does here).

Whether gcc 2.3.3 sufficiently supports valatile as to make this
working correctly, I do not know. In addition, the above code will
(if it works) obviously reference the memory twice, so you might be
tempted to throw in the extra local variable anyway.

But declaring hardware locations volatile should be the first step, and
is really necessary anyhow if you have a highly optimizing compiler.
-- 
 David Kastrup        dak@pool.informatik.rwth-aachen.de          
 Tel: +49-241-72419 Fax: +49-241-79502
 Goethestr. 20, D-52064 Aachen
Technical Details
Message-ID: <2g4c8j$dlh@urmel.informatik.rwth-aachen.de>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!uunet!zib-berlin.de!uni-paderborn.de!urmel.informatik.rwth-aachen.de!tabaqui!dak
References: <9312271918.AA29983@underprize.think.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,6164fb20f70fc94b
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1994-01-01 09:34:57 PST
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!uunet!zib-berlin.de!uni-paderborn.de!urmel.informatik.rwth-aachen.de!tabaqui!dak
From: dak@tabaqui.informatik.rwth-aachen.de (David Kastrup)
Newsgroups: gnu.gcc.help
Subject: Re: Optimization question
Date: 1 Jan 1994 17:35:15 GMT
Organization: Rechnerbetrieb Informatik - RWTH Aachen
Lines: 37
Distribution: gnu
Message-ID: <2g4c8j$dlh@urmel.informatik.rwth-aachen.de>
References: <9312271918.AA29983@underprize.think.com>
NNTP-Posting-Host: tabaqui.informatik.rwth-aachen.de
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit