public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113365] New: LONG DOUBLE: denormals: assigning a constant: factor 100 slow,
@ 2024-01-12 23:38 newbie-02 at gmx dot de
  2024-01-12 23:40 ` [Bug target/113365] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: newbie-02 at gmx dot de @ 2024-01-12 23:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113365

            Bug ID: 113365
           Summary: LONG DOUBLE: denormals: assigning a constant: factor
                    100 slow,
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: newbie-02 at gmx dot de
  Target Milestone: ---

Created attachment 57062
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57062&action=edit
Snippet demonstrating the problem.

Filed that at 'sourceware', and they responded 'likely gcc'. 

See subject, assigning 3.3E-4932 to a variable takes 100 times longer than
3.4E-4932. 

Boiled it into the attached file which here produces the following output: 

````  
Assigning a long double denormal constant to a long double variable seems very
slow: 
The '+ ( argc - 1 )' part is an attempt to block compiler cheating by compile
time assigning. 
First column is the time used for 1000000 iterations. Factor ~100 looks odd to
me. 
0.231966; 3.6451995318824746025284E-4951; x2l = ( LDBL_MIN_DEN + ( argc - 1 ) ) 
0.002198; 3.5000000000000000001381E-4932; x2l = ( 3.5e-4932l + ( argc - 1 ) ) 
0.002153; 3.4000000000000000000716E-4932; x2l = ( 3.4e-4932l + ( argc - 1 ) ) 
0.002115; 3.3621031431120935062627E-4932; x2l = ( 3.3621031431120935063E-4932l
+ ( argc - 1 ) ) 
Note the break here, above are 'normal, below 'denormal' values. 
0.209994; 3.3621031431120935058982E-4932; x2l = ( 3.362103143112093506E-4932l +
( argc - 1 ) ) 
0.207378; 3.3000000000000000000052E-4932; x2l = ( 3.3e-4932l + ( argc - 1 ) ) 
0.205288; 3.1999999999999999999388E-4932; x2l = ( 3.2e-4932l + ( argc - 1 ) ) 

Not observed without the '+ ( argc - 1 )' part, assume compiler cheating. 
0.002090; 3.6451995318824746025284E-4951; x2l = ( LDBL_MIN_DEN ) 
0.001863; 3.5000000000000000001381E-4932; x2l = ( 3.5e-4932l ) 
0.001814; 3.4000000000000000000716E-4932; x2l = ( 3.4e-4932l ) 
0.001865; 3.3621031431120935062627E-4932; x2l = ( 3.3621031431120935063E-4932l
) 
0.001811; 3.3621031431120935058982E-4932; x2l = ( 3.362103143112093506E-4932l ) 
0.001868; 3.3000000000000000000052E-4932; x2l = ( 3.3e-4932l ) 
0.001926; 3.1999999999999999999388E-4932; x2l = ( 3.2e-4932l ) 

Not observed when assigning long double values around double normal / denormal
break. 
0.063401; 4.9406564584124654417657E-324; x2l = ( DBL_MIN_DEN + ( argc - 1 ) ) 
0.002173; 2.3999999999999999999368E-308; x2l = ( 2.4e-308l + ( argc - 1 ) ) 
0.002116; 2.3000000000000000000299E-308; x2l = ( 2.3e-308l + ( argc - 1 ) ) 
0.002124; 2.2250738585072013999772E-308; x2l = ( 2.2250738585072014E-308l + (
argc - 1 ) ) 
0.002272; 2.2250738585072009999964E-308; x2l = ( 2.225073858507201E-308l + (
argc - 1 ) ) 
0.002590; 2.2000000000000000000024E-308; x2l = ( 2.2e-308l + ( argc - 1 ) ) 
0.002082; 2.0999999999999999999749E-308; x2l = ( 2.1e-308l + ( argc - 1 ) ) 

But! affecting evaluation of denormal double constants! Here penalty factor
'only' ~30. 
0.062303; 4.9406564584124654417657E-324; x2l = ( DBL_MIN_DEN + ( argc - 1 ) ) 
0.002470; 2.4000000000000000788233E-308; x2l = ( 2.4e-308 + ( argc - 1 ) ) 
0.002405; 2.2999999999999998902644E-308; x2l = ( 2.3e-308 + ( argc - 1 ) ) 
0.002234; 2.2250738585072013830902E-308; x2l = ( 2.2250738585072014E-308 + (
argc - 1 ) ) 
0.063479; 2.2250738585072008890246E-308; x2l = ( 2.225073858507201E-308 + (
argc - 1 ) ) 
0.062954; 2.2000000000000001957711E-308; x2l = ( 2.2e-308 + ( argc - 1 ) ) 
0.062987; 2.1000000000000000072122E-308; x2l = ( 2.1e-308 + ( argc - 1 ) ) 

No such problem when assigning to double variable. 
0.001588; 4.940656458412465442E-324; x2d = ( DBL_MIN_DEN + ( argc - 1 ) ) 
0.001528; 2.400000000000000079E-308; x2d = ( 2.4e-308 + ( argc - 1 ) ) 
0.001557; 2.299999999999999890E-308; x2d = ( 2.3e-308 + ( argc - 1 ) ) 
0.001582; 2.225073858507201383E-308; x2d = ( 2.2250738585072014E-308 + ( argc -
1 ) ) 
0.001528; 2.225073858507200889E-308; x2d = ( 2.225073858507201E-308 + ( argc -
1 ) ) 
0.001544; 2.200000000000000196E-308; x2d = ( 2.2e-308 + ( argc - 1 ) ) 
0.001483; 2.100000000000000007E-308; x2d = ( 2.1e-308 + ( argc - 1 ) ) 

Can't tell if hardware, compiler, library whatever. 
Assume evaluation of constant when read. 
````

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/113365] LONG DOUBLE: denormals: assigning a constant: factor 100 slow,
  2024-01-12 23:38 [Bug c/113365] New: LONG DOUBLE: denormals: assigning a constant: factor 100 slow, newbie-02 at gmx dot de
@ 2024-01-12 23:40 ` pinskia at gcc dot gnu.org
  2024-01-12 23:50 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-12 23:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113365

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Likely x87 being slow for subnormals.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/113365] LONG DOUBLE: denormals: assigning a constant: factor 100 slow,
  2024-01-12 23:38 [Bug c/113365] New: LONG DOUBLE: denormals: assigning a constant: factor 100 slow, newbie-02 at gmx dot de
  2024-01-12 23:40 ` [Bug target/113365] " pinskia at gcc dot gnu.org
@ 2024-01-12 23:50 ` pinskia at gcc dot gnu.org
  2024-01-13  0:11 ` newbie-02 at gmx dot de
  2024-01-15 15:22 ` newbie-02 at gmx dot de
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-12 23:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113365

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
At -O0, GCC produces a lot of load/stores to the stack and subnormals always
have a penality in HW for x87.

Note double uses SSE while long double uses x87 so the effect there will show
up more.

Note if we use -O2 and change the variable to be a volatile variable (otherwise
the loop is just optimized away), the speed difference is gone because you no
longer have addition happening of a subnormal which is what is causing the slow
down.


Anyways as I mentioned this is not a GCC bug but rather a HW limitation. 

There are many other targets where subnormals are slow even for double too.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/113365] LONG DOUBLE: denormals: assigning a constant: factor 100 slow,
  2024-01-12 23:38 [Bug c/113365] New: LONG DOUBLE: denormals: assigning a constant: factor 100 slow, newbie-02 at gmx dot de
  2024-01-12 23:40 ` [Bug target/113365] " pinskia at gcc dot gnu.org
  2024-01-12 23:50 ` pinskia at gcc dot gnu.org
@ 2024-01-13  0:11 ` newbie-02 at gmx dot de
  2024-01-15 15:22 ` newbie-02 at gmx dot de
  3 siblings, 0 replies; 5+ messages in thread
From: newbie-02 at gmx dot de @ 2024-01-13  0:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113365

--- Comment #3 from newbie-02 <newbie-02 at gmx dot de> ---
hi, thank you, super service, super fast, works!  

can't tell if the -O0 behaviour is meaningful ...  
but think it is rarely used. I came to it in my  
attempts to avoid compiler cheating / optimizing.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/113365] LONG DOUBLE: denormals: assigning a constant: factor 100 slow,
  2024-01-12 23:38 [Bug c/113365] New: LONG DOUBLE: denormals: assigning a constant: factor 100 slow, newbie-02 at gmx dot de
                   ` (2 preceding siblings ...)
  2024-01-13  0:11 ` newbie-02 at gmx dot de
@ 2024-01-15 15:22 ` newbie-02 at gmx dot de
  3 siblings, 0 replies; 5+ messages in thread
From: newbie-02 at gmx dot de @ 2024-01-15 15:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113365

--- Comment #4 from newbie-02 <newbie-02 at gmx dot de> ---
hello @Andrew Pinski,   

just if I'm allowed to add one more point / question:  

using the testing program, playing with optimization, I get  
the following results for binary64s ( doubles ):  

unoptimized:  
time:     result:                    calculation:  
0.005571; 4.940656458412465442E-324; x2d = nextafter( 1E-323, 0.0 ) 
0.002029; 4.940656458412465442E-324; x2d = ( ( 1E-323 ) - 5E-324 ) 
0.005395; 1.482196937523739633E-323; x2d = nextafter( 1E-323, 1.0 ) 
0.002023; 1.482196937523739633E-323; x2d = ( ( 1E-323 ) + 5E-324 ) 
which points out that addition / subtraction are faster in denormals,  
or assignd at compile time despite x2d is defined volatile.  

optimized ( compiled with -O2 ): I mostly! get understandable results,  
( nextafter similar and ADD / SUB faster reg, compiler cheating?,  
but on some occasions ( ~10% of compile attempts ):  
time:     result:                    calculation:  
0.009311; 4.940656458412465442E-324; x2d = nextafter( 1E-323, 0.0 ) 
0.000420; 4.940656458412465442E-324; x2d = ( ( 1E-323 ) - 5E-324 ) 
0.009668; 1.482196937523739633E-323; x2d = nextafter( 1E-323, 1.0 ) 
0.000423; 1.482196937523739633E-323; x2d = ( ( 1E-323 ) + 5E-324 ) 
which has ** ~doubled execution time for nextafters **.  

Is that something I should worry about? Somthing which could be improved?  
Either here by options or in gcc?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-15 15:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-12 23:38 [Bug c/113365] New: LONG DOUBLE: denormals: assigning a constant: factor 100 slow, newbie-02 at gmx dot de
2024-01-12 23:40 ` [Bug target/113365] " pinskia at gcc dot gnu.org
2024-01-12 23:50 ` pinskia at gcc dot gnu.org
2024-01-13  0:11 ` newbie-02 at gmx dot de
2024-01-15 15:22 ` newbie-02 at gmx dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).