-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain113.cpp
117 lines (102 loc) · 2.08 KB
/
main113.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
using namespace std;
// g++ -m64 -o main113.o -c main113.cpp && g++ -m64 main113.o -o zad113 && ./zad113
#include <iostream>
class Przedzial {
public:
double low;
double high;
Przedzial(double l, double h) {
this->low = l;
this->high = h;
}
friend const Przedzial operator+(const Przedzial& l, const Przedzial& r);
friend const Przedzial operator-(const Przedzial& l, const Przedzial& r);
};
const Przedzial operator +(const Przedzial& l, const Przedzial& r) {
Przedzial tmp(l.low, l.high);
int c = 0;
asm("myfunc:;"
"fldl (%1);"
"fldl (%2);"
"faddp;"
"fstcw %3;"
"movw %3, %%ax;"
"andw $0xf3ff, %%ax;"
"orw $0x0400, %%ax;"
"push %%rax;"
"fldcw (%%rsp);"
"fstpl (%0);"
"fldcw %3;"
"pop %%rax;"
"addq $8, %1;"
"addq $8, %2;"
"addq $8, %0;"
"fldl (%1);"
"fldl (%2);"
"faddp;"
"fstcw %3;"
"movw %3, %%ax;"
"andw $0xf3ff, %%ax;"
"orw $0x800, %%ax;"
"push %%rax;"
"fldcw (%%rsp);"
"fstpl (%0);"
"fldcw %3;"
"pop %%rax;"
:
:"r"(&tmp), "r"(&l), "r"(&r), "m"(c)
:"rax"
);
return tmp;
}
const Przedzial operator -(const Przedzial& l, const Przedzial& r) {
Przedzial tmp(l.low, l.high);
int c = 0;
asm("myfunc1:;"
"fldl (%2);"
"fldl (%1);"
"fsubp;"
"fstcw %3;"
"movw %3, %%ax;"
"andw $0xf3ff, %%ax;"
"orw $0x0400, %%ax;"
"push %%rax;"
"fldcw (%%rsp);"
"fstpl (%0);"
"fldcw %3;"
"pop %%rax;"
"addq $8, %1;"
"addq $8, %2;"
"addq $8, %0;"
"fldl (%2);"
"fldl (%1);"
"fsubp;"
"fstcw %3;"
"movw %3, %%ax;"
"andw $0xf3ff, %%ax;"
"orw $0x800, %%ax;"
"push %%rax;"
"fldcw (%%rsp);"
"fstpl (%0);"
"fldcw %3;"
"pop %%rax;"
:
:"r"(&tmp), "r"(&l), "r"(&r), "m"(c)
:"rax"
);
return tmp;
}
int main() {
Przedzial p1(20, 30);
Przedzial p2(-0.0001, 0.0001);
Przedzial sum = p1+p2;
cout << p1.low << ", " << p1.high << " + "
<< p2.low << ", " << p2.high << " = "
<< sum.low << ", " << sum.high << endl;
Przedzial diff = p2-p1;
cout << p2.low << ", " << p2.high << " - "
<< p1.low << ", " << p1.high << " = "
<< diff.low << ", " << diff.high << endl;
return 0;
}