octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bitshift of int8, int16, etc?


From: Daniel J Sebald
Subject: Re: bitshift of int8, int16, etc?
Date: Mon, 25 Jun 2007 16:11:13 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

David Bateman wrote:

This is the standard behavior of an arithmetic shift.. See

http://en.wikipedia.org/wiki/Arithmetic_shift

I looked at that reference yesterday.  OK, good then.


Ok, saturation might make sense. My preference was or an arithmetic
shift as a shift operator that had a clear and documented functionality.

DSP chips often have a control register with a bit to change such behavior, 
i.e. wrap or saturate.


If we got with a saturation we are defining our own operator (which is
fine of course). Ok, I'd be happy with saturation, but I don't see an
efficient implmentation.


The lack of overflow information concerns me a bit.  Should or shouldn't
that be worked into the code?


As with << and >> in C, its up to the user. I suppose we could set a
warning that is normally off, that would flag an overflow.

In any case, what would you propose as a patch

Well, how would one set up syntax to access that info?

[result, overflow] = bitshift (A, K, N, control)

The idea is to avoid the user having to use a somewhat clumsy programming 
technique of needing to know the values before the operation to understand what 
happened to them, i.e., unwind what was done, e.g.

A_after = bitshift (A, K, N, control);
if (sign(A_after) != sign(A_before))
 saturate or something etc...;
endif

and even that may not be right because I suppose a number could wrap around the 
range twice and end up being the same sign as it went in.

The "overflow" and "control" values would be optional.  Or could toss the 
"control" argument and implement different variations (if ever someone wants them) as a different 
function name, e.g., bitshiftwithsaturate().

I don't know, just brainstorming.  I'll defer to John on the worthiness of any 
of these alternatives.  It's just that it seems to me the purpose of these 
other integer types might be for simulating the behavior of imbedded algorithms 
which often do have these alternate behaviors.

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]