summaryrefslogtreecommitdiffstats
path: root/arch/m68k/fpsp040/decbin.S
blob: 16ed796bad87f375b98e21e5804aa375c4648858 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
|
|	decbin.sa 3.3 12/19/90
|
|	Description: Converts normalized packed bcd value pointed to by
|	register A6 to extended-precision value in FP0.
|
|	Input: Normalized packed bcd value in ETEMP(a6).
|
|	Output:	Exact floating-point representation of the packed bcd value.
|
|	Saves and Modifies: D2-D5
|
|	Speed: The program decbin takes ??? cycles to execute.
|
|	Object Size:
|
|	External Reference(s): None.
|
|	Algorithm:
|	Expected is a normal bcd (i.e. non-exceptional; all inf, zero,
|	and NaN operands are dispatched without entering this routine)
|	value in 68881/882 format at location ETEMP(A6).
|
|	A1.	Convert the bcd exponent to binary by successive adds and muls.
|	Set the sign according to SE. Subtract 16 to compensate
|	for the mantissa which is to be interpreted as 17 integer
|	digits, rather than 1 integer and 16 fraction digits.
|	Note: this operation can never overflow.
|
|	A2. Convert the bcd mantissa to binary by successive
|	adds and muls in FP0. Set the sign according to SM.
|	The mantissa digits will be converted with the decimal point
|	assumed following the least-significant digit.
|	Note: this operation can never overflow.
|
|	A3. Count the number of leading/trailing zeros in the
|	bcd string.  If SE is positive, count the leading zeros;
|	if negative, count the trailing zeros.  Set the adjusted
|	exponent equal to the exponent from A1 and the zero count
|	added if SM = 1 and subtracted if SM = 0.  Scale the
|	mantissa the equivalent of forcing in the bcd value:
|
|	SM = 0	a non-zero digit in the integer position
|	SM = 1	a non-zero digit in Mant0, lsd of the fraction
|
|	this will insure that any value, regardless of its
|	representation (ex. 0.1E2, 1E1, 10E0, 100E-1), is converted
|	consistently.
|
|	A4. Calculate the factor 10^exp in FP1 using a table of
|	10^(2^n) values.  To reduce the error in forming factors
|	greater than 10^27, a directed rounding scheme is used with
|	tables rounded to RN, RM, and RP, according to the table
|	in the comments of the pwrten section.
|
|	A5. Form the final binary number by scaling the mantissa by
|	the exponent factor.  This is done by multiplying the
|	mantissa in FP0 by the factor in FP1 if the adjusted
|	exponent sign is positive, and dividing FP0 by FP1 if
|	it is negative.
|
|	Clean up and return.  Check if the final mul or div resulted
|	in an inex2 exception.  If so, set inex1 in the fpsr and
|	check if the inex1 exception is enabled.  If so, set d7 upper
|	word to $0100.  This will signal unimp.sa that an enabled inex1
|	exception occurred.  Unimp will fix the stack.
|

|		Copyright (C) Motorola, Inc. 1990
|			All Rights Reserved
|
|       For details on the license for this file, please see the
|       file, README, in this same directory.

|DECBIN    idnt    2,1 | Motorola 040 Floating Point Software Package

	|section	8

#include "fpsp.h"

|
|	PTENRN, PTENRM, and PTENRP are arrays of powers of 10 rounded
|	to nearest, minus, and plus, respectively.  The tables include
|	10**{1,2,4,8,16,32,64,128,256,512,1024,2048,4096}.  No rounding
|	is required until the power is greater than 27, however, all
|	tables include the first 5 for ease of indexing.
|
	|xref	PTENRN
	|xref	PTENRM
	|xref	PTENRP

RTABLE:	.byte	0,0,0,0
	.byte	2,3,2,3
	.byte	2,3,3,2
	.byte	3,2,2,3

	.global	decbin
	.global	calc_e
	.global	pwrten
	.global	calc_m
	.global	norm
	.global	ap_st_z
	.global	ap_st_n
|
	.set	FNIBS,7
	.set	FSTRT,0
|
	.set	ESTRT,4
	.set	EDIGITS,2	|
|
| Constants in single precision
FZERO:	.long	0x00000000
FONE:	.long	0x3F800000
FTEN:	.long	0x41200000

	.set	TEN,10

|
decbin:
	| fmovel	#0,FPCR		;clr real fpcr
	moveml	%d2-%d5,-(%a7)
|
| Calculate exponent:
|  1. Copy bcd value in memory for use as a working copy.
|  2. Calculate absolute value of exponent in d1 by mul and add.
|  3. Correct for exponent sign.
|  4. Subtract 16 to compensate for interpreting the mant as all integer digits.
|     (i.e., all digits assumed left of the decimal point.)
|
| Register usage:
|
|  calc_e:
|	(*)  d0: temp digit storage
|	(*)  d1: accumulator for binary exponent
|	(*)  d2: digit count
|	(*)  d3: offset pointer
|	( )  d4: first word of bcd
|	( )  a0: pointer to working bcd value
|	( )  a6: pointer to original bcd value
|	(*)  FP_SCR1: working copy of original bcd value
|	(*)  L_SCR1: copy of original exponent word
|
calc_e:
	movel	#EDIGITS,%d2	|# of nibbles (digits) in fraction part
	moveql	#ESTRT,%d3	|counter to pick up digits
	leal	FP_SCR1(%a6),%a0	|load tmp bcd storage address
	movel	ETEMP(%a6),(%a0)	|save input bcd value
	movel	ETEMP_HI(%a6),4(%a0) |save words 2 and 3
	movel	ETEMP_LO(%a6),8(%a0) |and work with these
	movel	(%a0),%d4	|get first word of bcd
	clrl	%d1		|zero d1 for accumulator
e_gd:
	mulul	#TEN,%d1	|mul partial product by one digit place
	bfextu	%d4{%d3:#4},%d0	|get the digit and zero extend into d0
	addl	%d0,%d1		|d1 =