The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: AeroASM on February 20, 2005, 09:43:20 PM

Title: How to multiply 16 bit integer with 64 bit float?
Post by: AeroASM on February 20, 2005, 09:43:20 PM
I recently changed all my x87 code to SSE, except the following: I have a REAL8, which needs to be multiplied by a 16 bit integer.
The only way I can think to do this is:

fild my_integer
fmul my_float
fstp my_float


Is there a way to do this without the FPU?
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: raymond on February 21, 2005, 04:17:55 AM
You could always use the algorithms which were developed in the early days to emulate the x87. :eek

As you showed, using the FPU is very simple. Why don't you want to use the FPU???

Raymond
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: AeroASM on February 21, 2005, 07:53:10 AM
I wrote the whole program using the FPU, then I found out that the FPU is very slow, so I got rid of most of it and replaced it with SSE. I just don't want to rely on the FPU even for one little bit.
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: Mark_Larson on February 21, 2005, 03:36:13 PM

  You can use scalar SSE to do it.

Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: AeroASM on February 21, 2005, 06:26:46 PM
Will SSE recognize that one number is an integer and the other is a float?
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: raymond on February 21, 2005, 09:56:46 PM
Converting an integer to one of the float formats is quite easy with CPU instructions. If you have been using the FPU in the past, you must be aware of those formats. Ask if you need to go that route and need help.

Raymond
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: Mark_Larson on February 22, 2005, 01:47:33 AM
Quote from: AeroASM on February 21, 2005, 06:26:46 PM
Will SSE recognize that one number is an integer and the other is a float?

You can convert the integer to a float and then treat it like a float.

Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: AeroASM on February 22, 2005, 07:46:38 AM
How do I convert it?
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: raymond on February 22, 2005, 04:13:22 PM
Quote from: AeroASM on February 22, 2005, 07:46:38 AM
How do I convert it?

Look at the following description of the various floating point formats.

http://www.ray.masmcode.com/tutorial/fpuchap2.htm#floats

Once you understand it, try to convert an integer by yourself and compare it with the value which would be generated by your assembler. If you do succeed, you will remember how to do it for the rest of your life. If you need more help, I will be glad to provide it.

Raymond
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: AeroASM on February 22, 2005, 04:22:04 PM
Thanks, I have just had a brainwave.
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: Farabi on February 26, 2005, 05:28:52 AM
If I dont made mistake, mul instruction is more fast than the fmul and fimul instruction.
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: AeroASM on February 28, 2005, 07:10:47 AM
But mul doesn't work with floats, and I need to multiply an int by a float to get a float.
Title: Re: How to multiply 16 bit integer with 64 bit float?
Post by: hutch-- on February 28, 2005, 08:30:44 AM
Aero,

Rays suggestion is a good one, you can load the integer into a floating point register and do the rest using the other float value.