Questions tagged [x87]

x87 is the legacy 80bit floating point subset of the x86 instruction set. It's obsoleted by SSE/SSE2 for float/double, but is still useful for 80bit extended precision. The 32bit x86 ABI also returns FP results in an x87 register. See the tag wiki for a tutorial link.

See the wiki for links, including the most useful one: http://www.ray.masmcode.com/tutorial/index.html.

249 questions
5
votes
2 answers

Finding the "discrete" difference between close floating point numbers

Suppose I have two floating point numbers, x and y, with their values being very close. There's a discrete number of floating point numbers representable on a computer, so we can enumerate them in increasing order: f_1, f_2, f_3, .... I wish to…
Szabolcs
  • 24,728
  • 9
  • 85
  • 174
5
votes
2 answers

Double vs Float80 speed in Swift

I've heard that the x87 FPU works with 80-bit floats, so even if I want to calculate using 64-bit numbers, it would calculate it with 80-bit and then convert it. But which is fastest in Swift on x86-64, Double or Float80 (when calculating…
SpilledMango
  • 575
  • 7
  • 25
5
votes
2 answers

How to decompile this x87 assembly calculation?

The program I'm reversing does simple multiplication between float number and 8 byte integer: section .data va: dt 1.4426950408889634074 vb: dd 0x42424242 dd 0x41414141 section .text global main main: fld tword[va] fmul qword[vb] …
MCan
  • 59
  • 2
5
votes
1 answer

Why does the 80x87 instruction set use a "stack-based" design?

Back when Intel first designed the 8087, why did they choose to organize the floating-point registers as a stack? What possible advantage could be gained from such a design? It seems much less flexible and harder to work with than allowing arbitrary…
Alex D
  • 29,755
  • 7
  • 80
  • 126
4
votes
2 answers

Disassembling an 'faddl' instruction

In my venture of coding a disassembler for the 32-bit Linux on x86 platform, I came across an issue. I saw the following opcode sequence when I disassembled a simple ELF-32 executable using objdump: dc 82 04 08 0d 00 faddl 0xd0804(%edx) But…
Hrishikesh Murali
  • 535
  • 3
  • 7
  • 16
4
votes
0 answers

Clang compiler (x86): 80 bit long double

I'm trying to use native 80 bit long double on x86 Windows platform. The GCC option -mlong-double-80 doesn't seem to work with clang. I tried clang -target i386-windows -mlong-double-80 -c -O3 "test.c" But the compiler shows me the error: clang:…
Listener
  • 91
  • 7
4
votes
2 answers

Why do x86 FP compares set CF like unsigned integers, instead of using signed conditions?

The following documentation is provided in the Intel Instruction Reference for the COMISD instruction: Compares the double-precision floating-point values in the low quadwords of operand 1 (first operand) and operand 2 (second operand), and…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
4
votes
2 answers

Instruction FYL2XP1

I'm wondering why the instruction FYL2XP1 on x86-architecture computes exactly the mathematical formula y · log2(x + 1). What's special with this formula?
MZ97
  • 142
  • 1
  • 14
4
votes
1 answer

x87 FPU computing e powered x, maybe with a Taylor series?

I am trying to compute the function e^x (x is a single-precision float) in x87. To achieve this I am using the Taylor-series (as a reminder: e^x = 1 + (x^1)/1! + (x^2)/2! + ... + (x^n)/n!) As I'm working with the x87, I can calculate all values in…
Maru
  • 41
  • 4
4
votes
1 answer

Operand type mismatch in x87 inline assembly in a Linux kernel module

I really want to use floating point arithmetic in a Linux kernel module, just for the heck of it. I don't want to do anything fancy, just use the x87 trig instructions and/or the sqrt instruction, then assign the result to a variable. That's about…
SUBmarinoff
  • 83
  • 1
  • 8
4
votes
1 answer

How to reproduce floating point cos(x)!=cos(x)

How to reproduce this behavior? https://isocpp.org/wiki/faq/newbie#floating-point-arith2 To be precise, in the following code, parameters x and y are equal; they can be equal to 1.0 or any other value. void foo(double x, double y) { double cos_x =…
userbb
  • 2,148
  • 5
  • 30
  • 53
4
votes
0 answers

FPU instructions that check precision

Using the fldcw instruction it's possible to change the precision of the FPU unit to 24 or more bits. However after doing some testing I'm starting to think that very few x87 operations are in fact using that setting. I haven't tested all operations…
Marladu
  • 545
  • 5
  • 11
4
votes
1 answer

Access floating-point return of assembly function

our course exercise asks us to create a delta = b2 - 4ac function in GNU assembly, and access it from C. Since this is a course about compilers, and not about assembly, the professor chose to only demonstrate integer capabilities, and expects an…
pouzzler
  • 1,800
  • 2
  • 20
  • 32
4
votes
2 answers

Signalling NaN was corrupted when returning from x86 function (flds/fstps of x87)

I have strange behaviour with x86 (32-bit) linux gcc. I generate signalling NaN using gcc's builtin __builtin_nansf(""), which generates 0x7fa00000. After returning this value from function as float, it is modified into 0x7fe00000. There is short…
osgx
  • 90,338
  • 53
  • 357
  • 513
4
votes
2 answers

Add a constant value to a xmm register in x86

How would I add 1 or 2 to the register xmm0 (double)? I can do it like this, but sure there must be an easier way: movsd xmm0, [ecx] xor eax, eax inc eax cvtsi2sd xmm1, eax addsd xmm0, xmm1 movsd [ecx], xmm0 Also would it be possible to do this…
Tyilo
  • 28,998
  • 40
  • 113
  • 198
1 2
3
16 17