1 .file "reg_u_add.S"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "exception.h"
26 #include "fpu_asm.h"
27
28 .text
29 .align 2,144
30 .globl _reg_u_add
31 _reg_u_add:
32 pushl %ebp
33 movl %esp,%ebp
34
35 pushl %esi
36 pushl %edi
37 pushl %ebx
38
39 movl PARAM1,%esi
40 movl PARAM2,%edi
41
42 xorl %ecx,%ecx
43 movl EXP(%esi),%ecx
44 subl EXP(%edi),%ecx
45
46 jge L_arg1_larger
47
48
49 movl SIGL(%esi),%ebx
50 movl SIGH(%esi),%eax
51
52 movl %edi,%esi
53 negw %cx
54 jmp L_accum_loaded
55
56 L_arg1_larger:
57
58 movl SIGL(%edi),%ebx
59 movl SIGH(%edi),%eax
60
61 L_accum_loaded:
62 movl 16(%ebp),%edi
63
64 movl EXP(%esi),%edx
65 movl %edx,EXP(%edi)
66
67 xorl %edx,%edx
68
69 #ifdef PARANOID
70 testl $0x80000000,%eax
71 je L_bugged
72
73 testl $0x80000000,SIGH(%esi)
74 je L_bugged
75 #endif PARANOID
76
77 cmpw $32,%cx
78 jnc L_more_than_31
79
80
81 shrd %cl,%ebx,%edx
82 shrd %cl,%eax,%ebx
83 shr %cl,%eax
84 jmp L_shift_done
85
86 L_more_than_31:
87 cmpw $64,%cx
88 jnc L_more_than_63
89
90 subb $32,%cl
91 shrd %cl,%eax,%edx
92 shr %cl,%eax
93 movl %eax,%ebx
94 xorl %eax,%eax
95 jmp L_shift_done
96
97 L_more_than_63:
98 cmpw $66,%cx
99 jnc L_more_than_65
100
101 subb $64,%cl
102 movl %eax,%edx
103 shr %cl,%edx
104 xorl %ebx,%ebx
105 xorl %eax,%eax
106 jmp L_shift_done
107
108 L_more_than_65:
109
110 movw SIGN(%esi),%ax
111 movw %ax,SIGN(%edi)
112 movl SIGL(%esi),%eax
113 movl %eax,SIGL(%edi)
114 movl SIGH(%esi),%eax
115 movl %eax,SIGH(%edi)
116 jmp L_exit
117
118 L_shift_done:
119
120 addl SIGL(%esi),%ebx
121 adcl SIGH(%esi),%eax
122 jnc L_round_the_result
123
124
125 rcrl $1,%eax
126 rcrl $1,%ebx
127 rcrl $1,%edx
128
129 incl EXP(%edi)
130
131 L_round_the_result:
132
133 cmpl $0x80000000,%edx
134 jc L_no_round_up
135
136 jne L_do_round_up
137
138
139 testb $1,%ebx
140 jz L_no_round_up
141
142 L_do_round_up:
143 addl $1,%ebx
144 adcl $0,%eax
145 jnc L_no_round_up
146
147
148 rcrl $1,%eax
149 rcrl $1,%ebx
150 incl EXP(%edi)
151
152 L_no_round_up:
153
154 movl %eax,SIGH(%edi)
155 movl %ebx,SIGL(%edi)
156
157 movb TW_Valid,TAG(%edi)
158 movb SIGN(%esi),%al
159 movb %al,SIGN(%edi)
160
161
162 cmpl EXP_OVER,EXP(%edi)
163 jge L_overflow
164
165 L_exit:
166 popl %ebx
167 popl %edi
168 popl %esi
169 leave
170 ret
171
172
173 L_overflow:
174 push %edi
175 call _arith_overflow
176 pop %ebx
177 jmp L_exit
178
179
180 #ifdef PARANOID
181
182 L_bugged:
183 pushl EX_INTERNAL|0x201
184 call EXCEPTION
185 pop %ebx
186 jmp L_exit
187 #endif PARANOID