summaryrefslogtreecommitdiffstats
path: root/private/ntos/dll/i386/emfconst.asm
blob: 210cccf65f49a87ceb963fc8d245c5474d091535 (plain) (blame)
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
	subttl	emfconst.asm - Loading of 387 on chip constants
        page
;*******************************************************************************
;emfconst.asm - Loading of 387 on chip constants
;
;        Microsoft Confidential
;
;	 Copyright (c) Microsoft Corporation 1991
;        All Rights Reserved
;
;Purpose:
;       FLDZ, FLD1, FLDPI, FLDL2T, FLDL2E, FLDLG2, FLDLN2 instructions
;Inputs:
;	edi = [CURstk]
;
;Revision History:
;
; []	09/05/91  TP	Initial 32-bit version.
;
;*******************************************************************************


	PrevStackWrap	edi,Ld1		;Tied to PrevStackElem below

EM_ENTRY eFLD1
eFLD1:
;edi = [CURstk]
	PrevStackElem	edi,Ld1		;Point to receiving location
	cmp	EMSEG:[edi].bTag,bTAG_EMPTY	;Is it empty?
	jnz	FldErr			;in emload.asm
	mov	EMSEG:[CURstk],edi
	mov	EMSEG:[edi].lManLo,0
	mov	EMSEG:[edi].lManHi,1 shl 31
	mov	EMSEG:[edi].ExpSgn,bTAG_SNGL	;Exponent and sign are zero
	ret


	PrevStackWrap	edi,Ldz		;Tied to PrevStackElem below

EM_ENTRY eFLDZ
eFLDZ:
;edi = [CURstk]
	PrevStackElem	edi,Ldz		;Point to receiving location
	cmp	EMSEG:[edi].bTag,bTAG_EMPTY	;Is it empty?
	jnz	FldErr			;in emload.asm
	mov	EMSEG:[CURstk],edi
	mov	EMSEG:[edi].lManLo,0
	mov	EMSEG:[edi].lManHi,0
	mov	EMSEG:[edi].ExpSgn,bTAG_ZERO	;Exponent and sign are zero
	ret

;*******************************************************************************

;The 5 irrational constants need to be adjusted according to rounding mode.

DefConst	macro	cName,low,high,expon,round
c&cName&lo	equ	low
c&cName&hi	equ	high
c&cName&exp     equ     expon
c&cName&rnd     equ     round
	endm

DefConst	FLDL2T,0CD1B8AFEH,0D49A784BH,00001H,0

DefConst	FLDL2E,05C17F0BCH,0B8AA3B29H,00000H,1

DefConst	FLDLG2,0FBCFF799H,09A209A84H,0FFFEH,1

DefConst	FLDLN2,0D1CF79ACH,0B17217F7H,0FFFFH,1

DefConst	FLDPI,02168C235H,0C90FDAA2H,00001H,1


LoadConstant   macro   cName,nojmp
EM_ENTRY e&cName
e&cName:
	mov	ebx,c&cName&hi
	mov	edx,c&cName&lo
        mov     ecx,c&cName&exp shl 16 + c&cName&rnd
ifb	<nojmp>
	jmp	CommonConst
endif
	endm

LoadConstant	FLDL2T

LoadConstant	FLDL2E

LoadConstant	FLDLG2

LoadConstant	FLDLN2

LoadConstant	FLDPI,nojmp

CommonConst:
;ebx:edx = mantissa of constant, rounded to nearest
;high ecx = exponent 
;ch = sign
;cl = rounding flag: 1 indicates roundup occured for round nearest, else 0
;edi = [CURstk]
	test	EMSEG:[CWcntl],RoundControl	;Check rounding control bits
.erre	RCnear eq 0
	jnz	NotNearConst		;Adjust constant if not round nearest
StoreConst:
	mov	cl,bTAG_VALID
	mov	esi,edx
	jmp	FldCont			;In emload.asm

NotNearConst:
;It is known that the five constants positive irrational numbers.
;This means they are never exact, and chop and round down always
;produce the same answer.  It is also know that the values are such
;that rounding only alters bits in the last byte.
;
;A flag in cl indicates if the number has been rounded up for round
;nearest (1 = rounded up, 0 = rounded down).  In chop and round down 
;modes, this flag can be directly subtracted to reverse the rounding.  
;In round up mode, we want to add (1-flag) = -(flag-1).
.erre	RCchop eq 0CH			;Two bits set only for chop
	test	EMSEG:[CWcntl],RCdown	;DOWN bit set?
	jnz	DirectRoundConst	;If so, it's chop or down
;Round Up mode
	dec	cl			;-1 if round up needed, else 0
DirectRoundConst:
	sub	dl,cl			;Directed rounding
	jmp	StoreConst