[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in n
From: |
Dan Sebald |
Subject: |
[Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction |
Date: |
Wed, 29 Aug 2018 17:44:17 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0 |
Follow-up Comment #31, bug #54572 (project octave):
Works here.
This __signbit() function. Wouldn't it give better chance of optimization as
an "inline"? Or am I missing something here in the fact that the
instantiation of the int64_t integer type uses "inline"?
Also, in C/C++ doesn't the standard ensure the following
// Returns 1 for negative number, 0 otherwise.
static T
__signbit (T x)
{
return (x < 0);
}
is sufficient (or perhaps a cast to T is needed. Sure the optimizing compiler
will probably figure that out have the same code, but still.
Also, the signum routine:
+verbatun+
static T
signum (T x)
{
// With modest optimizations, this will compile without a jump.
return ((x > 0) ? 1 : 0) - __signbit (x);
}
Why even call the __signbit routine? And garden-variety optimization would
still do two comparisons with the above, x > 0 and x < 0 because of the
subtraction operator. How about:
return ((x < 0) ? -1 : (x > 0));
which on average might cut the comparisons to 1.5. Or, one could make the
argument that the more prevalent case is someone having mostly x > 0, so
"return ((x > 0) ? 1 : (x == 0) ? 0 : -1)" would work. The thing about
avoiding the use of addition and subtraction is that sometimes the processor
could have an instruction that loads a value into a register where that value
is encoded as part of the instruction and not coming from a separate register
which would need an additional load.
Here's a changeset you can pick and choose from or disregard.
(file #44897)
_______________________________________________________
Additional Item Attachment:
File name: octave-inline_some_int_arithmetic-djs2018aug29.patch Size:3 KB
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?54572>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, (continued)
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/28
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Rik, 2018/08/28
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/28
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Rik, 2018/08/28
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, John W. Eaton, 2018/08/28
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/28
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Rik, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, John W. Eaton, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Rik, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction,
Dan Sebald <=
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, John W. Eaton, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, John W. Eaton, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, John W. Eaton, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/29
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/30
- [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction, Dan Sebald, 2018/08/30