GIMP Forums » For GEGL developers
use of bitwise arithmetic in GEGL code
Jump to message:
-
use of bitwise... —
Nicolas Robidoux,
06 Aug 2009 09:00 PM
- use of bitwise... — Martin Nordholts, 06 Aug 2009 09:03 PM
-
use of bitwise... —
Martin Nordholts,
06 Aug 2009 09:23 PM
-
use of bitwise... —
Nicolas Robidoux,
06 Aug 2009 10:02 PM
-
use of bitwise... —
Martin Nordholts,
06 Aug 2009 10:20 PM
- use of bitwise... — Nicolas Robidoux, 06 Aug 2009 10:39 PM
-
use of bitwise... —
Martin Nordholts,
06 Aug 2009 10:20 PM
-
use of bitwise... —
Nicolas Robidoux,
06 Aug 2009 10:02 PM
-
use of bitwise... —
Nathan Summers,
06 Aug 2009 10:34 PM
- use of bitwise... — Nicolas Robidoux, 08 Aug 2009 03:31 PM
As a registered user, you can subscribe forum threads in order to get notified when replies are posted. Just log in at the right top of the page if you already have an account, otherwise you can register for free.
| Permalink: | 19067.10315.408349.597759@gargle.garg... |
|---|---|
| Date: | 06 Aug 2009 09:00 PM |
| From: | Nicolas Robidoux |
| Subject: | use of bitwise arithmetic in GEGL code |
Is the use of such tricks discouraged for GEGL (because gfloats could
be doubles at some point?)
We can take the absolute value by setting the sign bit to zero:
// Example 13.24
float f;
*(int*)&f &= 0x7FFFFFFF; // set sign bit to zero
(From http://www.agner.org/optimize/optimizing_cpp.pdf)
Nicolas Robidoux
Universite Laurentienne
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
| Permalink: | 4A7B2993.3000002@gmail.com |
|---|---|
| Date: | 06 Aug 2009 09:03 PM |
| From: | Martin Nordholts |
| Subject: | use of bitwise arithmetic in GEGL code |
On 08/06/2009 09:00 PM, Nicolas Robidoux wrote:
> Is the use of such tricks discouraged for GEGL (because gfloats could
> be doubles at some point?)
>
> We can take the absolute value by setting the sign bit to zero:
> // Example 13.24
> float f;
> *(int*)&f&= 0x7FFFFFFF; // set sign bit to zero
Why not use standard library functions?
/ Martin
> Is the use of such tricks discouraged for GEGL (because gfloats could
> be doubles at some point?)
>
> We can take the absolute value by setting the sign bit to zero:
> // Example 13.24
> float f;
> *(int*)&f&= 0x7FFFFFFF; // set sign bit to zero
Why not use standard library functions?
/ Martin
--
My GIMP Blog:
http://www.chromecode.com/
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
My GIMP Blog:
http://www.chromecode.com/
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
| Permalink: | 4A7B2E5E.7060405@gmail.com |
|---|---|
| Date: | 06 Aug 2009 09:23 PM |
| From: | Martin Nordholts |
| Subject: | use of bitwise arithmetic in GEGL code |
On 08/06/2009 09:00 PM, Nicolas Robidoux wrote:
> Is the use of such tricks discouraged for GEGL (because gfloats could
> be doubles at some point?)
>
> We can take the absolute value by setting the sign bit to zero:
> // Example 13.24
> float f;
> *(int*)&f&= 0x7FFFFFFF; // set sign bit to zero
>
> (From http://www.agner.org/optimize/optimizing_cpp.pdf)
It was an interesting paper, but I doubt that the gained speed in
execution performance outweights the messier code. Plus, his example was
to set the sign bit, i.e. x = -abs(x). Maybe x = abs(x) is equal to the
above for optimizing compilers
/ Martin
> Is the use of such tricks discouraged for GEGL (because gfloats could
> be doubles at some point?)
>
> We can take the absolute value by setting the sign bit to zero:
> // Example 13.24
> float f;
> *(int*)&f&= 0x7FFFFFFF; // set sign bit to zero
>
> (From http://www.agner.org/optimize/optimizing_cpp.pdf)
It was an interesting paper, but I doubt that the gained speed in
execution performance outweights the messier code. Plus, his example was
to set the sign bit, i.e. x = -abs(x). Maybe x = abs(x) is equal to the
above for optimizing compilers
/ Martin
--
My GIMP Blog:
http://www.chromecode.com/
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
My GIMP Blog:
http://www.chromecode.com/
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
| Permalink: | 19067.14014.520839.243232@gargle.garg... |
|---|---|
| Date: | 06 Aug 2009 10:02 PM |
| From: | Nicolas Robidoux |
| Subject: | use of bitwise arithmetic in GEGL code |
Michael:
> I doubt that the gained speed in execution performance outweights
> the messier code.
The bit twiddling absolute value was just an example. It's a
branch-free float minmod we're actually after.
Do I gather that it may be OK to use such bit twiddling provided the
speed gain is sufficient to justify code opacity?
Nicolas Robidoux
PS
Really, vector operations are where speed is to be found. But
implementation is a bit more involved than the occasional bit twiddle.
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
| Permalink: | 4A7B3B8B.8000203@gmail.com |
|---|---|
| Date: | 06 Aug 2009 10:20 PM |
| From: | Martin Nordholts |
| Subject: | use of bitwise arithmetic in GEGL code |
On 08/06/2009 10:02 PM, Nicolas Robidoux wrote:
> Michael:
>
>> I doubt that the gained speed in execution performance outweights
>> the messier code.
>
> The bit twiddling absolute value was just an example. It's a
> branch-free float minmod we're actually after.
>
> Do I gather that it may be OK to use such bit twiddling provided the
> speed gain is sufficient to justify code opacity?
If the code is unlikely to require changes later, then I'm fine with
these kind of optimizations
/ Martin
> Michael:
>
>> I doubt that the gained speed in execution performance outweights
>> the messier code.
>
> The bit twiddling absolute value was just an example. It's a
> branch-free float minmod we're actually after.
>
> Do I gather that it may be OK to use such bit twiddling provided the
> speed gain is sufficient to justify code opacity?
If the code is unlikely to require changes later, then I'm fine with
these kind of optimizations
/ Martin
--
My GIMP Blog:
http://www.chromecode.com/
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
My GIMP Blog:
http://www.chromecode.com/
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
| Permalink: | 19067.16237.657075.17154@gargle.gargl... |
|---|---|
| Date: | 06 Aug 2009 10:39 PM |
| From: | Nicolas Robidoux |
| Subject: | use of bitwise arithmetic in GEGL code |
Ralf Meyer (another Laurentian prof) did some quick and dirty
experimentation with preliminary versions of bit-twiddling minmods and
found that on PowerPC chips it made a big difference. Not on Intel.
Not really surprising: Avoiding branches like the plague is more
relevant to PowerPC/cell than Intel.
In GEGL (production) code? Not sure.
Nicolas Robidoux
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
| Permalink: | 955afe440908061334u312db558sa12a28f5a... |
|---|---|
| Date: | 06 Aug 2009 10:34 PM |
| From: | Nathan Summers |
| Subject: | use of bitwise arithmetic in GEGL code |
On Thu, Aug 6, 2009 at 3:00 PM, Nicolas Robidoux
<nrobidoux@cs.laurentian.ca> wrote:
>
> Is the use of such tricks discouraged for GEGL (because gfloats could
> be doubles at some point?)
>
> We can take the absolute value by setting the sign bit to zero:
> // Example 13.24
> float f;
> *(int*)&f &= 0x7FFFFFFF; // set sign bit to zero
Doesn't this violate pointer aliasing rules?
Rockwalrus
<nrobidoux@cs.laurentian.ca> wrote:
>
> Is the use of such tricks discouraged for GEGL (because gfloats could
> be doubles at some point?)
>
> We can take the absolute value by setting the sign bit to zero:
> // Example 13.24
> float f;
> *(int*)&f &= 0x7FFFFFFF; // set sign bit to zero
Doesn't this violate pointer aliasing rules?
Rockwalrus
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
| Permalink: | 19069.32300.398499.36090@gargle.gargl... |
|---|---|
| Date: | 08 Aug 2009 03:31 PM |
| From: | Nicolas Robidoux |
| Subject: | use of bitwise arithmetic in GEGL code |
Nathan Summers writes:
> On Thu, Aug 6, 2009 at 3:00 PM, Nicolas Robidoux wrote
> >
> > Is the use of such tricks discouraged for GEGL (because gfloats could
> > be doubles at some point?)
> >
> > We can take the absolute value by setting the sign bit to zero:
> > // Example 13.24
> > float f;
> > *(int*)&f &= 0x7FFFFFFF; // set sign bit to zero
>
> Doesn't this violate pointer aliasing rules?
Indeed.
Consequence of your observation: The next edition of Agner Fog's
online optimization manuals
http://www.agner.org/optimize/#manuals
will contain an updated version of the above example:
union {
float f;
int i;
} u;
u.i &= 0x7FFFFFFF; // set sign bit to zero
and the following caveat:
In general, it is faster to access a floating point variable as an
integer if it is stored in memory, but not if it is a register
variable. The union forces the variable to be stored in memory, at
least temporarily. Using the methods in the above examples will
therefore be a disadvantage if other nearby parts of the code could
benefit from using registers for the same variables. Using type
casting of pointers instead of unions in the above examples may not
work on compilers that rely on the strict aliasing rule of standard
C, specifying that pointers of different types cannot point to the
same object, except for char pointers.
Nicolas Robidoux
Laurentian University
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer


