473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

subnormal floating point numbers

Hi all,
first of all I beg your pardon if this question has been asked
before, but I was unable to find anything in the past posts.
I have written a piece of code that was supposed to be quite portable,
and uses a lot fp numbers. Everything goes well on PPC cpus, but on
some x86 CPU I get a dramatic loss of performance. After some
investigations I've discovered that the problem is caused by some
numbers becoming subnormal, PPC cpus seems to treat them quietly
without any significant loss of speed whereas on some x86 CPU I get
really very poor results as soon as these "strange" entities begin to
pop out...
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs? I don't need them and
for me it will be just ok to have a small quantity dropped to zero -
in fact, the code is written assuming implicitly that very small
number will eventually become zero.
I hope that there is a simple solution for the problem, apart from
reviewing any very single line of code and putting a lot of
if(issubnormal...) or whatever else...

Thanx in advance to everybody that can/will help me...

May 15 '07 #1
5 3676
On May 15, 3:27 pm, ultimatewarrior <ultimatecodewarr...@yahoo.it>
wrote:
first of all I beg your pardon if this question has been asked
before, but I was unable to find anything in the past posts.
I have written a piece of code that was supposed to be quite portable,
and uses a lot fp numbers. Everything goes well on PPC cpus, but on
some x86 CPU I get a dramatic loss of performance. After some
investigations I've discovered that the problem is caused by some
numbers becoming subnormal, PPC cpus seems to treat them quietly
without any significant loss of speed whereas on some x86 CPU I get
really very poor results as soon as these "strange" entities begin to
pop out...
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs? I don't need them and
for me it will be just ok to have a small quantity dropped to zero -
in fact, the code is written assuming implicitly that very small
number will eventually become zero.
I hope that there is a simple solution for the problem, apart from
reviewing any very single line of code and putting a lot of
if(issubnormal...) or whatever else...
I don't believe there is anything standard to effect this. I think
you're looking for a compiler switch (e.g., -fn on Sun C++). You
should ask in a group related to your compiler.

Cheers! --M

May 15 '07 #2
ultimatewarrior wrote:
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs?
Just assigning the subnormal to a double variable should force it to 0.

---
Walter Bright
Digital Mars C, C++, D programming language compilers
May 16 '07 #3
Walter Bright wrote:
ultimatewarrior wrote:
>Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs?

Just assigning the subnormal to a double variable should force it to 0.
If the subnormal doesn't propagate, this wouldn't solve the problem,
would it?

Regards,

Zeppe
May 16 '07 #4
On 16 Mag, 11:57, Zeppe <zeppe@.remove.all.this.long.comment.email.it>
wrote:
Walter Bright wrote:
ultimatewarrior wrote:
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs?
Just assigning the subnormal to a double variable should force it to 0.

If the subnormal doesn't propagate, this wouldn't solve the problem,
would it?
Well, I guess no. And I cannot change every bit of code in order to
replace any assignement from float to double.

I've probably found a workaround, anyway, using SSE instead of
standard FPU you can control (through the MXCSR register) how to deal
with subnormal numbers, you can instruct the CPU to treat them as
zeros (exactly what I need), unfortunately you need SSE because the
x87 FPU has no control over this (ok, SSE is there from PIII and
AthlonXP so I think I'll drop support for older CPUs...)

Has someone any experience with issues regarding the use of SSE for
floats (instead of the standard FPU)?

(BTW, thanx for your kind answers!)

May 16 '07 #5
"ultimatewarrior" <ul*****************@yahoo.itwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi all,
first of all I beg your pardon if this question has been asked
before, but I was unable to find anything in the past posts.
I have written a piece of code that was supposed to be quite portable,
and uses a lot fp numbers. Everything goes well on PPC cpus, but on
some x86 CPU I get a dramatic loss of performance. After some
investigations I've discovered that the problem is caused by some
numbers becoming subnormal, PPC cpus seems to treat them quietly
without any significant loss of speed whereas on some x86 CPU I get
really very poor results as soon as these "strange" entities begin to
pop out...
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs? I don't need them and
for me it will be just ok to have a small quantity dropped to zero -
in fact, the code is written assuming implicitly that very small
number will eventually become zero.
I hope that there is a simple solution for the problem, apart from
reviewing any very single line of code and putting a lot of
if(issubnormal...) or whatever else...

Thanx in advance to everybody that can/will help me...
Reading other responses, and your responses to their responses, perhaps you
should use double instead of float. My understanding is that double is
faster than float anyway on (most/all) platforms. It also seems this might
get rid of your subnormal problems. Especially since performance seems to
be an issue it seems like the right thing to do.
May 17 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a...
4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
31
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms....
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
10
by: Shawn | last post by:
Hello all, I apologize as I am sure this has probably been dealth with before... but I am doing an exercise from "Practical C Programming" and I have been unable to get it to work perfectly due to...
7
by: Vinoth | last post by:
I'm working in an ARM (ARM9) system which does not have Floating point co-processor or Floating point libraries. But it does support long long int (64 bits). Can you provide some link that would...
15
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this...
32
by: ma740988 | last post by:
template <class T> inline bool isEqual( const T& a, const T& b, const T epsilon = std::numeric_limits<T>::epsilon() ) { const T diff = a - b; return ( diff <= epsilon ) && ( diff >= -epsilon );...
23
by: ultimatewarrior | last post by:
Hi all, first of all I beg your pardon if this question has been asked before, but I was unable to find anything in the past posts. I have written a piece of code that was supposed to be quite...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.