Re: write statement output buffer flush off on Sun

From: James Giles (jamesgiles_at_worldnet.att.net)
Date: 03/30/04


Date: Tue, 30 Mar 2004 05:11:21 GMT

Robert Corbett wrote:
> "James Giles" <jamesgiles@worldnet.att.net> wrote in message
> news:<8IO9c.60768$PY1.1118150@bgtnsc05-news.ops.worldnet.att.net>...
...
>> The
>> best way (in terms of efficiency) to implement alternate return
>> is to place the address of the chosen return label onto the stack
>> replacing the normal return address and then execute a normal
>> return.
>
> You are assuming that it is likely an alternate return will be taken
> a high percentage of the time. For most programs where I have seen
> alternate returns used, the normal case is a normal return. The cost
> of passing the addresses of the alternate return labels to the called
> routine is usually greater than the cost of checking for a nonzero
> return value. On a certain popular class of machines where arguments
> are passed on the stack, passing the addresses involves memory traffic.

No. I'm assuming that an alternate return is almost never taken.
In that case, the test of the return-code in the caller after every
procedure can be more expensive than placing some addresses
(statically generated) onto the stack with the other argument
addresses (often also statically known). The first is at least
a load of the return code (memory traffic) and a conditional
branch - and it may involve additional instructions on some
hardware where condition codes must be set explicitly by
some compare or arithmetic operation.

Note that a branch *always* involves memory traffic. Instructions
are in memory. A branch often breaks instruction caching. On some
hardware, a conditional branch costs about the same whether it's
taken or not.

Performing the alternate return logic in the procedure instead of
the caller on some hardware can be a large win (especially if the
procedure is fast and the call is inside a loop). You certainly
can't *assume* that an implementation will use a return code.

-- 
J. Giles


Relevant Pages

  • Re: write statement output buffer flush off on Sun
    ... (previously snipped question related to Fortran alternate ... >>are passed on the stack, passing the addresses involves memory traffic. ... > branch - and it may involve additional instructions on some ... > hardware, a conditional branch costs about the same whether it's ...
    (comp.lang.fortran)
  • Re: XP sometimes balks on boot-up
    ... to catch this trap. ... Memory corruption, other hardware ... The most common cause of this is hardware memory corruption. ... A kernel stack overflow. ...
    (microsoft.public.windowsxp.general)
  • Re: ANSI C question about volatile
    ... The *intent* of the C Standard is clear: the hardware has some ... Only one "bus width" is supported, ... the register numbers might change in the process). ... programmer might use the "bis" or "bic" instructions on the VAX: ...
    (comp.lang.c)
  • Re: Higher Order Instructions
    ... push or pop instructions on the evaluation stack. ... higher order instructions to a stack machine these can be trivially ... this scheme amounts to macro expansion since e.g. your compose operation ...
    (microsoft.public.dotnet.framework.clr)
  • Re: implementing Futex
    ... feature atomic instructions, ... This area is prepared by the Kernel and holds functions for all ... Moreover it should be possible to allow "hardware" designers to ... NIOS-like FPGA-processor to provide some hardware support for atomicness ...
    (Linux-Kernel)