os/kernelhwsrv/kernel/eka/euser/epoc/win32/uc_realx.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\euser\epoc\win32\uc_realx.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "u32std.h"
sl@0
    19
#include <e32math.h>
sl@0
    20
sl@0
    21
#pragma warning (disable : 4100)	// unreferenced formal parameter
sl@0
    22
#pragma warning (disable : 4700)	// local variable 'this' used without
sl@0
    23
									// having been initialised
sl@0
    24
#pragma warning ( disable : 4414 )  // short jump to function converted to near
sl@0
    25
sl@0
    26
sl@0
    27
#if defined(__VC32__) && (_MSC_VER==1100)	// untested on MSVC++ > 5.0
sl@0
    28
// Workaround for MSVC++ 5.0 bug; MSVC incorrectly fixes up conditional jumps
sl@0
    29
// when the destination is a C++ function.
sl@0
    30
#define _ASM_j(cond,dest) _asm jn##cond short $+11 _asm jmp dest
sl@0
    31
#define _ASM_jn(cond,dest) _asm j##cond short $+11 _asm jmp dest
sl@0
    32
#pragma optimize( "", off )			// stop MSVC murdering the code
sl@0
    33
#else
sl@0
    34
#define _ASM_j(cond,dest) _asm j##cond dest
sl@0
    35
#define _ASM_jn(cond,dest) _asm jn##cond dest
sl@0
    36
#endif
sl@0
    37
sl@0
    38
//
sl@0
    39
// 64-bit precision floating point routines
sl@0
    40
// Register storage format:
sl@0
    41
// edx:ebx=64 bit normalised mantissa
sl@0
    42
// ecx bits 16-31 = 16-bit exponent, biased by 7FFF
sl@0
    43
// ecx bit 0 = sign
sl@0
    44
// ecx bit 8 = rounded-down flag
sl@0
    45
// ecx bit 9 = rounded-up flag
sl@0
    46
//
sl@0
    47
// Memory storage format:
sl@0
    48
// 3 doublewords per number
sl@0
    49
// Low 32 bits of mantissa at [addr]
sl@0
    50
// High 32 bits of mantissa at [addr+4]
sl@0
    51
// Exponent/flags/sign at [addr+8]
sl@0
    52
//
sl@0
    53
sl@0
    54
LOCAL_C void TRealXPanic(TInt aErr)
sl@0
    55
	{
sl@0
    56
	User::Panic(_L("MATHX"),aErr);
sl@0
    57
	}
sl@0
    58
sl@0
    59
__NAKED__ LOCAL_C void TRealXPanicEax(void)
sl@0
    60
	{
sl@0
    61
	_asm push eax
sl@0
    62
	_asm call TRealXPanic
sl@0
    63
	}
sl@0
    64
sl@0
    65
LOCAL_C __NAKED__ void TRealXRealIndefinite(void)
sl@0
    66
	{
sl@0
    67
	// return 'real indefinite' NaN in ecx,edx:ebx
sl@0
    68
	_asm mov ecx, 0xFFFF0001	// exponent=FFFF, sign negative
sl@0
    69
	_asm mov edx, 0xC0000000	// mantissa=C0000000 00000000
sl@0
    70
	_asm xor ebx, ebx
sl@0
    71
	_asm mov eax, -6			// return KErrArgument
sl@0
    72
	_asm ret
sl@0
    73
	}
sl@0
    74
sl@0
    75
LOCAL_C __NAKED__ void TRealXBinOpNaN(void)
sl@0
    76
	{
sl@0
    77
	// generic routine to process NaN's in binary operations
sl@0
    78
	// destination operand in ecx,edx:eax
sl@0
    79
	// source operand at [esi]
sl@0
    80
sl@0
    81
	_asm mov eax, [esi+8]		// source operand into eax,edi:ebp
sl@0
    82
	_asm mov edi, [esi+4]
sl@0
    83
	_asm mov ebp, [esi]
sl@0
    84
	_asm cmp ecx, 0xFFFF0000	// check if dest is a NaN
sl@0
    85
	_asm jb short TRealXBinOpNaN1	// if not, swap them
sl@0
    86
	_asm cmp edx, 0x80000000
sl@0
    87
	_asm jne short TRealXBinOpNaN2
sl@0
    88
	_asm test ebx, ebx
sl@0
    89
	_asm jne short TRealXBinOpNaN2
sl@0
    90
	TRealXBinOpNaN1:			// swap the operands
sl@0
    91
	_asm xchg ecx, eax
sl@0
    92
	_asm xchg edx, edi
sl@0
    93
	_asm xchg ebx, ebp
sl@0
    94
	TRealXBinOpNaN2:
sl@0
    95
	_asm cmp eax, 0xFFFF0000	// check if both operands are NaNs
sl@0
    96
	_asm jb short TRealXBinOpNaN4	// if not, ignore non-NaN operand
sl@0
    97
	_asm cmp edi, 0x80000000
sl@0
    98
	_asm jne short TRealXBinOpNaN3
sl@0
    99
	_asm test ebp, ebp
sl@0
   100
	_asm je short TRealXBinOpNaN4
sl@0
   101
	TRealXBinOpNaN3:			// if both operands are NaN's, compare significands
sl@0
   102
	_asm cmp edx, edi
sl@0
   103
	_asm ja short TRealXBinOpNaN4
sl@0
   104
	_asm jb short TRealXBinOpNaN5
sl@0
   105
	_asm cmp ebx, ebp
sl@0
   106
	_asm jae short TRealXBinOpNaN4
sl@0
   107
	TRealXBinOpNaN5:			// come here if dest is smaller - copy source to dest
sl@0
   108
	_asm mov ecx, eax
sl@0
   109
	_asm mov edx, edi
sl@0
   110
	_asm mov ebx, ebp
sl@0
   111
	TRealXBinOpNaN4:			// NaN with larger significand is in ecx,edx:ebx
sl@0
   112
	_asm or edx, 0x40000000		// convert an SNaN to a QNaN
sl@0
   113
	_asm mov eax, -6			// return KErrArgument
sl@0
   114
	_asm ret
sl@0
   115
	}
sl@0
   116
sl@0
   117
// Add TRealX at [esi] + ecx,edx:ebx
sl@0
   118
// Result in ecx,edx:ebx
sl@0
   119
// Error code in eax
sl@0
   120
// Note:	+0 + +0 = +0, -0 + -0 = -0, +0 + -0 = -0 + +0 = +0,
sl@0
   121
//			+/-0 + X = X + +/-0 = X, X + -X = -X + X = +0
sl@0
   122
__NAKED__ LOCAL_C void TRealXAdd()
sl@0
   123
	{
sl@0
   124
	_asm xor ch, ch				// clear rounding flags
sl@0
   125
	_asm cmp ecx, 0xFFFF0000	// check if dest=NaN or infinity
sl@0
   126
	_asm jnc addfpsd			// branch if it is
sl@0
   127
	_asm mov eax, [esi+8]		// fetch sign/exponent of source
sl@0
   128
	_asm cmp eax, 0xFFFF0000	// check if source=NaN or infinity
sl@0
   129
	_asm jnc addfpss			// branch if it is
sl@0
   130
	_asm cmp eax, 0x10000		// check if source=0
sl@0
   131
	_asm jc addfp0s				// branch if it is
sl@0
   132
	_asm cmp ecx, 0x10000		// check if dest=0
sl@0
   133
	_asm jc addfp0d				// branch if it is
sl@0
   134
	_asm and cl, 1				// clear bits 1-7 of ecx
sl@0
   135
	_asm and al, 1				// clear bits 1-7 of eax
sl@0
   136
	_asm mov ch, cl
sl@0
   137
	_asm xor ch, al				// xor of signs into ch bit 0
sl@0
   138
	_asm add ch, ch
sl@0
   139
	_asm or cl, ch				// and into cl bit 1
sl@0
   140
	_asm or al, ch				// and al bit 1
sl@0
   141
	_asm xor ch, ch				// clear rounding flags
sl@0
   142
	_asm mov ebp, [esi]			// fetch source mantissa 0-31
sl@0
   143
	_asm mov edi, [esi+4]		// fetch source mantissa 32-63
sl@0
   144
	_asm ror ecx, 16			// dest exponent into cx
sl@0
   145
	_asm ror eax, 16			// source exponent into ax
sl@0
   146
	_asm push ecx				// push dest exponent/sign
sl@0
   147
	_asm sub cx, ax				// cx = dest exponent - source exponent
sl@0
   148
	_asm je short addfp3b		// if equal, no shifting required
sl@0
   149
	_asm ja short addfp1		// branch if dest exponent >= source exponent
sl@0
   150
	_asm xchg ebx, ebp			// make sure edi:ebp contains the mantissa to be shifted
sl@0
   151
	_asm xchg edx, edi			//
sl@0
   152
	_asm xchg eax, [esp]		// and larger exponent and corresponding sign is on the stack
sl@0
   153
	_asm neg cx					// make cx positive = number of right shifts needed
sl@0
   154
	addfp1:
sl@0
   155
	_asm cmp cx, 64				// if more than 64 shifts needed
sl@0
   156
	_asm ja addfp2				// branch to output larger number
sl@0
   157
	_asm jb addfp3				// branch if <64 shifts
sl@0
   158
	_asm mov eax, edi			// exactly 64 shifts needed - rounding word=mant high
sl@0
   159
	_asm test ebp, ebp			// check bits lost
sl@0
   160
	_asm jz short addfp3a
sl@0
   161
	_asm or ch, 1				// if not all zero, set rounded-down flag
sl@0
   162
	addfp3a:
sl@0
   163
	_asm xor edi, edi			// clear edx:ebx
sl@0
   164
	_asm xor ebp, ebp
sl@0
   165
	_asm jmp short addfp5		// finished shifting
sl@0
   166
	addfp3b:					// exponents equal
sl@0
   167
	_asm xor eax, eax			// set rounding word=0
sl@0
   168
	_asm jmp short addfp5
sl@0
   169
	addfp3:
sl@0
   170
	_asm cmp cl, 32				// 32 or more shifts needed ?
sl@0
   171
	_asm jb short addfp4		// skip if <32
sl@0
   172
	_asm mov eax, ebp			// rounding word=mant low
sl@0
   173
	_asm mov ebp, edi			// mant low=mant high
sl@0
   174
	_asm xor edi, edi			// mant high=0
sl@0
   175
	_asm sub cl, 32				// reduce count by 32
sl@0
   176
	_asm jz short addfp5		// if now zero, finished shifting
sl@0
   177
	_asm shrd edi, eax, cl		// shift ebp:eax:edi right by cl bits
sl@0
   178
	_asm shrd eax, ebp, cl		//
sl@0
   179
	_asm shr ebp, cl			//
sl@0
   180
	_asm test edi, edi			// check bits lost in shift
sl@0
   181
	_asm jz short addfp5		// if all zero, finished
sl@0
   182
	_asm or ch, 1				// else set rounded-down flag
sl@0
   183
	_asm xor edi, edi			// clear edx again
sl@0
   184
	_asm jmp short addfp5		// finished shifting
sl@0
   185
	addfp4:						// <32 shifts needed now
sl@0
   186
	_asm xor eax, eax			// clear rounding word initially
sl@0
   187
	_asm shrd eax, ebp, cl		// shift edi:ebp:eax right by cl bits
sl@0
   188
	_asm shrd ebp, edi, cl		//
sl@0
   189
	_asm shr edi, cl			//
sl@0
   190
sl@0
   191
	addfp5:
sl@0
   192
	_asm mov [esp+3], ch		// rounding flag into ch image on stack
sl@0
   193
	_asm pop ecx				// recover sign and exponent into ecx, with rounding flag
sl@0
   194
	_asm ror ecx, 16			// into normal position
sl@0
   195
	_asm test cl, 2				// addition or subtraction needed ?
sl@0
   196
	_asm jnz short subfp1		// branch if subtraction
sl@0
   197
	_asm add ebx,ebp			// addition required - add mantissas
sl@0
   198
	_asm adc edx,edi			//
sl@0
   199
	_asm jnc short roundfp		// branch if no carry
sl@0
   200
	_asm rcr edx,1				// shift carry right into mantissa
sl@0
   201
	_asm rcr ebx,1				//
sl@0
   202
	_asm rcr eax,1				// and into rounding word
sl@0
   203
	_asm jnc short addfp5a
sl@0
   204
	_asm or ch, 1				// if 1 shifted out, set rounded-down flag
sl@0
   205
	addfp5a:
sl@0
   206
	_asm add ecx, 0x10000		// and increment exponent
sl@0
   207
sl@0
   208
	// perform rounding based on rounding word in eax and rounding flag in ch
sl@0
   209
	roundfp:
sl@0
   210
	_asm cmp eax, 0x80000000
sl@0
   211
	_asm jc roundfp0			// if rounding word<80000000, round down
sl@0
   212
	_asm ja roundfp1			// if >80000000, round up
sl@0
   213
	_asm test ch, 1
sl@0
   214
	_asm jnz short roundfp1		// if rounded-down flag set, round up
sl@0
   215
	_asm test ch, 2
sl@0
   216
	_asm jnz short roundfp0		// if rounded-up flag set, round down
sl@0
   217
	_asm test bl, 1				// else test mantissa lsb
sl@0
   218
	_asm jz short roundfp0		// round down if 0, up if 1 (round to even)
sl@0
   219
	roundfp1:					// Come here to round up
sl@0
   220
	_asm add ebx, 1				// increment mantissa
sl@0
   221
	_asm adc edx,0				//
sl@0
   222
	_asm jnc roundfp1a			// if no carry OK
sl@0
   223
	_asm rcr edx,1				// else shift carry into mantissa (edx:ebx=0 here)
sl@0
   224
	_asm add ecx, 0x10000		// and increment exponent
sl@0
   225
	roundfp1a:
sl@0
   226
	_asm cmp ecx, 0xFFFF0000	// check for overflow
sl@0
   227
	_asm jae short addfpovfw	// jump if overflow
sl@0
   228
	_asm mov ch, 2				// else set rounded-up flag
sl@0
   229
	_asm xor eax, eax			// return KErrNone
sl@0
   230
	_asm ret
sl@0
   231
sl@0
   232
	roundfp0:					// Come here to round down
sl@0
   233
	_asm cmp ecx, 0xFFFF0000	// check for overflow
sl@0
   234
	_asm jae short addfpovfw	// jump if overflow
sl@0
   235
	_asm test eax, eax			// else check if rounding word zero
sl@0
   236
	_asm jz short roundfp0a		// if so, leave rounding flags as they are
sl@0
   237
	_asm mov ch, 1				// else set rounded-down flag
sl@0
   238
	roundfp0a:
sl@0
   239
	_asm xor eax, eax			// return KErrNone
sl@0
   240
	_asm ret					// exit
sl@0
   241
sl@0
   242
	addfpovfw:					// Come here if overflow occurs
sl@0
   243
	_asm xor ch, ch				// clear rounding flags, exponent=FFFF
sl@0
   244
	_asm xor ebx, ebx
sl@0
   245
	_asm mov edx, 0x80000000	// mantissa=80000000 00000000 for infinity
sl@0
   246
	_asm mov eax, -9			// return KErrOverflow
sl@0
   247
	_asm ret
sl@0
   248
sl@0
   249
	// exponents differ by more than 64 - output larger number
sl@0
   250
	addfp2:
sl@0
   251
	_asm pop ecx				// recover exponent and sign
sl@0
   252
	_asm ror ecx, 16			// into normal position
sl@0
   253
	_asm or ch, 1				// set rounded-down flag
sl@0
   254
	_asm test cl, 2				// check if signs the same
sl@0
   255
	_asm jz addfp2a
sl@0
   256
	_asm xor ch, 3				// if not, set rounded-up flag
sl@0
   257
	addfp2a:
sl@0
   258
	_asm xor eax, eax			// return KErrNone
sl@0
   259
	_asm ret
sl@0
   260
sl@0
   261
	// signs differ, so must subtract mantissas
sl@0
   262
	subfp1:
sl@0
   263
	_asm add ch, ch				// if rounded-down flag set, change it to rounded-up
sl@0
   264
	_asm neg eax				// subtract rounding word from 0
sl@0
   265
	_asm sbb ebx, ebp			// and subtract mantissas with borrow
sl@0
   266
	_asm sbb edx, edi			//
sl@0
   267
	_asm jnc short subfp2		// if no borrow, sign is correct
sl@0
   268
	_asm xor cl, 1				// else change sign of result
sl@0
   269
	_asm shr ch, 1				// change rounding back to rounded-down
sl@0
   270
	_asm not eax				// negate rounding word
sl@0
   271
	_asm not ebx				// and mantissa
sl@0
   272
	_asm not edx				//
sl@0
   273
	_asm add eax,1				// two's complement negation
sl@0
   274
	_asm adc ebx,0				//
sl@0
   275
	_asm adc edx,0				//
sl@0
   276
	subfp2:
sl@0
   277
	_asm jnz short subfp3		// branch if edx non-zero at this point
sl@0
   278
	_asm mov edx, ebx			// else shift ebx into edx
sl@0
   279
	_asm or edx, edx			//
sl@0
   280
	_asm jz short subfp4		// if still zero, branch
sl@0
   281
	_asm mov ebx, eax			// else shift rounding word into ebx
sl@0
   282
	_asm xor eax, eax			// and zero rounding word
sl@0
   283
	_asm sub ecx, 0x200000		// decrease exponent by 32 due to shift
sl@0
   284
	_asm jnc short subfp3		// if no borrow, carry on
sl@0
   285
	_asm jmp short subfpundflw	// if borrow here, underflow
sl@0
   286
	subfp4:
sl@0
   287
	_asm mov edx, eax			// move rounding word into edx
sl@0
   288
	_asm or edx, edx			// is edx still zero ?
sl@0
   289
	_asm jz short subfp0		// if so, result is precisely zero
sl@0
   290
	_asm xor ebx, ebx			// else zero ebx and rounding word
sl@0
   291
	_asm xor eax, eax			//
sl@0
   292
	_asm sub ecx, 0x400000		// and decrease exponent by 64 due to shift
sl@0
   293
	_asm jc short subfpundflw	// if borrow, underflow
sl@0
   294
	subfp3:
sl@0
   295
	_asm mov edi, ecx			// preserve sign and exponent
sl@0
   296
	_asm bsr ecx, edx			// position of most significant 1 into ecx
sl@0
   297
	_asm neg ecx				//
sl@0
   298
	_asm add ecx, 31			// cl = 31-position of MS 1 = number of shifts to normalise
sl@0
   299
	_asm shld edx, ebx, cl		// shift edx:ebx:eax left by cl bits
sl@0
   300
	_asm shld ebx, eax, cl		//
sl@0
   301
	_asm shl eax, cl			//
sl@0
   302
	_asm mov ebp, ecx			// bit count into ebp for subtraction
sl@0
   303
	_asm shl ebp, 16			// shift left by 16 to align with exponent
sl@0
   304
	_asm mov ecx, edi			// exponent, sign, rounding flags back into ecx
sl@0
   305
	_asm sub ecx, ebp			// subtract shift count from exponent
sl@0
   306
	_asm jc short subfpundflw	// if borrow, underflow
sl@0
   307
	_asm cmp ecx, 0x10000		// check if exponent 0
sl@0
   308
	_asm jnc roundfp			// if not, jump to round result, else underflow
sl@0
   309
sl@0
   310
	// come here if underflow
sl@0
   311
	subfpundflw:
sl@0
   312
	_asm and ecx, 1				// set exponent to zero, leave sign
sl@0
   313
	_asm xor edx, edx
sl@0
   314
	_asm xor ebx, ebx
sl@0
   315
	_asm mov eax, -10			// return KErrUnderflow
sl@0
   316
	_asm ret
sl@0
   317
sl@0
   318
	// come here to return zero result
sl@0
   319
	subfp0:
sl@0
   320
	_asm xor ecx, ecx			// set exponent to zero, positive sign
sl@0
   321
	_asm xor edx, edx
sl@0
   322
	_asm xor ebx, ebx
sl@0
   323
	addfp0snzd:
sl@0
   324
	_asm xor eax, eax			// return KErrNone
sl@0
   325
	_asm ret
sl@0
   326
sl@0
   327
	// come here if source=0 - eax=source exponent/sign
sl@0
   328
	addfp0s:
sl@0
   329
	_asm cmp ecx, 0x10000		// check if dest=0
sl@0
   330
	_asm jnc addfp0snzd			// if not, return dest unaltered
sl@0
   331
	_asm and ecx, eax			// else both zero, result negative iff both zeros negative
sl@0
   332
	_asm and ecx, 1
sl@0
   333
	_asm xor eax, eax			// return KErrNone
sl@0
   334
	_asm ret
sl@0
   335
sl@0
   336
	// come here if dest=0, source nonzero
sl@0
   337
	addfp0d:
sl@0
   338
	_asm mov ebx, [esi]			// return source unaltered
sl@0
   339
	_asm mov edx, [esi+4]
sl@0
   340
	_asm mov ecx, [esi+8]
sl@0
   341
	_asm xor eax, eax			// return KErrNone
sl@0
   342
	_asm ret
sl@0
   343
sl@0
   344
	// come here if dest=NaN or infinity
sl@0
   345
	addfpsd:
sl@0
   346
	_asm cmp edx, 0x80000000	// check for infinity
sl@0
   347
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   348
	_asm test ebx, ebx
sl@0
   349
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   350
	_asm mov eax, [esi+8]		// eax=second operand exponent
sl@0
   351
	_asm cmp eax, 0xFFFF0000	// check second operand for NaN or infinity
sl@0
   352
	_asm jae short addfpsd1		// branch if NaN or infinity
sl@0
   353
	addfpsd2:
sl@0
   354
	_asm mov eax, -9			// else return dest unaltered (infinity) and KErrOverflow
sl@0
   355
	_asm ret
sl@0
   356
	addfpsd1:
sl@0
   357
	_asm mov ebp, [esi]			// source mantissa into edi:ebp
sl@0
   358
	_asm mov edi, [esi+4]
sl@0
   359
	_asm cmp edi, 0x80000000	// check for infinity
sl@0
   360
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   361
	_asm test ebp, ebp
sl@0
   362
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   363
	_asm xor al, cl				// both operands are infinity - check signs
sl@0
   364
	_asm test al, 1
sl@0
   365
	_asm jz short addfpsd2		// if both the same, return KErrOverflow
sl@0
   366
	_asm jmp TRealXRealIndefinite	// else return 'real indefinite'
sl@0
   367
sl@0
   368
	// come here if source=NaN or infinity, dest finite
sl@0
   369
	addfpss:
sl@0
   370
	_asm mov ebp, [esi]			// source mantissa into edi:ebp
sl@0
   371
	_asm mov edi, [esi+4]
sl@0
   372
	_asm cmp edi, 0x80000000	// check for infinity
sl@0
   373
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   374
	_asm test ebp, ebp
sl@0
   375
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   376
	_asm mov ecx, eax			// if source=infinity, return source unaltered
sl@0
   377
	_asm mov edx, edi
sl@0
   378
	_asm mov ebx, ebp
sl@0
   379
	_asm mov eax, -9			// return KErrOverflow
sl@0
   380
	_asm ret
sl@0
   381
	}
sl@0
   382
sl@0
   383
// Subtract TRealX at [esi] - ecx,edx:ebx
sl@0
   384
// Result in ecx,edx:ebx
sl@0
   385
// Error code in eax
sl@0
   386
__NAKED__ LOCAL_C void TRealXSubtract()
sl@0
   387
	{
sl@0
   388
	_asm xor cl, 1              // negate subtrahend
sl@0
   389
	_asm jmp TRealXAdd
sl@0
   390
	}
sl@0
   391
sl@0
   392
// Multiply TRealX at [esi] * ecx,edx:ebx
sl@0
   393
// Result in ecx,edx:ebx
sl@0
   394
// Error code in eax
sl@0
   395
__NAKED__ LOCAL_C void TRealXMultiply()
sl@0
   396
	{
sl@0
   397
	_asm xor ch, ch				// clear rounding flags
sl@0
   398
	_asm mov eax, [esi+8]		// fetch sign/exponent of source
sl@0
   399
	_asm xor cl, al				// xor signs
sl@0
   400
	_asm cmp ecx, 0xFFFF0000	// check if dest=NaN or infinity
sl@0
   401
	_asm jnc mulfpsd			// branch if it is
sl@0
   402
	_asm cmp eax, 0xFFFF0000	// check if source=NaN or infinity
sl@0
   403
	_asm jnc mulfpss			// branch if it is
sl@0
   404
	_asm cmp eax, 0x10000		// check if source=0
sl@0
   405
	_asm jc mulfp0				// branch if it is
sl@0
   406
	_asm cmp ecx, 0x10000		// check if dest=0
sl@0
   407
	_asm jc mulfp0				// branch if it is
sl@0
   408
	_asm push ecx				// save result sign
sl@0
   409
	_asm shr ecx, 16			// dest exponent into cx
sl@0
   410
	_asm shr eax, 16			// source exponent into ax
sl@0
   411
	_asm add eax, ecx			// add exponents
sl@0
   412
	_asm sub eax, 0x7FFE		// eax now contains result exponent
sl@0
   413
	_asm push eax				// save it
sl@0
   414
	_asm mov edi, edx			// save dest mantissa high
sl@0
   415
	_asm mov eax, ebx			// dest mantissa low -> eax
sl@0
   416
	_asm mul dword ptr [esi]	// dest mantissa low * source mantissa low -> edx:eax
sl@0
   417
	_asm xchg ebx, eax			// result dword 0 -> ebx, dest mant low -> eax
sl@0
   418
	_asm mov ebp, edx			// result dword 1 -> ebp
sl@0
   419
	_asm mul dword ptr [esi+4]	// dest mant low * src mant high -> edx:eax
sl@0
   420
	_asm add ebp, eax			// add in partial product to dwords 1 and 2
sl@0
   421
	_asm adc edx, 0				//
sl@0
   422
	_asm mov ecx, edx			// result dword 2 -> ecx
sl@0
   423
	_asm mov eax, edi			// dest mant high -> eax
sl@0
   424
	_asm mul dword ptr [esi+4]	// dest mant high * src mant high -> edx:eax
sl@0
   425
	_asm add ecx, eax			// add in partial product to dwords 2, 3
sl@0
   426
	_asm adc edx, 0				//
sl@0
   427
	_asm mov eax, edi			// dest mant high -> eax
sl@0
   428
	_asm mov edi, edx			// result dword 3 -> edi
sl@0
   429
	_asm mul dword ptr [esi]	// dest mant high * src mant low -> edx:eax
sl@0
   430
	_asm add ebp, eax			// add in partial product to dwords 1, 2
sl@0
   431
	_asm adc ecx, edx			//
sl@0
   432
	_asm adc edi, 0				// 128-bit mantissa product is now in edi:ecx:ebp:ebx
sl@0
   433
	_asm mov edx, edi			// top 64 bits into edx:ebx
sl@0
   434
	_asm mov edi, ebx
sl@0
   435
	_asm mov ebx, ecx			// bottom 64 bits now in ebp:edi
sl@0
   436
	_asm pop ecx				// recover exponent
sl@0
   437
	_asm js short mulfp1		// skip if mantissa normalised
sl@0
   438
	_asm add edi, edi			// else shift left (only one shift will be needed)
sl@0
   439
	_asm adc ebp, ebp
sl@0
   440
	_asm adc ebx, ebx
sl@0
   441
	_asm adc edx, edx
sl@0
   442
	_asm dec ecx				// and decrement exponent
sl@0
   443
	mulfp1:
sl@0
   444
	_asm cmp ebp, 0x80000000	// compare bottom 64 bits with 80000000 00000000 for rounding
sl@0
   445
	_asm ja short mulfp2		// branch to round up
sl@0
   446
	_asm jb short mulfp3		// branch to round down
sl@0
   447
	_asm test edi, edi
sl@0
   448
	_asm jnz short mulfp2		// branch to round up
sl@0
   449
	_asm test bl, 1				// if exactly half-way, test LSB of result mantissa
sl@0
   450
	_asm jz short mulfp4		// if LSB=0, round down (round to even)
sl@0
   451
	mulfp2:
sl@0
   452
	_asm add ebx, 1				// round up - increment mantissa
sl@0
   453
	_asm adc edx, 0
sl@0
   454
	_asm jnc short mulfp2a
sl@0
   455
	_asm rcr edx, 1
sl@0
   456
	_asm inc ecx
sl@0
   457
	mulfp2a:
sl@0
   458
	_asm mov al, 2				// set rounded-up flag
sl@0
   459
	_asm jmp short mulfp5
sl@0
   460
	mulfp3:						// round down
sl@0
   461
	_asm xor al, al				// clear rounding flags
sl@0
   462
	_asm or ebp, edi			// check for exact result
sl@0
   463
	_asm jz short mulfp5		// skip if exact
sl@0
   464
	mulfp4:						// come here to round down when we know result inexact
sl@0
   465
	_asm mov al, 1				// else set rounded-down flag
sl@0
   466
	mulfp5:						// final mantissa now in edx:ebx, exponent in ecx
sl@0
   467
	_asm cmp ecx, 0xFFFF		// check for overflow
sl@0
   468
	_asm jge short mulfp6		// branch if overflow
sl@0
   469
	_asm cmp ecx, 0				// check for underflow
sl@0
   470
	_asm jle short mulfp7		// branch if underflow
sl@0
   471
	_asm shl ecx, 16			// else exponent up to top end of ecx
sl@0
   472
	_asm mov ch, al				// rounding flags into ch
sl@0
   473
	_asm pop eax				// recover result sign
sl@0
   474
	_asm mov cl, al				// into cl
sl@0
   475
	_asm xor eax, eax			// return KErrNone
sl@0
   476
	_asm ret
sl@0
   477
sl@0
   478
	// come here if overflow
sl@0
   479
	mulfp6:
sl@0
   480
	_asm pop eax				// recover result sign
sl@0
   481
	_asm mov ecx, 0xFFFF0000	// exponent=FFFF
sl@0
   482
	_asm mov cl, al				// sign into cl
sl@0
   483
	_asm mov edx, 0x80000000	// set mantissa to 80000000 00000000 for infinity
sl@0
   484
	_asm xor ebx, ebx
sl@0
   485
	_asm mov eax, -9			// return KErrOverflow
sl@0
   486
	_asm ret
sl@0
   487
sl@0
   488
	// come here if underflow
sl@0
   489
	mulfp7:
sl@0
   490
	_asm pop eax				// recover result sign
sl@0
   491
	_asm xor ecx, ecx			// exponent=0
sl@0
   492
	_asm mov cl, al				// sign into cl
sl@0
   493
	_asm xor edx, edx
sl@0
   494
	_asm xor ebx, ebx
sl@0
   495
	_asm mov eax, -10			// return KErrUnderflow
sl@0
   496
	_asm ret
sl@0
   497
sl@0
   498
	// come here if either operand zero
sl@0
   499
	mulfp0:
sl@0
   500
	_asm and ecx, 1				// set exponent=0, keep sign
sl@0
   501
	_asm xor edx, edx
sl@0
   502
	_asm xor ebx, ebx
sl@0
   503
	_asm xor eax, eax			// return KErrNone
sl@0
   504
	_asm ret
sl@0
   505
sl@0
   506
	// come here if destination operand NaN or infinity
sl@0
   507
	mulfpsd:
sl@0
   508
	_asm cmp edx, 0x80000000	// check for infinity
sl@0
   509
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   510
	_asm test ebx, ebx
sl@0
   511
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   512
	_asm cmp eax, 0xFFFF0000	// check second operand for NaN or infinity
sl@0
   513
	_asm jae short mulfpsd1		// branch if NaN or infinity
sl@0
   514
	_asm cmp eax, 0x10000		// check if second operand zero
sl@0
   515
	_ASM_j(c,TRealXRealIndefinite)	// if so, return 'real indefinite'
sl@0
   516
	_asm mov eax, -9			// else return dest (infinity) with xor sign and KErrOverflow
sl@0
   517
	_asm ret
sl@0
   518
	mulfpsd1:
sl@0
   519
	_asm mov ebp, [esi]			// source mantissa into edi:ebp
sl@0
   520
	_asm mov edi, [esi+4]
sl@0
   521
	_asm cmp edi, 0x80000000	// check for infinity
sl@0
   522
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   523
	_asm test ebp, ebp
sl@0
   524
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   525
	_asm mov eax, -9			// both operands infinity - return infinity with xor sign
sl@0
   526
	_asm ret					// and KErrOverflow
sl@0
   527
sl@0
   528
	// come here if source operand NaN or infinity, destination finite
sl@0
   529
	mulfpss:
sl@0
   530
	_asm mov ebp, [esi]			// source mantissa into edi:ebp
sl@0
   531
	_asm mov edi, [esi+4]
sl@0
   532
	_asm cmp edi, 0x80000000	// check for infinity
sl@0
   533
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   534
	_asm test ebp, ebp
sl@0
   535
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   536
	_asm cmp ecx, 0x10000		// source=infinity, check if dest=0
sl@0
   537
	_ASM_j(c,TRealXRealIndefinite)	// if so, return 'real indefinite'
sl@0
   538
	_asm or ecx, 0xFFFF0000		// set exp=FFFF, leave xor sign in cl
sl@0
   539
	_asm mov edx, edi			// set mantissa for infinity
sl@0
   540
	_asm mov ebx, ebp
sl@0
   541
	_asm mov eax, -9			// return KErrOverflow
sl@0
   542
	_asm ret
sl@0
   543
	}
sl@0
   544
sl@0
   545
// Divide 96-bit unsigned dividend EDX:EAX:0 by 64-bit unsigned divisor ECX:EBX
sl@0
   546
// Assume ECX bit 31 = 1, ie 2^63 <= divisor < 2^64
sl@0
   547
// Assume the quotient fits in 32 bits
sl@0
   548
// Return 32 bit quotient in EDI
sl@0
   549
// Return 64 bit remainder in EBP:ESI
sl@0
   550
__NAKED__ LOCAL_C void LongDivide(void)
sl@0
   551
	{
sl@0
   552
	_asm push edx				// save dividend
sl@0
   553
	_asm push eax				//
sl@0
   554
	_asm cmp edx, ecx			// check if truncation of divisor will overflow DIV instruction
sl@0
   555
	_asm jb short longdiv1		// skip if not
sl@0
   556
	_asm xor eax, eax			// else return quotient of 0xFFFFFFFF
sl@0
   557
	_asm dec eax				//
sl@0
   558
	_asm jmp short longdiv2		//
sl@0
   559
	longdiv1:
sl@0
   560
	_asm div ecx				// divide EDX:EAX by ECX to give approximate quotient in EAX
sl@0
   561
	longdiv2:
sl@0
   562
	_asm mov edi, eax			// save approx quotient
sl@0
   563
	_asm mul ebx				// multiply approx quotient by full divisor ECX:EBX
sl@0
   564
	_asm mov esi, eax			// first partial product into EBP:ESI
sl@0
   565
	_asm mov ebp, edx			//
sl@0
   566
	_asm mov eax, edi			// approx quotient back into eax
sl@0
   567
	_asm mul ecx				// upper partial product now in EDX:EAX
sl@0
   568
	_asm add eax, ebp			// add to form 96-bit product in EDX:EAX:ESI
sl@0
   569
	_asm adc edx, 0				//
sl@0
   570
	_asm neg esi				// remainder = dividend - approx quotient * divisor
sl@0
   571
	_asm mov ebp, [esp]			// fetch dividend bits 32-63
sl@0
   572
	_asm sbb ebp, eax			//
sl@0
   573
	_asm mov eax, [esp+4]		// fetch dividend bits 64-95
sl@0
   574
	_asm sbb eax, edx			// remainder is now in EAX:EBP:ESI
sl@0
   575
	_asm jns short longdiv4		// if remainder positive, quotient is correct, so exit
sl@0
   576
	longdiv3:
sl@0
   577
	_asm dec edi				// else quotient is too big, so decrement it
sl@0
   578
	_asm add esi, ebx			// and add divisor to remainder
sl@0
   579
	_asm adc ebp, ecx			//
sl@0
   580
	_asm adc eax, 0				//
sl@0
   581
	_asm js short longdiv3		// if still negative, repeat (requires <4 iterations)
sl@0
   582
	longdiv4:
sl@0
   583
	_asm add esp, 8				// remove dividend from stack
sl@0
   584
	_asm ret					// return with quotient in EDI, remainder in EBP:ESI
sl@0
   585
	}
sl@0
   586
sl@0
   587
// Divide TRealX at [esi] / ecx,edx:ebx
sl@0
   588
// Result in ecx,edx:ebx
sl@0
   589
// Error code in eax
sl@0
   590
__NAKED__ LOCAL_C void TRealXDivide(void)
sl@0
   591
	{
sl@0
   592
	_asm xor ch, ch				// clear rounding flags
sl@0
   593
	_asm mov eax, [esi+8]		// fetch sign/exponent of dividend
sl@0
   594
	_asm xor cl, al				// xor signs
sl@0
   595
	_asm cmp eax, 0xFFFF0000	// check if dividend=NaN or infinity
sl@0
   596
	_asm jnc divfpss			// branch if it is
sl@0
   597
	_asm cmp ecx, 0xFFFF0000	// check if divisor=NaN or infinity
sl@0
   598
	_asm jnc divfpsd			// branch if it is
sl@0
   599
	_asm cmp ecx, 0x10000		// check if divisor=0
sl@0
   600
	_asm jc divfpdv0			// branch if it is
sl@0
   601
	_asm cmp eax, 0x10000		// check if dividend=0
sl@0
   602
	_asm jc divfpdd0			// branch if it is
sl@0
   603
	_asm push esi				// save pointer to dividend
sl@0
   604
	_asm push ecx				// save result sign
sl@0
   605
	_asm shr ecx, 16			// divisor exponent into cx
sl@0
   606
	_asm shr eax, 16			// dividend exponent into ax
sl@0
   607
	_asm sub eax, ecx			// subtract exponents
sl@0
   608
	_asm add eax, 0x7FFE		// eax now contains result exponent
sl@0
   609
	_asm push eax				// save it
sl@0
   610
	_asm mov ecx, edx			// divisor mantissa into ecx:ebx
sl@0
   611
	_asm mov edx, [esi+4]		// dividend mantissa into edx:eax
sl@0
   612
	_asm mov eax, [esi]
sl@0
   613
	_asm xor edi, edi			// clear edi initially
sl@0
   614
	_asm cmp edx, ecx			// compare EDX:EAX with ECX:EBX
sl@0
   615
	_asm jb short divfp1		// if EDX:EAX < ECX:EBX, leave everything as is
sl@0
   616
	_asm ja short divfp2		//
sl@0
   617
	_asm cmp eax, ebx			// if EDX=ECX, then compare ls dwords
sl@0
   618
	_asm jb short divfp1		// if dividend mant < divisor mant, leave everything as is
sl@0
   619
	divfp2:
sl@0
   620
	_asm sub eax, ebx			// else dividend mant -= divisor mant
sl@0
   621
	_asm sbb edx, ecx			//
sl@0
   622
	_asm inc edi				// and EDI=1 (bit 0 of EDI is the integer part of the result)
sl@0
   623
	_asm inc dword ptr [esp]	// also increment result exponent
sl@0
   624
	divfp1:
sl@0
   625
	_asm push edi				// save top bit of result
sl@0
   626
	_asm call LongDivide		// divide EDX:EAX:0 by ECX:EBX to give next 32 bits of result in EDI
sl@0
   627
	_asm push edi				// save next 32 bits of result
sl@0
   628
	_asm mov edx, ebp			// remainder from EBP:ESI into EDX:EAX
sl@0
   629
	_asm mov eax, esi			//
sl@0
   630
	_asm call LongDivide		// divide EDX:EAX:0 by ECX:EBX to give next 32 bits of result in EDI
sl@0
   631
	_asm test byte ptr [esp+4], 1	// test integer bit of result
sl@0
   632
	_asm jnz short divfp4		// if set, no need to calculate another bit
sl@0
   633
	_asm xor eax, eax			//
sl@0
   634
	_asm add esi, esi			// 2*remainder into EAX:EBP:ESI
sl@0
   635
	_asm adc ebp, ebp			//
sl@0
   636
	_asm adc eax, eax			//
sl@0
   637
	_asm sub esi, ebx			// subtract divisor to generate final quotient bit
sl@0
   638
	_asm sbb ebp, ecx			//
sl@0
   639
	_asm sbb eax, 0				//
sl@0
   640
	_asm jnc short divfp3		// skip if no borrow - in this case eax=0
sl@0
   641
	_asm add esi, ebx			// if borrow add back - final remainder now in EBP:ESI
sl@0
   642
	_asm adc ebp, ecx			//
sl@0
   643
	_asm adc eax, 0				// eax will be zero after this and carry will be set
sl@0
   644
	divfp3:
sl@0
   645
	_asm cmc					// final bit = 1-C
sl@0
   646
	_asm rcr eax, 1				// shift it into eax bit 31
sl@0
   647
	_asm mov ebx, edi			// result into EDX:EBX:EAX, remainder in EBP:ESI
sl@0
   648
	_asm pop edx
sl@0
   649
	_asm add esp, 4				// discard integer bit (zero)
sl@0
   650
	_asm jmp short divfp5		// branch to round
sl@0
   651
sl@0
   652
	divfp4:						// integer bit was set
sl@0
   653
	_asm mov ebx, edi			// result into EDX:EBX:EAX
sl@0
   654
	_asm pop edx				//
sl@0
   655
	_asm pop eax				// integer part of result into eax (=1)
sl@0
   656
	_asm stc					// shift a 1 into top end of mantissa
sl@0
   657
	_asm rcr edx,1				//
sl@0
   658
	_asm rcr ebx,1				//
sl@0
   659
	_asm rcr eax,1				// bottom bit into eax bit 31
sl@0
   660
sl@0
   661
	// when we get to here we have 65 bits of quotient mantissa in
sl@0
   662
	// EDX:EBX:EAX (bottom bit in eax bit 31)
sl@0
   663
	// and the remainder is in EBP:ESI
sl@0
   664
	divfp5:
sl@0
   665
	_asm pop ecx				// recover result exponent
sl@0
   666
	_asm add eax, eax			// test rounding bit
sl@0
   667
	_asm jnc short divfp6		// branch to round down
sl@0
   668
	_asm or ebp, esi			// test remainder to see if we are exactly half-way
sl@0
   669
	_asm jnz short divfp7		// if not, round up
sl@0
   670
	_asm test bl, 1				// exactly halfway - test LSB of mantissa
sl@0
   671
	_asm jz short divfp8		// round down if LSB=0 (round to even)
sl@0
   672
	divfp7:
sl@0
   673
	_asm add ebx, 1				// round up - increment mantissa
sl@0
   674
	_asm adc edx, 0
sl@0
   675
	_asm jnc short divfp7a
sl@0
   676
	_asm rcr edx, 1				// if carry, shift 1 into mantissa MSB
sl@0
   677
	_asm inc ecx				// and increment exponent
sl@0
   678
	divfp7a:
sl@0
   679
	_asm mov al, 2				// set rounded-up flag
sl@0
   680
	_asm jmp short divfp9
sl@0
   681
	divfp6:
sl@0
   682
	_asm xor al, al				// round down - first clear rounding flags
sl@0
   683
	_asm or ebp, esi			// test if result exact
sl@0
   684
	_asm jz short divfp9		// skip if exact
sl@0
   685
	divfp8:						// come here to round down when we know result is inexact
sl@0
   686
	_asm mov al, 1				// set rounded-down flag
sl@0
   687
	divfp9:						// final mantissa now in edx:ebx, exponent in ecx
sl@0
   688
	_asm cmp ecx, 0xFFFF		// check for overflow
sl@0
   689
	_asm jge short divfp10		// branch if overflow
sl@0
   690
	_asm cmp ecx, 0				// check for underflow
sl@0
   691
	_asm jle short divfp11		// branch if underflow
sl@0
   692
	_asm shl ecx, 16			// else exponent up to top end of ecx
sl@0
   693
	_asm mov ch, al				// rounding flags into ch
sl@0
   694
	_asm pop eax				// recover result sign
sl@0
   695
	_asm mov cl, al				// into cl
sl@0
   696
	_asm pop esi				// recover dividend pointer
sl@0
   697
	_asm xor eax, eax			// return KErrNone
sl@0
   698
	_asm ret
sl@0
   699
sl@0
   700
	// come here if overflow
sl@0
   701
	divfp10:
sl@0
   702
	_asm pop eax				// recover result sign
sl@0
   703
	_asm mov ecx, 0xFFFF0000	// exponent=FFFF
sl@0
   704
	_asm mov cl, al				// sign into cl
sl@0
   705
	_asm mov edx, 0x80000000	// set mantissa to 80000000 00000000 for infinity
sl@0
   706
	_asm xor ebx, ebx
sl@0
   707
	_asm mov eax, -9			// return KErrOverflow
sl@0
   708
	_asm pop esi				// recover dividend pointer
sl@0
   709
	_asm ret
sl@0
   710
sl@0
   711
	// come here if underflow
sl@0
   712
	divfp11:
sl@0
   713
	_asm pop eax				// recover result sign
sl@0
   714
	_asm xor ecx, ecx			// exponent=0
sl@0
   715
	_asm mov cl, al				// sign into cl
sl@0
   716
	_asm xor edx, edx
sl@0
   717
	_asm xor ebx, ebx
sl@0
   718
	_asm mov eax, -10			// return KErrUnderflow
sl@0
   719
	_asm pop esi				// recover dividend pointer
sl@0
   720
	_asm ret
sl@0
   721
sl@0
   722
sl@0
   723
	// come here if divisor=0, dividend finite
sl@0
   724
	divfpdv0:
sl@0
   725
	_asm cmp eax, 0x10000		// check if dividend also zero
sl@0
   726
	_ASM_j(c,TRealXRealIndefinite)	// if so, return 'real indefinite'
sl@0
   727
	_asm or ecx, 0xFFFF0000		// else set exponent=FFFF, leave xor sign in cl
sl@0
   728
	_asm mov edx, 0x80000000	// set mantissa for infinity
sl@0
   729
	_asm xor ebx, ebx
sl@0
   730
	_asm mov eax, -41			// return KErrDivideByZero
sl@0
   731
	_asm ret
sl@0
   732
sl@0
   733
	// come here if dividend=0, divisor finite and nonzero
sl@0
   734
	divfpdd0:
sl@0
   735
	_asm and ecx, 1				// exponent=0, leave xor sign in cl
sl@0
   736
	_asm xor eax, eax			// return KErrNone
sl@0
   737
	_asm ret
sl@0
   738
sl@0
   739
	// come here if dividend is a NaN or infinity
sl@0
   740
	divfpss:
sl@0
   741
	_asm mov ebp, [esi]			// dividend mantissa into edi:ebp
sl@0
   742
	_asm mov edi, [esi+4]
sl@0
   743
	_asm cmp edi, 0x80000000	// check for infinity
sl@0
   744
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   745
	_asm test ebp, ebp
sl@0
   746
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   747
	_asm cmp ecx, 0xFFFF0000	// check divisor for NaN or infinity
sl@0
   748
	_asm jae short divfpss1		// branch if NaN or infinity
sl@0
   749
	_asm or ecx, 0xFFFF0000		// infinity/finite - return infinity with xor sign
sl@0
   750
	_asm mov edx, 0x80000000
sl@0
   751
	_asm xor ebx, ebx
sl@0
   752
	_asm mov eax, -9			// return KErrOverflow
sl@0
   753
	_asm ret
sl@0
   754
	divfpss1:
sl@0
   755
	_asm cmp edx, 0x80000000	// check for infinity
sl@0
   756
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   757
	_asm test ebx, ebx
sl@0
   758
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   759
	_asm jmp TRealXRealIndefinite	// if both operands infinite, return 'real indefinite'
sl@0
   760
sl@0
   761
	// come here if divisor is a NaN or infinity, dividend finite
sl@0
   762
	divfpsd:
sl@0
   763
	_asm cmp edx, 0x80000000	// check for infinity
sl@0
   764
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   765
	_asm test ebx, ebx
sl@0
   766
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   767
	_asm and ecx, 1				// dividend is finite, divisor=infinity, so return 0 with xor sign
sl@0
   768
	_asm xor edx, edx
sl@0
   769
	_asm xor ebx, ebx
sl@0
   770
	_asm xor eax, eax			// return KErrNone
sl@0
   771
	_asm ret
sl@0
   772
	}
sl@0
   773
sl@0
   774
// TRealX modulo - dividend at [esi], divisor in ecx,edx:ebx
sl@0
   775
// Result in ecx,edx:ebx
sl@0
   776
// Error code in eax
sl@0
   777
__NAKED__ LOCAL_C void TRealXModulo(void)
sl@0
   778
	{
sl@0
   779
	_asm mov eax, [esi+8]		// fetch sign/exponent of dividend
sl@0
   780
	_asm mov cl, al				// result sign=dividend sign
sl@0
   781
	_asm xor ch, ch				// clear rounding flags
sl@0
   782
	_asm cmp eax, 0xFFFF0000	// check if dividend=NaN or infinity
sl@0
   783
	_asm jnc modfpss			// branch if it is
sl@0
   784
	_asm cmp ecx, 0xFFFF0000	// check if divisor=NaN or infinity
sl@0
   785
	_asm jnc modfpsd			// branch if it is
sl@0
   786
	_asm cmp ecx, 0x10000		// check if divisor=0
sl@0
   787
	_ASM_j(c,TRealXRealIndefinite)	// if so, return 'real indefinite'
sl@0
   788
	_asm shr eax, 16			// ax=dividend exponent
sl@0
   789
	_asm ror ecx, 16			// cx=divisor exponent
sl@0
   790
	_asm sub ax, cx				// ax=dividend exponent-divisor exponent
sl@0
   791
	_asm jc modfpdd0			// if dividend exponent is smaller, return dividend
sl@0
   792
	_asm cmp ax, 64				// check if exponents differ by >= 64 bits
sl@0
   793
	_asm jnc modfplp			// if so, underflow
sl@0
   794
	_asm mov ah, 0				// ah bit 0 acts as 65th accumulator bit
sl@0
   795
	_asm mov ebp, [esi]			// edi:ebp=dividend mantissa
sl@0
   796
	_asm mov edi, [esi+4]		//
sl@0
   797
	_asm jmp short modfp2		// skip left shift on first iteration
sl@0
   798
	modfp1:
sl@0
   799
	_asm add ebp, ebp			// shift accumulator left (65 bits)
sl@0
   800
	_asm adc edi, edi
sl@0
   801
	_asm adc ah, ah
sl@0
   802
	modfp2:
sl@0
   803
	_asm sub ebp, ebx			// subtract divisor from dividend
sl@0
   804
	_asm sbb edi, edx
sl@0
   805
	_asm sbb ah, 0
sl@0
   806
	_asm jnc short modfp3		// skip if no borrow
sl@0
   807
	_asm add ebp, ebx			// else add back
sl@0
   808
	_asm adc edi, edx
sl@0
   809
	_asm adc ah, 0
sl@0
   810
	modfp3:
sl@0
   811
	_asm dec al					// any more bits to do?
sl@0
   812
	_asm jns short modfp1		// loop if there are
sl@0
   813
	_asm mov edx, edi			// result mantissa (not yet normalised) into edx:ebx
sl@0
   814
	_asm mov ebx, ebp
sl@0
   815
	_asm or edi, ebx			// check for zero
sl@0
   816
	_asm jz modfp0				// jump if result zero
sl@0
   817
	_asm or edx, edx			// check if ms dword zero
sl@0
   818
	_asm jnz short modfp4
sl@0
   819
	_asm mov edx, ebx			// if so, shift left by 32
sl@0
   820
	_asm xor ebx, ebx
sl@0
   821
	_asm sub cx, 32				// and decrement exponent by 32
sl@0
   822
	_asm jbe modfpund			// if borrow or exponent zero, underflow
sl@0
   823
	modfp4:
sl@0
   824
	_asm mov edi, ecx			// preserve sign and exponent
sl@0
   825
	_asm bsr ecx, edx			// position of most significant 1 into ecx
sl@0
   826
	_asm neg ecx				//
sl@0
   827
	_asm add ecx, 31			// cl = 31-position of MS 1 = number of shifts to normalise
sl@0
   828
	_asm shld edx, ebx, cl		// shift edx:ebx left by cl bits
sl@0
   829
	_asm shl ebx, cl			//
sl@0
   830
	_asm mov ebp, ecx			// bit count into ebp for subtraction
sl@0
   831
	_asm mov ecx, edi			// exponent & sign back into ecx
sl@0
   832
	_asm sub cx, bp				// subtract shift count from exponent
sl@0
   833
	_asm jbe short modfpund		// if borrow or exponent 0, underflow
sl@0
   834
	_asm rol ecx, 16			// else ecx=exponent:sign
sl@0
   835
	_asm xor eax, eax			// normal exit, result in ecx,edx:ebx
sl@0
   836
	_asm ret
sl@0
   837
sl@0
   838
	// dividend=NaN or infinity
sl@0
   839
	modfpss:
sl@0
   840
	_asm mov ebp, [esi]			// dividend mantissa into edi:ebp
sl@0
   841
	_asm mov edi, [esi+4]
sl@0
   842
	_asm cmp edi, 0x80000000	// check for infinity
sl@0
   843
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   844
	_asm test ebp, ebp
sl@0
   845
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   846
	_asm cmp ecx, 0xFFFF0000	// check divisor for NaN or infinity
sl@0
   847
	_ASM_j(b,TRealXRealIndefinite)	// infinity%finite - return 'real indefinite'
sl@0
   848
	_asm cmp edx, 0x80000000	// check for divisor=infinity
sl@0
   849
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   850
	_asm test ebx, ebx
sl@0
   851
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   852
	_asm jmp TRealXRealIndefinite	// if both operands infinite, return 'real indefinite'
sl@0
   853
sl@0
   854
	// divisor=NaN or infinity, dividend finite
sl@0
   855
	modfpsd:
sl@0
   856
	_asm cmp edx, 0x80000000	// check for infinity
sl@0
   857
	_ASM_jn(e,TRealXBinOpNaN)	// branch if NaN
sl@0
   858
	_asm test ebx, ebx
sl@0
   859
	_ASM_jn(e,TRealXBinOpNaN)
sl@0
   860
	// finite%infinity - return dividend unaltered
sl@0
   861
sl@0
   862
	modfpdd0:
sl@0
   863
	_asm mov ebx, [esi]			// normal exit, return dividend unaltered
sl@0
   864
	_asm mov edx, [esi+4]
sl@0
   865
	_asm mov ecx, [esi+8]
sl@0
   866
	_asm xor eax, eax
sl@0
   867
	_asm ret
sl@0
   868
sl@0
   869
	modfp0:
sl@0
   870
	_asm shr ecx, 16			// normal exit, result 0
sl@0
   871
	_asm xor eax, eax
sl@0
   872
	_asm ret
sl@0
   873
sl@0
   874
	modfpund:
sl@0
   875
	_asm shr ecx, 16			// underflow, result 0
sl@0
   876
	_asm mov eax, -10			// return KErrUnderflow
sl@0
   877
	_asm ret
sl@0
   878
sl@0
   879
	modfplp:
sl@0
   880
	_asm shr ecx, 16			// loss of precision, result 0
sl@0
   881
	_asm mov eax, -7			// return KErrTotalLossOfPrecision
sl@0
   882
	_asm ret
sl@0
   883
	}
sl@0
   884
sl@0
   885
sl@0
   886
sl@0
   887
sl@0
   888
__NAKED__ EXPORT_C TRealX::TRealX()
sl@0
   889
/**
sl@0
   890
Constructs a default extended precision object.
sl@0
   891
sl@0
   892
This sets the value to zero.
sl@0
   893
*/
sl@0
   894
	{
sl@0
   895
	_asm xor eax, eax
sl@0
   896
	_asm mov [ecx], eax			// set value to zero
sl@0
   897
	_asm mov [ecx+4], eax
sl@0
   898
	_asm mov [ecx+8], eax
sl@0
   899
	_asm mov eax, ecx			// must return this
sl@0
   900
	_asm ret
sl@0
   901
	}
sl@0
   902
sl@0
   903
sl@0
   904
sl@0
   905
sl@0
   906
__NAKED__ EXPORT_C TRealX::TRealX(TUint /*aExp*/, TUint /*aMantHi*/, TUint /*aMantLo*/)
sl@0
   907
/**
sl@0
   908
Constructs an extended precision object from an explicit exponent and
sl@0
   909
a 64 bit mantissa.
sl@0
   910
sl@0
   911
@param aExp    The exponent 
sl@0
   912
@param aMantHi The high order 32 bits of the 64 bit mantissa 
sl@0
   913
@param aMantLo The low order 32 bits of the 64 bit mantissa 
sl@0
   914
*/
sl@0
   915
	{
sl@0
   916
	_asm mov eax, [esp+4]		// eax=aExp
sl@0
   917
	_asm mov [ecx+8], eax
sl@0
   918
	_asm mov eax, [esp+8]		// eax=aMantHi
sl@0
   919
	_asm mov [ecx+4], eax
sl@0
   920
	_asm mov eax, [esp+12]		// eax=aMantLo
sl@0
   921
	_asm mov [ecx], eax
sl@0
   922
	_asm mov eax, ecx			// must return this
sl@0
   923
	_asm ret 12
sl@0
   924
	}
sl@0
   925
sl@0
   926
sl@0
   927
sl@0
   928
sl@0
   929
__NAKED__ EXPORT_C TInt TRealX::Set(TInt /*aInt*/)
sl@0
   930
/**
sl@0
   931
Gives this extended precision object a new value taken
sl@0
   932
from a signed integer.
sl@0
   933
sl@0
   934
@param aInt The signed integer value.
sl@0
   935
sl@0
   936
@return KErrNone, always.
sl@0
   937
*/
sl@0
   938
	{
sl@0
   939
	// on entry ecx=this, [esp+4]=aInt, return code in eax
sl@0
   940
	_asm mov edx, [esp+4]		// edx=aInt
sl@0
   941
	_asm or edx, edx			// test sign/zero
sl@0
   942
	_asm mov eax, 0x7FFF
sl@0
   943
	_asm jz short trealxfromint0	// branch if 0
sl@0
   944
	_asm jns short trealxfromint1	// skip if positive
sl@0
   945
	_asm neg edx					// take absolute value
sl@0
   946
	_asm add eax, 0x10000			// sign bit in eax bit 16
sl@0
   947
	trealxfromint1:
sl@0
   948
	_asm push ecx					// save this
sl@0
   949
	_asm bsr ecx, edx				// bit number of edx MSB into ecx
sl@0
   950
	_asm add eax, ecx				// add to eax to form result exponent
sl@0
   951
	_asm neg cl
sl@0
   952
	_asm add cl, 31					// 31-bit number = number of shifts to normalise edx
sl@0
   953
	_asm shl edx, cl				// normalise edx
sl@0
   954
	_asm pop ecx					// this back into ecx
sl@0
   955
	_asm ror eax, 16				// sign/exponent into normal positions
sl@0
   956
	_asm mov [ecx+4], edx			// store mantissa high word
sl@0
   957
	_asm mov [ecx+8], eax			// store sign/exponent
sl@0
   958
	_asm xor eax, eax
sl@0
   959
	_asm mov [ecx], eax				// zero mantissa low word
sl@0
   960
	_asm ret 4						// return KErrNone
sl@0
   961
	trealxfromint0:
sl@0
   962
	_asm mov [ecx], edx
sl@0
   963
	_asm mov [ecx+4], edx			// store mantissa high word=0
sl@0
   964
	_asm mov [ecx+8], edx			// store sign/exponent=0
sl@0
   965
	_asm xor eax, eax				// return KErrNone
sl@0
   966
	_asm ret 4
sl@0
   967
	}
sl@0
   968
sl@0
   969
sl@0
   970
sl@0
   971
sl@0
   972
__NAKED__ EXPORT_C TInt TRealX::Set(TUint /*aInt*/)
sl@0
   973
/**
sl@0
   974
Gives this extended precision object a new value taken from
sl@0
   975
an unsigned integer.
sl@0
   976
sl@0
   977
@param aInt The unsigned integer value.
sl@0
   978
sl@0
   979
@return KErrNone, always.
sl@0
   980
*/
sl@0
   981
	{
sl@0
   982
	// on entry ecx=this, [esp+4]=aInt, return code in eax
sl@0
   983
	_asm mov edx, [esp+4]		// edx=aInt
sl@0
   984
	_asm mov eax, 0x7FFF
sl@0
   985
	_asm or edx, edx				// test for 0
sl@0
   986
	_asm jz short trealxfromuint0	// branch if 0
sl@0
   987
	_asm push ecx					// save this
sl@0
   988
	_asm bsr ecx, edx				// bit number of edx MSB into ecx
sl@0
   989
	_asm add eax, ecx				// add to eax to form result exponent
sl@0
   990
	_asm neg cl
sl@0
   991
	_asm add cl, 31					// 31-bit number = number of shifts to normalise edx
sl@0
   992
	_asm shl edx, cl				// normalise edx
sl@0
   993
	_asm pop ecx					// this back into ecx
sl@0
   994
	_asm shl eax, 16				// exponent into normal position
sl@0
   995
	_asm mov [ecx+4], edx			// store mantissa high word
sl@0
   996
	_asm mov [ecx+8], eax			// store exponent
sl@0
   997
	_asm xor eax, eax
sl@0
   998
	_asm mov [ecx], eax				// zero mantissa low word
sl@0
   999
	_asm ret 4						// return KErrNone
sl@0
  1000
	trealxfromuint0:
sl@0
  1001
	_asm mov [ecx], edx
sl@0
  1002
	_asm mov [ecx+4], edx			// store mantissa high word=0
sl@0
  1003
	_asm mov [ecx+8], edx			// store sign/exponent=0
sl@0
  1004
	_asm xor eax, eax				// return KErrNone
sl@0
  1005
	_asm ret 4
sl@0
  1006
	}
sl@0
  1007
sl@0
  1008
sl@0
  1009
sl@0
  1010
sl@0
  1011
__NAKED__ LOCAL_C void TRealXFromTInt64(void)
sl@0
  1012
	{
sl@0
  1013
	// Convert TInt64 in edx:ebx to TRealX in ecx,edx:ebx
sl@0
  1014
	_asm mov eax, 0x7FFF
sl@0
  1015
	_asm or edx, edx				// test sign/zero
sl@0
  1016
	_asm jz short trealxfromtint64a	// branch if top word zero
sl@0
  1017
	_asm jns short trealxfromtint64b
sl@0
  1018
	_asm add eax, 0x10000			// sign bit into eax bit 16
sl@0
  1019
	_asm neg edx					// take absolute value
sl@0
  1020
	_asm neg ebx
sl@0
  1021
	_asm sbb edx, 0
sl@0
  1022
	_asm jz short trealxfromtint64d	// branch if top word zero
sl@0
  1023
	trealxfromtint64b:
sl@0
  1024
	_asm bsr ecx, edx				// ecx=bit number of edx MSB
sl@0
  1025
	_asm add eax, ecx				// add to exponent in eax
sl@0
  1026
	_asm add eax, 32
sl@0
  1027
	_asm neg cl
sl@0
  1028
	_asm add cl, 31					// 31-bit number = number of left shifts to normalise
sl@0
  1029
	_asm shld edx, ebx, cl			// shift left to normalise edx:ebx
sl@0
  1030
	_asm shl ebx, cl
sl@0
  1031
	_asm mov ecx, eax				// sign/exponent into ecx
sl@0
  1032
	_asm ror ecx, 16				// and into normal positions
sl@0
  1033
	_asm ret
sl@0
  1034
	trealxfromtint64a:				// come here if top word zero
sl@0
  1035
	_asm or ebx, ebx				// test for bottom word also zero
sl@0
  1036
	_asm jz short trealxfromtint64c	// branch if it is
sl@0
  1037
	trealxfromtint64d:				// come here if top word zero, bottom word not
sl@0
  1038
	_asm mov edx, ebx				// shift edx:ebx left 32
sl@0
  1039
	_asm xor ebx, ebx
sl@0
  1040
	_asm bsr ecx, edx				// ecx=bit number of edx MSB
sl@0
  1041
	_asm add eax, ecx				// add to exponent in eax
sl@0
  1042
	_asm neg cl
sl@0
  1043
	_asm add cl, 31					// 31-bit number = number of left shifts to normalise
sl@0
  1044
	_asm shl edx, cl				// normalise
sl@0
  1045
	_asm mov ecx, eax				// sign/exponent into ecx
sl@0
  1046
	_asm ror ecx, 16				// and into normal positions
sl@0
  1047
	_asm ret
sl@0
  1048
	trealxfromtint64c:				// entire number is zero
sl@0
  1049
	_asm xor ecx, ecx
sl@0
  1050
	_asm ret
sl@0
  1051
	}
sl@0
  1052
sl@0
  1053
sl@0
  1054
sl@0
  1055
sl@0
  1056
__NAKED__ EXPORT_C TInt TRealX::Set(const TInt64& /*aInt*/)
sl@0
  1057
/**
sl@0
  1058
Gives this extended precision object a new value taken from
sl@0
  1059
a 64 bit integer.
sl@0
  1060
sl@0
  1061
@param aInt The 64 bit integer value.
sl@0
  1062
sl@0
  1063
@return KErrNone, always.
sl@0
  1064
*/
sl@0
  1065
	{
sl@0
  1066
	// on entry ecx=this, [esp+4]=address of aInt, return code in eax
sl@0
  1067
	_asm push ebx
sl@0
  1068
	_asm push ecx
sl@0
  1069
	_asm mov edx, [esp+12]		// edx=address of aInt
sl@0
  1070
	_asm mov ebx, [edx]
sl@0
  1071
	_asm mov edx, [edx+4]		// edx:ebx=aInt
sl@0
  1072
	_asm call TRealXFromTInt64	// convert to TRealX in ecx,edx:ebx
sl@0
  1073
	_asm pop eax				// eax=this
sl@0
  1074
	_asm mov [eax], ebx			// store result
sl@0
  1075
	_asm mov [eax+4], edx
sl@0
  1076
	_asm mov [eax+8], ecx
sl@0
  1077
	_asm xor eax, eax			// return KErrNone
sl@0
  1078
	_asm pop ebx
sl@0
  1079
	_asm ret 4
sl@0
  1080
	}
sl@0
  1081
sl@0
  1082
sl@0
  1083
sl@0
  1084
sl@0
  1085
__NAKED__ LOCAL_C void __6TRealXi()
sl@0
  1086
	{
sl@0
  1087
	// common function for int to TRealX
sl@0
  1088
	_asm mov edx, [esp+4]		// edx=aInt
sl@0
  1089
	_asm or edx, edx			// test sign/zero
sl@0
  1090
	_asm mov eax, 0x7FFF
sl@0
  1091
	_asm jz short trealxfromint0	// branch if 0
sl@0
  1092
	_asm jns short trealxfromint1	// skip if positive
sl@0
  1093
	_asm neg edx					// take absolute value
sl@0
  1094
	_asm add eax, 0x10000			// sign bit in eax bit 16
sl@0
  1095
	trealxfromint1:
sl@0
  1096
	_asm push ecx					// save this
sl@0
  1097
	_asm bsr ecx, edx				// bit number of edx MSB into ecx
sl@0
  1098
	_asm add eax, ecx				// add to eax to form result exponent
sl@0
  1099
	_asm neg cl
sl@0
  1100
	_asm add cl, 31					// 31-bit number = number of shifts to normalise edx
sl@0
  1101
	_asm shl edx, cl				// normalise edx
sl@0
  1102
	_asm pop ecx					// this back into ecx
sl@0
  1103
	_asm ror eax, 16				// sign/exponent into normal positions
sl@0
  1104
	_asm mov [ecx+4], edx			// store mantissa high word
sl@0
  1105
	_asm mov [ecx+8], eax			// store sign/exponent
sl@0
  1106
	_asm xor eax, eax
sl@0
  1107
	_asm mov [ecx], eax				// zero mantissa low word
sl@0
  1108
	_asm mov eax, ecx				// return eax=this
sl@0
  1109
	_asm ret 4
sl@0
  1110
	trealxfromint0:
sl@0
  1111
	_asm mov [ecx], edx
sl@0
  1112
	_asm mov [ecx+4], edx			// store mantissa high word=0
sl@0
  1113
	_asm mov [ecx+8], edx			// store sign/exponent=0
sl@0
  1114
	_asm mov eax, ecx				// return eax=this
sl@0
  1115
	_asm ret 4
sl@0
  1116
	}
sl@0
  1117
sl@0
  1118
sl@0
  1119
sl@0
  1120
sl@0
  1121
__NAKED__ EXPORT_C TRealX::TRealX(TInt /*aInt*/)
sl@0
  1122
/**
sl@0
  1123
Constructs an extended precision object from a signed integer value.
sl@0
  1124
sl@0
  1125
@param aInt The signed integer value.
sl@0
  1126
*/
sl@0
  1127
	{
sl@0
  1128
	// on entry ecx=this, [esp+4]=aInt, return eax=this
sl@0
  1129
	_asm jmp __6TRealXi
sl@0
  1130
	}
sl@0
  1131
sl@0
  1132
sl@0
  1133
sl@0
  1134
sl@0
  1135
__NAKED__ EXPORT_C TRealX& TRealX::operator=(TInt /*aInt*/)
sl@0
  1136
/**
sl@0
  1137
Assigns the specified signed integer value to this extended precision object.
sl@0
  1138
sl@0
  1139
@param aInt The signed integer value.
sl@0
  1140
sl@0
  1141
@return A reference to this extended precision object.
sl@0
  1142
*/
sl@0
  1143
	{
sl@0
  1144
	// on entry ecx=this, [esp+4]=aInt, return eax=this
sl@0
  1145
	_asm jmp __6TRealXi
sl@0
  1146
	}
sl@0
  1147
sl@0
  1148
sl@0
  1149
sl@0
  1150
sl@0
  1151
__NAKED__ LOCAL_C void __6TRealXui()
sl@0
  1152
	{
sl@0
  1153
	// common function for unsigned int to TRealX
sl@0
  1154
	_asm mov edx, [esp+4]		// edx=aInt
sl@0
  1155
	_asm mov eax, 0x7FFF
sl@0
  1156
	_asm or edx, edx				// test for zero
sl@0
  1157
	_asm jz short trealxfromuint0	// branch if 0
sl@0
  1158
	_asm push ecx					// save this
sl@0
  1159
	_asm bsr ecx, edx				// bit number of edx MSB into ecx
sl@0
  1160
	_asm add eax, ecx				// add to eax to form result exponent
sl@0
  1161
	_asm neg cl
sl@0
  1162
	_asm add cl, 31					// 31-bit number = number of shifts to normalise edx
sl@0
  1163
	_asm shl edx, cl				// normalise edx
sl@0
  1164
	_asm pop ecx					// this back into ecx
sl@0
  1165
	_asm shl eax, 16				// exponent into normal position
sl@0
  1166
	_asm mov [ecx+4], edx			// store mantissa high word
sl@0
  1167
	_asm mov [ecx+8], eax			// store exponent
sl@0
  1168
	_asm xor eax, eax
sl@0
  1169
	_asm mov [ecx], eax				// zero mantissa low word
sl@0
  1170
	_asm mov eax, ecx				// return eax=this
sl@0
  1171
	_asm ret 4
sl@0
  1172
	trealxfromuint0:
sl@0
  1173
	_asm mov [ecx], edx
sl@0
  1174
	_asm mov [ecx+4], edx			// store mantissa high word=0
sl@0
  1175
	_asm mov [ecx+8], edx			// store sign/exponent=0
sl@0
  1176
	_asm mov eax, ecx				// return eax=this
sl@0
  1177
	_asm ret 4
sl@0
  1178
	}
sl@0
  1179
sl@0
  1180
sl@0
  1181
sl@0
  1182
sl@0
  1183
__NAKED__ EXPORT_C TRealX::TRealX(TUint /*aInt*/)
sl@0
  1184
/**
sl@0
  1185
Constructs an extended precision object from an unsigned integer value.
sl@0
  1186
sl@0
  1187
@param aInt The unsigned integer value.
sl@0
  1188
*/
sl@0
  1189
	{
sl@0
  1190
	// on entry ecx=this, [esp+4]=aInt, return eax=this
sl@0
  1191
	_asm jmp __6TRealXui
sl@0
  1192
	}
sl@0
  1193
sl@0
  1194
sl@0
  1195
sl@0
  1196
sl@0
  1197
__NAKED__ EXPORT_C TRealX& TRealX::operator=(TUint /*aInt*/)
sl@0
  1198
/**
sl@0
  1199
Assigns the specified unsigned integer value to this extended precision object.
sl@0
  1200
sl@0
  1201
@param aInt The unsigned integer value.
sl@0
  1202
sl@0
  1203
@return A reference to this extended precision object.
sl@0
  1204
*/
sl@0
  1205
	{
sl@0
  1206
	// on entry ecx=this, [esp+4]=aInt, return eax=this
sl@0
  1207
	_asm jmp __6TRealXui
sl@0
  1208
	}
sl@0
  1209
sl@0
  1210
sl@0
  1211
sl@0
  1212
sl@0
  1213
__NAKED__ LOCAL_C void __6TRealXRC6TInt64()
sl@0
  1214
	{
sl@0
  1215
	// common function for TInt64 to TRealX
sl@0
  1216
	_asm push ebx				// preserve ebx
sl@0
  1217
	_asm push ecx				// save this
sl@0
  1218
	_asm mov edx, [esp+12]		// edx=address of aInt
sl@0
  1219
	_asm mov ebx, [edx]
sl@0
  1220
	_asm mov edx, [edx+4]		// edx:ebx=aInt
sl@0
  1221
	_asm call TRealXFromTInt64	// convert to TRealX in ecx,edx:ebx
sl@0
  1222
	_asm pop eax				// eax=this
sl@0
  1223
	_asm mov [eax], ebx			// store result
sl@0
  1224
	_asm mov [eax+4], edx
sl@0
  1225
	_asm mov [eax+8], ecx
sl@0
  1226
	_asm pop ebx				// restore ebx
sl@0
  1227
	_asm ret 4					// return this in eax
sl@0
  1228
	}
sl@0
  1229
sl@0
  1230
sl@0
  1231
sl@0
  1232
sl@0
  1233
__NAKED__ EXPORT_C TRealX::TRealX(const TInt64& /*aInt*/)
sl@0
  1234
/**
sl@0
  1235
Constructs an extended precision object from a 64 bit integer.
sl@0
  1236
sl@0
  1237
@param aInt A reference to a 64 bit integer. 
sl@0
  1238
*/
sl@0
  1239
	{
sl@0
  1240
	// on entry ecx=this, [esp+4]=address of aInt, return eax=this
sl@0
  1241
	_asm jmp __6TRealXRC6TInt64
sl@0
  1242
	}
sl@0
  1243
sl@0
  1244
sl@0
  1245
sl@0
  1246
sl@0
  1247
__NAKED__ EXPORT_C TRealX& TRealX::operator=(const TInt64& /*aInt*/)
sl@0
  1248
/**
sl@0
  1249
Assigns the specified 64 bit integer value to this extended precision object.
sl@0
  1250
sl@0
  1251
@param aInt A reference to a 64 bit integer. 
sl@0
  1252
sl@0
  1253
@return A reference to this extended precision object.
sl@0
  1254
*/
sl@0
  1255
	{
sl@0
  1256
	// on entry ecx=this, [esp+4]=address of aInt, return eax=this
sl@0
  1257
	_asm jmp __6TRealXRC6TInt64
sl@0
  1258
	}
sl@0
  1259
sl@0
  1260
sl@0
  1261
sl@0
  1262
sl@0
  1263
__NAKED__ LOCAL_C void ConvertTReal32ToTRealX(void)
sl@0
  1264
	{
sl@0
  1265
	// Convert TReal32 in edx to TRealX in ecx:edx,ebx
sl@0
  1266
	_asm xor ebx, ebx			// mant low always zero
sl@0
  1267
	_asm mov eax, edx
sl@0
  1268
	_asm shr eax, 23			// exponent now in al, sign in ah bit 0
sl@0
  1269
	_asm test al, al			// check for denormal/zero
sl@0
  1270
	_asm jz short treal32totrealx2	// branch if denormal/zero
sl@0
  1271
	_asm xor ecx, ecx
sl@0
  1272
	_asm mov cl, al
sl@0
  1273
	_asm add ecx, 0x7F80		// bias exponent correctly for TRealX
sl@0
  1274
	_asm cmp al, 0xFF			// check for infinity/NaN
sl@0
  1275
	_asm jnz short treal32totrealx1	// skip if neither
sl@0
  1276
	_asm mov cl, al				// else set TRealX exponent to FFFF
sl@0
  1277
	_asm mov ch, al
sl@0
  1278
	treal32totrealx1:
sl@0
  1279
	_asm shl edx, 8				// left-justify mantissa in edx
sl@0
  1280
	_asm or edx, 0x80000000		// put in implied integer bit
sl@0
  1281
	_asm shl ecx, 16			// exponent into ecx bits 16-31
sl@0
  1282
	_asm mov cl, ah				// sign into ecx bit 0
sl@0
  1283
	_asm ret
sl@0
  1284
	treal32totrealx2:			// come here if exponent 0
sl@0
  1285
	_asm shl edx, 9				// left-justify mantissa in edx (shift out integer bit as well)
sl@0
  1286
	_asm jnz short treal32totrealx3	// jump if denormal
sl@0
  1287
	_asm xor ecx, ecx			// else return 0
sl@0
  1288
	_asm mov cl, ah				// with same sign as input value
sl@0
  1289
	_asm ret
sl@0
  1290
	treal32totrealx3:			// come here if denormal
sl@0
  1291
	_asm bsr ecx, edx			// ecx=bit number of MSB of edx
sl@0
  1292
	_asm neg ecx
sl@0
  1293
	_asm add ecx, 31			// ecx=number of left shifts to normalise edx
sl@0
  1294
	_asm shl edx, cl			// normalise
sl@0
  1295
	_asm neg ecx
sl@0
  1296
	_asm add ecx, 0x7F80			// exponent=7F80-number of shifts
sl@0
  1297
	_asm shl ecx, 16			// exponent into ecx bits 16-31
sl@0
  1298
	_asm mov cl, ah				// sign into ecx bit 0
sl@0
  1299
	_asm ret
sl@0
  1300
	}
sl@0
  1301
sl@0
  1302
__NAKED__ LOCAL_C void ConvertTReal64ToTRealX(void)
sl@0
  1303
	{
sl@0
  1304
	// Convert TReal64 in edx:ebx to TRealX in ecx:edx,ebx
sl@0
  1305
	_asm mov eax, edx
sl@0
  1306
	_asm shr eax, 20
sl@0
  1307
	_asm mov ecx, 0x7FF
sl@0
  1308
	_asm and ecx, eax				// ecx=exponent
sl@0
  1309
	_asm jz short treal64totrealx1	// branch if zero/denormal
sl@0
  1310
	_asm add ecx, 0x7C00			// else bias exponent correctly for TRealX
sl@0
  1311
	_asm cmp ecx, 0x83FF			// check for infinity/NaN
sl@0
  1312
	_asm jnz short treal64totrealx2
sl@0
  1313
	_asm mov ch, cl					// if so, set exponent to FFFF
sl@0
  1314
	treal64totrealx2:
sl@0
  1315
	_asm shl ecx, 16				// exponent into ecx bits 16-31
sl@0
  1316
	_asm mov cl, 11					// number of shifts needed to justify mantissa correctly
sl@0
  1317
	_asm shld edx, ebx, cl			// shift mantissa left
sl@0
  1318
	_asm shl ebx, cl
sl@0
  1319
	_asm or edx, 0x80000000			// put in implied integer bit
sl@0
  1320
	_asm shr eax, 11				// sign bit into al bit 0
sl@0
  1321
	_asm mov cl, al					// into ecx bit 0
sl@0
  1322
	_asm ret
sl@0
  1323
	treal64totrealx1:				// come here if zero/denormal
sl@0
  1324
	_asm mov cl, 12					// number of shifts needed to justify mantissa correctly
sl@0
  1325
	_asm shld edx, ebx, cl			// shift mantissa left
sl@0
  1326
	_asm shl ebx, cl
sl@0
  1327
	_asm test edx, edx				// check for zero
sl@0
  1328
	_asm jnz short treal64totrealx3
sl@0
  1329
	_asm test ebx, ebx
sl@0
  1330
	_asm jnz short treal64totrealx4
sl@0
  1331
	_asm shr eax, 11				// sign bit into eax bit 0, rest of eax=0
sl@0
  1332
	_asm mov ecx, eax				// return 0 result with correct sign
sl@0
  1333
	_asm ret
sl@0
  1334
	treal64totrealx4:				// come here if denormal, edx=0
sl@0
  1335
	_asm mov edx, ebx				// shift mantissa left 32
sl@0
  1336
	_asm xor ebx, ebx
sl@0
  1337
	_asm bsr ecx, edx				// ecx=bit number of MSB of edx
sl@0
  1338
	_asm neg ecx
sl@0
  1339
	_asm add ecx, 31				// ecx=number of left shifts to normalise edx
sl@0
  1340
	_asm shl edx, cl				// normalise
sl@0
  1341
	_asm neg ecx
sl@0
  1342
	_asm add ecx, 0x7BE0			// exponent=7BE0-number of shifts
sl@0
  1343
	_asm shl ecx, 16				// exponent into bits 16-31 of ecx
sl@0
  1344
	_asm shr eax, 11
sl@0
  1345
	_asm mov cl, al					// sign into bit 0 of ecx
sl@0
  1346
	_asm ret
sl@0
  1347
	treal64totrealx3:				// come here if denormal, edx nonzero
sl@0
  1348
	_asm bsr ecx, edx				// ecx=bit number of MSB of edx
sl@0
  1349
	_asm neg ecx
sl@0
  1350
	_asm add ecx, 31				// ecx=number of left shifts to normalise edx:ebx
sl@0
  1351
	_asm shld edx, ebx, cl			// normalise
sl@0
  1352
	_asm shl ebx, cl
sl@0
  1353
	_asm neg ecx
sl@0
  1354
	_asm add ecx, 0x7C00				// exponent=7C00-number of shifts
sl@0
  1355
	_asm shl ecx, 16				// exponent into bits 16-31 of ecx
sl@0
  1356
	_asm shr eax, 11
sl@0
  1357
	_asm mov cl, al					// sign into bit 0 of ecx
sl@0
  1358
	_asm ret
sl@0
  1359
	}
sl@0
  1360
sl@0
  1361
sl@0
  1362
sl@0
  1363
sl@0
  1364
__NAKED__ EXPORT_C TInt TRealX::Set(TReal32 /*aReal*/)
sl@0
  1365
/**
sl@0
  1366
Gives this extended precision object a new value taken from
sl@0
  1367
a single precision floating point number.
sl@0
  1368
sl@0
  1369
@param aReal The single precision floating point value. 
sl@0
  1370
sl@0
  1371
@return KErrNone, if a valid number;
sl@0
  1372
        KErrOverflow, if the number is infinite;
sl@0
  1373
        KErrArgument, if not a number.
sl@0
  1374
*/
sl@0
  1375
	{
sl@0
  1376
	// on entry, ecx=this and aReal is in [esp+4]
sl@0
  1377
	// on exit, error code in eax
sl@0
  1378
	_asm push ebx					// save ebx
sl@0
  1379
	_asm push ecx					// save this
sl@0
  1380
	_asm mov edx, [esp+12]			// aReal into edx
sl@0
  1381
	_asm call ConvertTReal32ToTRealX
sl@0
  1382
	_asm pop eax					// eax=this
sl@0
  1383
	_asm mov [eax], ebx				// store result
sl@0
  1384
	_asm mov [eax+4], edx
sl@0
  1385
	_asm mov [eax+8], ecx
sl@0
  1386
	_asm xor eax, eax				// error code=KErrNone initially
sl@0
  1387
	_asm cmp ecx, 0xFFFF0000		// check for infinity/NaN
sl@0
  1388
	_asm jb short trealxsettreal32a	// if neither, return KErrNone
sl@0
  1389
	_asm mov eax, -9				// eax=KErrOverflow
sl@0
  1390
	_asm cmp edx, 0x80000000			// check for infinity
sl@0
  1391
	_asm je short trealxsettreal32a	// if infinity, return KErrOverflow
sl@0
  1392
	_asm mov eax, -6				// if NaN, return KErrArgument
sl@0
  1393
	trealxsettreal32a:
sl@0
  1394
	_asm pop ebx
sl@0
  1395
	_asm ret 4
sl@0
  1396
	}
sl@0
  1397
sl@0
  1398
sl@0
  1399
sl@0
  1400
sl@0
  1401
__NAKED__ EXPORT_C TInt TRealX::Set(TReal64 /*aReal*/)
sl@0
  1402
/**
sl@0
  1403
Gives this extended precision object a new value taken from
sl@0
  1404
a double precision floating point number.
sl@0
  1405
sl@0
  1406
@param aReal The double precision floating point value. 
sl@0
  1407
sl@0
  1408
@return KErrNone, if a valid number;
sl@0
  1409
        KErrOverflow, if the number is infinite;
sl@0
  1410
        KErrArgument, if not a number.
sl@0
  1411
*/
sl@0
  1412
	{
sl@0
  1413
	// on entry, ecx=this and aReal is in [esp+4] (mant low) and [esp+8] (sign/exp/mant high)
sl@0
  1414
	// on exit, error code in eax
sl@0
  1415
	_asm push ebx				// save ebx
sl@0
  1416
	_asm push ecx				// save this
sl@0
  1417
	_asm mov ebx, [esp+12]		// aReal into edx:ebx
sl@0
  1418
	_asm mov edx, [esp+16]
sl@0
  1419
	_asm call ConvertTReal64ToTRealX
sl@0
  1420
	_asm pop eax				// eax=this
sl@0
  1421
	_asm mov [eax], ebx			// store result
sl@0
  1422
	_asm mov [eax+4], edx
sl@0
  1423
	_asm mov [eax+8], ecx
sl@0
  1424
	_asm xor eax, eax				// error code=KErrNone initially
sl@0
  1425
	_asm cmp ecx, 0xFFFF0000		// check for infinity/NaN
sl@0
  1426
	_asm jb short trealxsettreal64a	// if neither, return KErrNone
sl@0
  1427
	_asm mov eax, -9				// eax=KErrOverflow
sl@0
  1428
	_asm cmp edx, 0x80000000			// check for infinity
sl@0
  1429
	_asm jne short trealxsettreal64b	// branch if NaN
sl@0
  1430
	_asm test ebx, ebx
sl@0
  1431
	_asm je short trealxsettreal64a		// if infinity, return KErrOverflow
sl@0
  1432
	trealxsettreal64b:
sl@0
  1433
	_asm mov eax, -6				// if NaN, return KErrArgument
sl@0
  1434
	trealxsettreal64a:
sl@0
  1435
	_asm pop ebx
sl@0
  1436
	_asm ret 8
sl@0
  1437
	}
sl@0
  1438
sl@0
  1439
sl@0
  1440
sl@0
  1441
sl@0
  1442
__NAKED__ LOCAL_C void __6TRealXf()
sl@0
  1443
	{
sl@0
  1444
	// common function for float to TRealX
sl@0
  1445
	_asm push ebx				// save ebx
sl@0
  1446
	_asm push ecx				// save this
sl@0
  1447
	_asm mov edx, [esp+12]		// aReal into edx
sl@0
  1448
	_asm call ConvertTReal32ToTRealX
sl@0
  1449
	_asm pop eax				// eax=this
sl@0
  1450
	_asm mov [eax], ebx			// store result
sl@0
  1451
	_asm mov [eax+4], edx
sl@0
  1452
	_asm mov [eax+8], ecx
sl@0
  1453
	_asm pop ebx
sl@0
  1454
	_asm ret 4
sl@0
  1455
	}
sl@0
  1456
sl@0
  1457
sl@0
  1458
sl@0
  1459
sl@0
  1460
__NAKED__ EXPORT_C TRealX::TRealX(TReal32 /*aReal*/)
sl@0
  1461
/**
sl@0
  1462
Constructs an extended precision object from
sl@0
  1463
a single precision floating point number.
sl@0
  1464
sl@0
  1465
@param aReal The single precision floating point value.
sl@0
  1466
*/
sl@0
  1467
	{
sl@0
  1468
	// on entry, ecx=this and aReal is in [esp+4]
sl@0
  1469
	// on exit, eax=this
sl@0
  1470
	_asm jmp __6TRealXf
sl@0
  1471
	}
sl@0
  1472
sl@0
  1473
sl@0
  1474
sl@0
  1475
sl@0
  1476
__NAKED__ EXPORT_C TRealX& TRealX::operator=(TReal32 /*aReal*/)
sl@0
  1477
/**
sl@0
  1478
Assigns the specified single precision floating point number to
sl@0
  1479
this extended precision object.
sl@0
  1480
sl@0
  1481
@param aReal The single precision floating point value.
sl@0
  1482
sl@0
  1483
@return A reference to this extended precision object.
sl@0
  1484
*/
sl@0
  1485
	{
sl@0
  1486
	// on entry, ecx=this and aReal is in [esp+4]
sl@0
  1487
	// on exit, eax=this
sl@0
  1488
	_asm jmp __6TRealXf
sl@0
  1489
	}
sl@0
  1490
sl@0
  1491
sl@0
  1492
sl@0
  1493
sl@0
  1494
__NAKED__ LOCAL_C void __6TRealXd()
sl@0
  1495
	{
sl@0
  1496
	// common function for double to TRealX
sl@0
  1497
	_asm push ebx				// save ebx
sl@0
  1498
	_asm push ecx				// save this
sl@0
  1499
	_asm mov ebx, [esp+12]		// aReal into edx:ebx
sl@0
  1500
	_asm mov edx, [esp+16]
sl@0
  1501
	_asm call ConvertTReal64ToTRealX
sl@0
  1502
	_asm pop eax				// eax=this
sl@0
  1503
	_asm mov [eax], ebx			// store result
sl@0
  1504
	_asm mov [eax+4], edx
sl@0
  1505
	_asm mov [eax+8], ecx
sl@0
  1506
	_asm pop ebx
sl@0
  1507
	_asm ret 8
sl@0
  1508
	}
sl@0
  1509
sl@0
  1510
sl@0
  1511
sl@0
  1512
sl@0
  1513
__NAKED__ EXPORT_C TRealX::TRealX(TReal64 /*aReal*/)
sl@0
  1514
/**
sl@0
  1515
Constructs an extended precision object from
sl@0
  1516
a double precision floating point number.
sl@0
  1517
sl@0
  1518
@param aReal The double precision floating point value.
sl@0
  1519
*/
sl@0
  1520
	{
sl@0
  1521
	// on entry, ecx=this and aReal is in [esp+4] (mant low) and [esp+8] (sign/exp/mant high)
sl@0
  1522
	// on exit, eax=this
sl@0
  1523
	_asm jmp __6TRealXd
sl@0
  1524
	}
sl@0
  1525
sl@0
  1526
sl@0
  1527
sl@0
  1528
sl@0
  1529
__NAKED__ EXPORT_C TRealX& TRealX::operator=(TReal64 /*aReal*/)
sl@0
  1530
/**
sl@0
  1531
Assigns the specified double precision floating point number to
sl@0
  1532
this extended precision object.
sl@0
  1533
sl@0
  1534
@param aReal The double precision floating point value.
sl@0
  1535
sl@0
  1536
@return A reference to this extended precision object.
sl@0
  1537
*/
sl@0
  1538
	{
sl@0
  1539
	// on entry, ecx=this and aReal is in [esp+4] (mant low) and [esp+8] (sign/exp/mant high)
sl@0
  1540
	// on exit, eax=this
sl@0
  1541
	_asm jmp __6TRealXd
sl@0
  1542
	}
sl@0
  1543
sl@0
  1544
sl@0
  1545
sl@0
  1546
sl@0
  1547
__NAKED__ EXPORT_C TRealX::operator TInt() const
sl@0
  1548
/**
sl@0
  1549
Gets the extended precision value as a signed integer value.
sl@0
  1550
sl@0
  1551
The operator returns:
sl@0
  1552
sl@0
  1553
1. zero , if the extended precision value is not a number
sl@0
  1554
sl@0
  1555
2. 0x7FFFFFFF, if the value is positive and too big to fit into a TInt.
sl@0
  1556
sl@0
  1557
3. 0x80000000, if the value is negative and too big to fit into a TInt.
sl@0
  1558
*/
sl@0
  1559
	{
sl@0
  1560
	// on entry ecx=this, return value in eax
sl@0
  1561
	_asm mov edx, [ecx]			// edx=mantissa low
sl@0
  1562
	_asm mov eax, [ecx+4]		// eax=mantissa high
sl@0
  1563
	_asm mov ecx, [ecx+8]		// ecx=exponent/sign
sl@0
  1564
	_asm ror ecx, 16			// exponent into cx
sl@0
  1565
	_asm cmp cx, 0xFFFF
sl@0
  1566
	_asm jz short trealxtoint1	// branch if exp=FFFF
sl@0
  1567
	_asm mov dx, cx
sl@0
  1568
	_asm mov cx, 0x801E
sl@0
  1569
	_asm sub cx, dx				// cx=number of right shifts needed to convert mantissa to int
sl@0
  1570
	_asm jbe short trealxtoint2	// if exp>=801E, saturate result
sl@0
  1571
	_asm cmp cx, 31				// more than 31 shifts needed?
sl@0
  1572
	_asm ja short trealxtoint0	// if so, underflow to zero
sl@0
  1573
	_asm shr eax, cl			// else ABS(result)=eax>>cl
sl@0
  1574
	_asm test ecx, 0x10000		// test sign
sl@0
  1575
	_asm jz short trealxtoint3	// skip if +
sl@0
  1576
	_asm neg eax
sl@0
  1577
	trealxtoint3:
sl@0
  1578
	_asm ret
sl@0
  1579
	trealxtoint1:			// come here if exponent=FFFF
sl@0
  1580
	_asm cmp eax, 0x80000000		// check for infinity
sl@0
  1581
	_asm jnz short trealxtoint0	// if NaN, return 0
sl@0
  1582
	_asm test edx, edx
sl@0
  1583
	_asm jnz short trealxtoint0	// if NaN, return 0
sl@0
  1584
	trealxtoint2:			// come here if argument too big for 32-bit integer
sl@0
  1585
	_asm mov eax, 0x7FFFFFFF
sl@0
  1586
	_asm shr ecx, 17			// sign bit into carry flag
sl@0
  1587
	_asm adc eax, 0				// eax=7FFFFFFF if +, 80000000 if -
sl@0
  1588
	_asm ret					// return saturated value
sl@0
  1589
	trealxtoint0:			// come here if INT(argument)=0 or NaN
sl@0
  1590
	_asm xor eax, eax			// return 0
sl@0
  1591
	_asm ret
sl@0
  1592
	}
sl@0
  1593
sl@0
  1594
sl@0
  1595
sl@0
  1596
sl@0
  1597
__NAKED__ EXPORT_C TRealX::operator TUint() const
sl@0
  1598
/**
sl@0
  1599
Returns the extended precision value as an unsigned signed integer value.
sl@0
  1600
sl@0
  1601
The operator returns:
sl@0
  1602
sl@0
  1603
1. zero, if the extended precision value is not a number
sl@0
  1604
sl@0
  1605
2. 0xFFFFFFFF, if the value is positive and too big to fit into a TUint.
sl@0
  1606
sl@0
  1607
3. zero, if the value is negative and too big to fit into a TUint.
sl@0
  1608
*/
sl@0
  1609
	{
sl@0
  1610
	// on entry ecx=this, return value in eax
sl@0
  1611
	_asm mov edx, [ecx]			// edx=mantissa low
sl@0
  1612
	_asm mov eax, [ecx+4]		// eax=mantissa high
sl@0
  1613
	_asm mov ecx, [ecx+8]		// ecx=exponent/sign
sl@0
  1614
	_asm ror ecx, 16			// exponent into cx
sl@0
  1615
	_asm cmp cx, 0xFFFF
sl@0
  1616
	_asm jz short trealxtouint1	// branch if exp=FFFF
sl@0
  1617
	_asm mov dx, cx
sl@0
  1618
	_asm mov cx, 0x801E
sl@0
  1619
	_asm sub cx, dx				// cx=number of right shifts needed to convert mantissa to int
sl@0
  1620
	_asm jb short trealxtouint2	// if exp>801E, saturate result
sl@0
  1621
	_asm cmp cx, 31				// more than 31 shifts needed?
sl@0
  1622
	_asm ja short trealxtouint0	// if so, underflow to zero
sl@0
  1623
	_asm test ecx, 0x10000		// test sign
sl@0
  1624
	_asm jnz short trealxtouint0	// if -, return 0
sl@0
  1625
	_asm shr eax, cl			// else result=eax>>cl
sl@0
  1626
	_asm ret
sl@0
  1627
	trealxtouint1:			// come here if exponent=FFFF
sl@0
  1628
	_asm cmp eax, 0x80000000		// check for infinity
sl@0
  1629
	_asm jnz short trealxtouint0	// if NaN, return 0
sl@0
  1630
	_asm test edx, edx
sl@0
  1631
	_asm jnz short trealxtouint0	// if NaN, return 0
sl@0
  1632
	trealxtouint2:			// come here if argument too big for 32-bit integer
sl@0
  1633
	_asm mov eax, 0xFFFFFFFF
sl@0
  1634
	_asm shr ecx, 17			// sign bit into carry flag
sl@0
  1635
	_asm adc eax, 0				// eax=FFFFFFFF if +, 0 if -
sl@0
  1636
	_asm ret					// return saturated value
sl@0
  1637
	trealxtouint0:			// come here if INT(argument)=0 or NaN
sl@0
  1638
	_asm xor eax, eax			// return 0
sl@0
  1639
	_asm ret
sl@0
  1640
	}
sl@0
  1641
sl@0
  1642
sl@0
  1643
sl@0
  1644
sl@0
  1645
__NAKED__ LOCAL_C void ConvertTRealXToTInt64(void)
sl@0
  1646
	{
sl@0
  1647
	// Convert TRealX in ecx,edx:ebx to TInt64 in edx:ebx
sl@0
  1648
	_asm ror ecx, 16				// exponent into cx
sl@0
  1649
	_asm cmp cx, 0xFFFF
sl@0
  1650
	_asm jz short trealxtoint64a	// branch if exp=FFFF
sl@0
  1651
	_asm mov ax, cx
sl@0
  1652
	_asm mov cx, 0x803E
sl@0
  1653
	_asm sub cx, ax					// cx=number of right shifts needed to convert mantissa to int
sl@0
  1654
	_asm jbe short trealxtoint64b	// if exp>=803E, saturate result
sl@0
  1655
	_asm cmp cx, 63					// more than 63 shifts needed?
sl@0
  1656
	_asm ja short trealxtoint64z	// if so, underflow to zero
sl@0
  1657
	_asm cmp cl, 31					// more than 31 shifts needed?
sl@0
  1658
	_asm jbe short trealxtoint64d	// branch if not
sl@0
  1659
	_asm sub cl, 32					// cl=shift count - 32
sl@0
  1660
	_asm mov ebx, edx				// shift right by 32
sl@0
  1661
	_asm xor edx, edx
sl@0
  1662
	trealxtoint64d:
sl@0
  1663
	_asm shrd ebx, edx, cl			// shift edx:ebx right by cl to give ABS(result)
sl@0
  1664
	_asm shr edx, cl
sl@0
  1665
	_asm test ecx, 0x10000			// test sign
sl@0
  1666
	_asm jz short trealxtoint64c	// skip if +
sl@0
  1667
	_asm neg edx					// if -, negate
sl@0
  1668
	_asm neg ebx
sl@0
  1669
	_asm sbb edx, 0
sl@0
  1670
	trealxtoint64c:
sl@0
  1671
	_asm ret
sl@0
  1672
	trealxtoint64a:			// come here if exponent=FFFF
sl@0
  1673
	_asm cmp edx, 0x80000000			// check for infinity
sl@0
  1674
	_asm jnz short trealxtoint64z	// if NaN, return 0
sl@0
  1675
	_asm test ebx, ebx
sl@0
  1676
	_asm jnz short trealxtoint64z	// if NaN, return 0
sl@0
  1677
	trealxtoint64b:			// come here if argument too big for 32-bit integer
sl@0
  1678
	_asm mov edx, 0x7FFFFFFF
sl@0
  1679
	_asm mov ebx, 0xFFFFFFFF
sl@0
  1680
	_asm shr ecx, 17				// sign bit into carry flag
sl@0
  1681
	_asm adc ebx, 0					// edx:ebx=7FFFFFFF FFFFFFFF if +,
sl@0
  1682
	_asm adc edx, 0					// or 80000000 00000000 if -
sl@0
  1683
	_asm ret						// return saturated value
sl@0
  1684
	trealxtoint64z:			// come here if INT(argument)=0 or NaN
sl@0
  1685
	_asm xor edx, edx				// return 0
sl@0
  1686
	_asm xor ebx, ebx
sl@0
  1687
	_asm ret
sl@0
  1688
	}
sl@0
  1689
sl@0
  1690
sl@0
  1691
sl@0
  1692
sl@0
  1693
/**
sl@0
  1694
Returns the extended precision value as a 64 bit integer value.
sl@0
  1695
sl@0
  1696
The operator returns:
sl@0
  1697
sl@0
  1698
1. zero, if the extended precision value is not a number
sl@0
  1699
sl@0
  1700
2. 0x7FFFFFFF FFFFFFFF, if the value is positive and too big to fit
sl@0
  1701
   into a TInt64
sl@0
  1702
sl@0
  1703
3. 0x80000000 00000000, if the value is negative and too big to fit
sl@0
  1704
   into a TInt64.
sl@0
  1705
*/
sl@0
  1706
__NAKED__ EXPORT_C TRealX::operator TInt64() const
sl@0
  1707
	{
sl@0
  1708
	// on entry, ecx=this, return value in edx:eax
sl@0
  1709
	_asm push ebx
sl@0
  1710
	_asm mov ebx, [ecx]			// get TRealX value into ecx,edx:ebx
sl@0
  1711
	_asm mov edx, [ecx+4]
sl@0
  1712
	_asm mov ecx, [ecx+8]
sl@0
  1713
	_asm call ConvertTRealXToTInt64
sl@0
  1714
	_asm mov eax, ebx			// store low result into eax
sl@0
  1715
	_asm pop ebx
sl@0
  1716
	_asm ret
sl@0
  1717
	}
sl@0
  1718
sl@0
  1719
sl@0
  1720
sl@0
  1721
sl@0
  1722
__NAKED__ LOCAL_C void TRealXGetTReal32(void)
sl@0
  1723
	{
sl@0
  1724
	// Convert TRealX in ecx,edx:ebx to TReal32 in edx
sl@0
  1725
	// Return error code in eax
sl@0
  1726
	_asm cmp ecx, 0xFFFF0000		// check for infinity/NaN
sl@0
  1727
	_asm jnc short trealxgettreal32a
sl@0
  1728
	_asm xor eax, eax
sl@0
  1729
	_asm ror ecx, 16				// exponent into cx
sl@0
  1730
	_asm sub cx, 0x7F80				// cx=result exponent if normalised
sl@0
  1731
	_asm jbe short trealxgettreal32b	// jump if denormal, zero or underflow
sl@0
  1732
	_asm cmp cx, 0xFF				// check if overflow
sl@0
  1733
	_asm jb short trealxgettreal32c	// jump if not
sl@0
  1734
	trealxgettreal32d:			// come here if overflow
sl@0
  1735
	_asm xor edx, edx				// set mantissa=0 to generate infinity
sl@0
  1736
	_asm ror ecx, 16				// ecx back to normal format
sl@0
  1737
	trealxgettreal32a:			// come here if infinity or NaN
sl@0
  1738
	_asm shr edx, 7
sl@0
  1739
	_asm or edx, 0xFF000000			// set exponent to FF
sl@0
  1740
	_asm shr ecx, 1					// sign bit -> carry
sl@0
  1741
	_asm rcr edx, 1					// sign bit -> MSB of result
sl@0
  1742
	_asm mov eax, edx
sl@0
  1743
	_asm shl eax, 9					// test for infinity or NaN
sl@0
  1744
	_asm mov eax, -9				// eax=KErrOverflow
sl@0
  1745
	_asm jz short trealxgettreal32e
sl@0
  1746
	_asm mov eax, -6				// if NaN, eax=KErrArgument
sl@0
  1747
	trealxgettreal32e:
sl@0
  1748
	_asm ret
sl@0
  1749
	trealxgettreal32b:			// come here if exponent<=7F80
sl@0
  1750
	_asm cmp cx, -24				// check for zero or total underflow
sl@0
  1751
	_asm jle short trealxgettreal32z
sl@0
  1752
	_asm neg cl
sl@0
  1753
	_asm inc cl						// cl=number of right shifts to form denormal mantissa
sl@0
  1754
	_asm shrd eax, ebx, cl			// shift mantissa right into eax
sl@0
  1755
	_asm shrd ebx, edx, cl
sl@0
  1756
	_asm shr edx, cl
sl@0
  1757
	_asm or edx, 0x80000000			// set top bit to ensure correct rounding up
sl@0
  1758
	_asm xor cl, cl					// cl=result exponent=0
sl@0
  1759
	trealxgettreal32c:			// come here if result normalised
sl@0
  1760
	_asm cmp dl, 0x80				// check rounding bits
sl@0
  1761
	_asm ja short trealxgettreal32f	// branch to round up
sl@0
  1762
	_asm jb short trealxgettreal32g	// branch to round down
sl@0
  1763
	_asm test ebx, ebx
sl@0
  1764
	_asm jnz short trealxgettreal32f	// branch to round up
sl@0
  1765
	_asm test eax, eax
sl@0
  1766
	_asm jnz short trealxgettreal32f	// branch to round up
sl@0
  1767
	_asm test ecx, 0x01000000			// check rounded-down flag
sl@0
  1768
	_asm jnz short trealxgettreal32f	// branch to round up
sl@0
  1769
	_asm test ecx, 0x02000000			// check rounded-up flag
sl@0
  1770
	_asm jnz short trealxgettreal32g	// branch to round down
sl@0
  1771
	_asm test dh, 1						// else round to even
sl@0
  1772
	_asm jz short trealxgettreal32g		// branch to round down if LSB=0
sl@0
  1773
	trealxgettreal32f:				// come here to round up
sl@0
  1774
	_asm add edx, 0x100					// increment mantissa
sl@0
  1775
	_asm jnc short trealxgettreal32g
sl@0
  1776
	_asm rcr edx, 1
sl@0
  1777
	_asm inc cl							// if carry, increment exponent
sl@0
  1778
	_asm cmp cl, 0xFF					// and check for overflow
sl@0
  1779
	_asm jz short trealxgettreal32d		// branch out if overflow
sl@0
  1780
	trealxgettreal32g:				// come here to round down
sl@0
  1781
	_asm xor dl, dl
sl@0
  1782
	_asm add edx, edx					// shift out integer bit
sl@0
  1783
	_asm mov dl, cl
sl@0
  1784
	_asm ror edx, 8						// exponent->edx bits 24-31, mantissa in 23-1
sl@0
  1785
	_asm test edx, edx					// check if underflow
sl@0
  1786
	_asm jz short trealxgettreal32h		// branch out if underflow
sl@0
  1787
	_asm shr ecx, 17					// sign bit->carry
sl@0
  1788
	_asm rcr edx, 1						// ->edx bit 31, exp->edx bits 23-30, mant->edx bits 22-0
sl@0
  1789
	_asm xor eax, eax					// return KErrNone
sl@0
  1790
	_asm ret
sl@0
  1791
	trealxgettreal32z:				// come here if zero or underflow
sl@0
  1792
	_asm xor eax, eax
sl@0
  1793
	_asm cmp cx, 0x8080					// check for zero
sl@0
  1794
	_asm jz short trealxgettreal32y		// if zero, return KErrNone
sl@0
  1795
	trealxgettreal32h:				// come here if underflow after rounding
sl@0
  1796
	_asm mov eax, -10					// eax=KErrUnderflow
sl@0
  1797
	trealxgettreal32y:
sl@0
  1798
	_asm xor edx, edx
sl@0
  1799
	_asm shr ecx, 17
sl@0
  1800
	_asm rcr edx, 1						// sign bit into edx bit 31, rest of edx=0
sl@0
  1801
	_asm ret
sl@0
  1802
	}
sl@0
  1803
sl@0
  1804
sl@0
  1805
sl@0
  1806
sl@0
  1807
__NAKED__ LOCAL_C void TRealXGetTReal64(void)
sl@0
  1808
	{
sl@0
  1809
	// Convert TRealX in ecx,edx:ebx to TReal64 in edx:ebx
sl@0
  1810
	// Return error code in eax
sl@0
  1811
	// edi, esi also modified
sl@0
  1812
	_asm ror ecx, 16				// exponent into cx
sl@0
  1813
	_asm cmp cx, 0xFFFF				// check for infinity/NaN
sl@0
  1814
	_asm jnc short trealxgettreal64a
sl@0
  1815
	_asm xor eax, eax
sl@0
  1816
	_asm xor edi, edi
sl@0
  1817
	_asm sub cx, 0x7C00				// cx=result exponent if normalised
sl@0
  1818
	_asm jbe short trealxgettreal64b	// jump if denormal, zero or underflow
sl@0
  1819
	_asm cmp cx, 0x07FF				// check if overflow
sl@0
  1820
	_asm jb short trealxgettreal64c	// jump if not
sl@0
  1821
	trealxgettreal64d:			// come here if overflow
sl@0
  1822
	_asm xor edx, edx				// set mantissa=0 to generate infinity
sl@0
  1823
	_asm xor ebx, ebx
sl@0
  1824
	trealxgettreal64a:			// come here if infinity or NaN
sl@0
  1825
	_asm mov cl, 10
sl@0
  1826
	_asm shrd ebx, edx, cl
sl@0
  1827
	_asm shr edx, cl
sl@0
  1828
	_asm or edx, 0xFFE00000			// set exponent to 7FF
sl@0
  1829
	_asm shr ecx, 17				// sign bit -> carry
sl@0
  1830
	_asm rcr edx, 1					// sign bit -> MSB of result
sl@0
  1831
	_asm rcr ebx, 1
sl@0
  1832
	_asm mov eax, edx
sl@0
  1833
	_asm shl eax, 12				// test for infinity or NaN
sl@0
  1834
	_asm mov eax, -9				// eax=KErrOverflow
sl@0
  1835
	_asm jnz short trealxgettreal64n
sl@0
  1836
	_asm test ebx, ebx
sl@0
  1837
	_asm jz short trealxgettreal64e
sl@0
  1838
	trealxgettreal64n:
sl@0
  1839
	_asm mov eax, -6				// if NaN, eax=KErrArgument
sl@0
  1840
	trealxgettreal64e:
sl@0
  1841
	_asm ret
sl@0
  1842
	trealxgettreal64b:			// come here if exponent<=7C00
sl@0
  1843
	_asm cmp cx, -53				// check for zero or total underflow
sl@0
  1844
	_asm jle trealxgettreal64z
sl@0
  1845
	_asm neg cl
sl@0
  1846
	_asm inc cl						// cl=number of right shifts to form denormal mantissa
sl@0
  1847
	_asm cmp cl, 32
sl@0
  1848
	_asm jb trealxgettreal64x
sl@0
  1849
	_asm mov eax, ebx				// if >=32 shifts, do 32 shifts and decrement count by 32
sl@0
  1850
	_asm mov ebx, edx
sl@0
  1851
	_asm xor edx, edx
sl@0
  1852
	trealxgettreal64x:
sl@0
  1853
	_asm shrd edi, eax, cl
sl@0
  1854
	_asm shrd eax, ebx, cl			// shift mantissa right into eax
sl@0
  1855
	_asm shrd ebx, edx, cl
sl@0
  1856
	_asm shr edx, cl
sl@0
  1857
	_asm or edx, 0x80000000			// set top bit to ensure correct rounding up
sl@0
  1858
	_asm xor cx, cx					// cx=result exponent=0
sl@0
  1859
	trealxgettreal64c:			// come here if result normalised
sl@0
  1860
	_asm mov esi, ebx
sl@0
  1861
	_asm and esi, 0x7FF				// esi=rounding bits
sl@0
  1862
	_asm cmp esi, 0x400				// check rounding bits
sl@0
  1863
	_asm ja short trealxgettreal64f	// branch to round up
sl@0
  1864
	_asm jb short trealxgettreal64g	// branch to round down
sl@0
  1865
	_asm test eax, eax
sl@0
  1866
	_asm jnz short trealxgettreal64f	// branch to round up
sl@0
  1867
	_asm test edi, edi
sl@0
  1868
	_asm jnz short trealxgettreal64f	// branch to round up
sl@0
  1869
	_asm test ecx, 0x01000000			// check rounded-down flag
sl@0
  1870
	_asm jnz short trealxgettreal64f	// branch to round up
sl@0
  1871
	_asm test ecx, 0x02000000			// check rounded-up flag
sl@0
  1872
	_asm jnz short trealxgettreal64g	// branch to round down
sl@0
  1873
	_asm test ebx, 0x800					// else round to even
sl@0
  1874
	_asm jz short trealxgettreal64g		// branch to round down if LSB=0
sl@0
  1875
	trealxgettreal64f:				// come here to round up
sl@0
  1876
	_asm add ebx, 0x800					// increment mantissa
sl@0
  1877
	_asm adc edx, 0
sl@0
  1878
	_asm jnc short trealxgettreal64g
sl@0
  1879
	_asm rcr edx, 1
sl@0
  1880
	_asm inc cx							// if carry, increment exponent
sl@0
  1881
	_asm cmp cx, 0x7FF					// and check for overflow
sl@0
  1882
	_asm jz trealxgettreal64d			// branch out if overflow
sl@0
  1883
	trealxgettreal64g:				// come here to round down
sl@0
  1884
	_asm xor bl, bl						// clear rounding bits
sl@0
  1885
	_asm and bh, 0xF8
sl@0
  1886
	_asm mov di, cx						// save exponent
sl@0
  1887
	_asm mov cl, 10
sl@0
  1888
	_asm and edx, 0x7FFFFFFF				// clear integer bit
sl@0
  1889
	_asm shrd ebx, edx, cl				// shift mantissa right by 10
sl@0
  1890
	_asm shr edx, cl
sl@0
  1891
	_asm shl edi, 21					// exponent into edi bits 21-31
sl@0
  1892
	_asm or edx, edi					// into edx bits 21-31
sl@0
  1893
	_asm test edx, edx					// check if underflow
sl@0
  1894
	_asm jnz short trealxgettreal64i
sl@0
  1895
	_asm test ebx, ebx
sl@0
  1896
	_asm jz short trealxgettreal64h		// branch out if underflow
sl@0
  1897
	trealxgettreal64i:
sl@0
  1898
	_asm shr ecx, 17					// sign bit->carry
sl@0
  1899
	_asm rcr edx, 1						// ->edx bit 31, exp->edx bits 20-30, mant->edx bits 20-0
sl@0
  1900
	_asm rcr ebx, 1
sl@0
  1901
	_asm xor eax, eax					// return KErrNone
sl@0
  1902
	_asm ret
sl@0
  1903
	trealxgettreal64z:				// come here if zero or underflow
sl@0
  1904
	_asm xor eax, eax
sl@0
  1905
	_asm cmp cx, 0x8400					// check for zero
sl@0
  1906
	_asm jz short trealxgettreal64y		// if zero, return KErrNone
sl@0
  1907
	trealxgettreal64h:				// come here if underflow after rounding
sl@0
  1908
	_asm mov eax, -10					// eax=KErrUnderflow
sl@0
  1909
	trealxgettreal64y:
sl@0
  1910
	_asm xor edx, edx
sl@0
  1911
	_asm xor ebx, ebx
sl@0
  1912
	_asm shr ecx, 17
sl@0
  1913
	_asm rcr edx, 1						// sign bit into edx bit 31, rest of edx=0, ebx=0
sl@0
  1914
	_asm ret
sl@0
  1915
	}
sl@0
  1916
sl@0
  1917
sl@0
  1918
sl@0
  1919
sl@0
  1920
__NAKED__ EXPORT_C TRealX::operator TReal32() const
sl@0
  1921
/**
sl@0
  1922
Returns the extended precision value as
sl@0
  1923
a single precision floating point value.
sl@0
  1924
*/
sl@0
  1925
	{
sl@0
  1926
	// On entry, ecx=this
sl@0
  1927
	// On exit, TReal32 value on top of FPU stack
sl@0
  1928
	_asm push ebx
sl@0
  1929
	_asm mov ebx, [ecx]			// *this into ecx,edx:ebx
sl@0
  1930
	_asm mov edx, [ecx+4]
sl@0
  1931
	_asm mov ecx, [ecx+8]
sl@0
  1932
	_asm call TRealXGetTReal32	// Convert to TReal32 in edx
sl@0
  1933
	_asm push edx				// push TReal32 onto stack
sl@0
  1934
	_asm fld dword ptr [esp]	// push TReal32 onto FPU stack
sl@0
  1935
	_asm pop edx
sl@0
  1936
	_asm pop ebx
sl@0
  1937
	_asm ret
sl@0
  1938
	}
sl@0
  1939
sl@0
  1940
sl@0
  1941
sl@0
  1942
sl@0
  1943
__NAKED__ EXPORT_C TRealX::operator TReal64() const
sl@0
  1944
/**
sl@0
  1945
Returns the extended precision value as
sl@0
  1946
a double precision floating point value.
sl@0
  1947
*/
sl@0
  1948
	{
sl@0
  1949
	// On entry, ecx=this
sl@0
  1950
	// On exit, TReal64 value on top of FPU stack
sl@0
  1951
	_asm push ebx
sl@0
  1952
	_asm push esi
sl@0
  1953
	_asm push edi
sl@0
  1954
	_asm mov ebx, [ecx]			// *this into ecx,edx:ebx
sl@0
  1955
	_asm mov edx, [ecx+4]
sl@0
  1956
	_asm mov ecx, [ecx+8]
sl@0
  1957
	_asm call TRealXGetTReal64	// Convert to TReal32 in edx:ebx
sl@0
  1958
	_asm push edx				// push TReal64 onto stack
sl@0
  1959
	_asm push ebx
sl@0
  1960
	_asm fld qword ptr [esp]	// push TReal64 onto FPU stack
sl@0
  1961
	_asm add esp, 8
sl@0
  1962
	_asm pop edi
sl@0
  1963
	_asm pop esi
sl@0
  1964
	_asm pop ebx
sl@0
  1965
	_asm ret
sl@0
  1966
	}
sl@0
  1967
sl@0
  1968
sl@0
  1969
sl@0
  1970
sl@0
  1971
__NAKED__ EXPORT_C TInt TRealX::GetTReal(TReal32& /*aVal*/) const
sl@0
  1972
/**
sl@0
  1973
Extracts the extended precision value as
sl@0
  1974
a single precision floating point value.
sl@0
  1975
sl@0
  1976
@param aVal A reference to a single precision object which contains
sl@0
  1977
            the result of the operation.
sl@0
  1978
sl@0
  1979
@return KErrNone, if the operation is successful;
sl@0
  1980
        KErrOverflow, if the operation results in overflow;
sl@0
  1981
        KErrUnderflow, if the operation results in underflow.
sl@0
  1982
*/
sl@0
  1983
	{
sl@0
  1984
	// On entry, ecx=this, [esp+4]=address of aVal
sl@0
  1985
	// On exit, eax=return code
sl@0
  1986
	_asm push ebx
sl@0
  1987
	_asm mov ebx, [ecx]			// *this into ecx,edx:ebx
sl@0
  1988
	_asm mov edx, [ecx+4]
sl@0
  1989
	_asm mov ecx, [ecx+8]
sl@0
  1990
	_asm call TRealXGetTReal32
sl@0
  1991
	_asm mov ecx, [esp+8]		// ecx=address of aVal
sl@0
  1992
	_asm mov [ecx], edx			// store result
sl@0
  1993
	_asm pop ebx
sl@0
  1994
	_asm ret 4					// return with error code in eax
sl@0
  1995
	}
sl@0
  1996
sl@0
  1997
sl@0
  1998
sl@0
  1999
sl@0
  2000
__NAKED__ EXPORT_C TInt TRealX::GetTReal(TReal64& /*aVal*/) const
sl@0
  2001
/**
sl@0
  2002
Extracts the extended precision value as
sl@0
  2003
a double precision floating point value.
sl@0
  2004
sl@0
  2005
@param aVal A reference to a double precision object which
sl@0
  2006
            contains the result of the operation.
sl@0
  2007
sl@0
  2008
@return KErrNone, if the operation is successful;
sl@0
  2009
        KErrOverflow, if the operation results in overflow;
sl@0
  2010
        KErrUnderflow, if the operation results in underflow.
sl@0
  2011
*/
sl@0
  2012
	{
sl@0
  2013
	// On entry, ecx=this, [esp+4]=address of aVal
sl@0
  2014
	// On exit, eax=return code
sl@0
  2015
	_asm push ebx
sl@0
  2016
	_asm push esi
sl@0
  2017
	_asm push edi
sl@0
  2018
	_asm mov ebx, [ecx]			// *this into ecx,edx:ebx
sl@0
  2019
	_asm mov edx, [ecx+4]
sl@0
  2020
	_asm mov ecx, [ecx+8]
sl@0
  2021
	_asm call TRealXGetTReal64
sl@0
  2022
	_asm mov ecx, [esp+16]		// ecx=address of aVal
sl@0
  2023
	_asm mov [ecx], ebx			// store result
sl@0
  2024
	_asm mov [ecx+4], edx
sl@0
  2025
	_asm pop edi
sl@0
  2026
	_asm pop esi
sl@0
  2027
	_asm pop ebx
sl@0
  2028
	_asm ret 4					// return with error code in eax
sl@0
  2029
	}
sl@0
  2030
sl@0
  2031
sl@0
  2032
sl@0
  2033
sl@0
  2034
__NAKED__ EXPORT_C void TRealX::SetZero(TBool /*aNegative*/)
sl@0
  2035
/**
sl@0
  2036
Sets the value of this extended precision object to zero.
sl@0
  2037
sl@0
  2038
@param aNegative ETrue, the value is a negative zero;
sl@0
  2039
                 EFalse, the value is a positive zero, this is the default.
sl@0
  2040
*/
sl@0
  2041
	{
sl@0
  2042
	_asm mov edx, [esp+4]		// aNegative into edx
sl@0
  2043
	_asm xor eax, eax			// eax=0
sl@0
  2044
	_asm mov [ecx], eax
sl@0
  2045
	_asm mov [ecx+4], eax
sl@0
  2046
	_asm test edx, edx
sl@0
  2047
	_asm jz short setzero1
sl@0
  2048
	_asm inc eax				// eax=1 if aNegative!=0
sl@0
  2049
	setzero1:
sl@0
  2050
	_asm mov [ecx+8], eax		// generate positive or negative zero
sl@0
  2051
	_asm ret 4
sl@0
  2052
	}
sl@0
  2053
sl@0
  2054
sl@0
  2055
sl@0
  2056
sl@0
  2057
__NAKED__ EXPORT_C void TRealX::SetNaN()
sl@0
  2058
/**
sl@0
  2059
Sets the value of this extended precision object to 'not a number'.
sl@0
  2060
*/
sl@0
  2061
	{
sl@0
  2062
	_asm xor eax, eax			// set *this to 'real indefinite'
sl@0
  2063
	_asm mov [ecx], eax
sl@0
  2064
	_asm mov eax, 0xC0000000
sl@0
  2065
	_asm mov [ecx+4], eax
sl@0
  2066
	_asm mov eax, 0xFFFF0001
sl@0
  2067
	_asm mov [ecx+8], eax
sl@0
  2068
	_asm ret
sl@0
  2069
	}
sl@0
  2070
sl@0
  2071
sl@0
  2072
sl@0
  2073
sl@0
  2074
__NAKED__ EXPORT_C void TRealX::SetInfinite(TBool /*aNegative*/)
sl@0
  2075
/**
sl@0
  2076
Sets the value of this extended precision object to infinity.
sl@0
  2077
sl@0
  2078
@param aNegative ETrue, the value is a negative zero;
sl@0
  2079
                 EFalse, the value is a positive zero.
sl@0
  2080
*/
sl@0
  2081
	{
sl@0
  2082
	_asm mov edx, [esp+4]		// aNegative into edx
sl@0
  2083
	_asm mov eax, 0xFFFF0000	// exponent=FFFF, sign=0 initially
sl@0
  2084
	_asm test edx, edx
sl@0
  2085
	_asm jz short setinf1
sl@0
  2086
	_asm inc eax				// sign=1 if aNegative!=0
sl@0
  2087
	setinf1:
sl@0
  2088
	_asm mov [ecx+8], eax		// generate positive or negative infinity
sl@0
  2089
	_asm mov eax, 0x80000000
sl@0
  2090
	_asm mov [ecx+4], eax
sl@0
  2091
	_asm xor eax, eax
sl@0
  2092
	_asm mov [ecx], eax
sl@0
  2093
	_asm ret 4
sl@0
  2094
	}
sl@0
  2095
sl@0
  2096
sl@0
  2097
sl@0
  2098
sl@0
  2099
__NAKED__ EXPORT_C TBool TRealX::IsZero() const
sl@0
  2100
/**
sl@0
  2101
Determines whether the extended precision value is zero.
sl@0
  2102
sl@0
  2103
@return True, if the extended precision value is zero, false, otherwise.
sl@0
  2104
*/
sl@0
  2105
	{
sl@0
  2106
	_asm mov eax, [ecx+8]		// check exponent
sl@0
  2107
	_asm shr eax, 16			// move exponent into ax
sl@0
  2108
	_asm jz short iszero1		// branch if zero
sl@0
  2109
	_asm xor eax, eax			// else return 0
sl@0
  2110
	_asm ret
sl@0
  2111
	iszero1:
sl@0
  2112
	_asm inc eax				// if zero, return 1
sl@0
  2113
	_asm ret
sl@0
  2114
	}
sl@0
  2115
sl@0
  2116
sl@0
  2117
sl@0
  2118
sl@0
  2119
__NAKED__ EXPORT_C TBool TRealX::IsNaN() const
sl@0
  2120
/**
sl@0
  2121
Determines whether the extended precision value is 'not a number'.
sl@0
  2122
sl@0
  2123
@return True, if the extended precision value is 'not a number',
sl@0
  2124
        false, otherwise.
sl@0
  2125
*/
sl@0
  2126
	{
sl@0
  2127
	_asm mov eax, [ecx+8]		// check exponent
sl@0
  2128
	_asm cmp eax, 0xFFFF0000
sl@0
  2129
	_asm jc short isnan0		// branch if not FFFF
sl@0
  2130
	_asm mov eax, [ecx+4]
sl@0
  2131
	_asm cmp eax, 0x80000000		// check for infinity
sl@0
  2132
	_asm jne short isnan1
sl@0
  2133
	_asm mov eax, [ecx]
sl@0
  2134
	_asm test eax, eax
sl@0
  2135
	_asm jne short isnan1
sl@0
  2136
	isnan0:
sl@0
  2137
	_asm xor eax, eax			// return 0 if not NaN
sl@0
  2138
	_asm ret
sl@0
  2139
	isnan1:
sl@0
  2140
	_asm mov eax, 1				// return 1 if NaN
sl@0
  2141
	_asm ret
sl@0
  2142
	}
sl@0
  2143
sl@0
  2144
sl@0
  2145
sl@0
  2146
sl@0
  2147
__NAKED__ EXPORT_C TBool TRealX::IsInfinite() const
sl@0
  2148
/**
sl@0
  2149
Determines whether the extended precision value has a finite value.
sl@0
  2150
sl@0
  2151
@return True, if the extended precision value is finite,
sl@0
  2152
        false, if the value is 'not a number' or is infinite,
sl@0
  2153
*/
sl@0
  2154
	{
sl@0
  2155
	_asm mov eax, [ecx+8]		// check exponent
sl@0
  2156
	_asm cmp eax, 0xFFFF0000
sl@0
  2157
	_asm jc short isinf0		// branch if not FFFF
sl@0
  2158
	_asm mov eax, [ecx+4]
sl@0
  2159
	_asm cmp eax, 0x80000000		// check for infinity
sl@0
  2160
	_asm jne short isinf0
sl@0
  2161
	_asm mov eax, [ecx]
sl@0
  2162
	_asm test eax, eax
sl@0
  2163
	_asm jne short isinf0
sl@0
  2164
	_asm inc eax				// return 1 if infinity
sl@0
  2165
	_asm ret
sl@0
  2166
	isinf0:
sl@0
  2167
	_asm xor eax, eax			// return 0 if not infinity
sl@0
  2168
	_asm ret
sl@0
  2169
	}
sl@0
  2170
sl@0
  2171
sl@0
  2172
sl@0
  2173
sl@0
  2174
__NAKED__ EXPORT_C TBool TRealX::IsFinite() const
sl@0
  2175
/**
sl@0
  2176
Determines whether the extended precision value has a finite value.
sl@0
  2177
sl@0
  2178
@return True, if the extended precision value is finite,
sl@0
  2179
        false, if the value is 'not a number' or is infinite,
sl@0
  2180
*/
sl@0
  2181
	{
sl@0
  2182
	_asm mov eax, [ecx+8]		// check exponent
sl@0
  2183
	_asm cmp eax, 0xFFFF0000	// check for NaN or infinity
sl@0
  2184
	_asm jnc short isfinite0	// branch if NaN or infinity
sl@0
  2185
	_asm mov eax, 1				// return 1 if finite
sl@0
  2186
	_asm ret
sl@0
  2187
	isfinite0:
sl@0
  2188
	_asm xor eax, eax			// return 0 if NaN or infinity
sl@0
  2189
	_asm ret
sl@0
  2190
	}
sl@0
  2191
sl@0
  2192
sl@0
  2193
sl@0
  2194
sl@0
  2195
__NAKED__ EXPORT_C const TRealX& TRealX::operator+=(const TRealX& /*aVal*/)
sl@0
  2196
/**
sl@0
  2197
Adds an extended precision value to this extended precision number.
sl@0
  2198
sl@0
  2199
@param aVal The extended precision value to be added.
sl@0
  2200
sl@0
  2201
@return A reference to this object.
sl@0
  2202
sl@0
  2203
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2204
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2205
*/
sl@0
  2206
	{
sl@0
  2207
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2208
	_asm push ebx				// save registers
sl@0
  2209
	_asm push ebp
sl@0
  2210
	_asm push esi
sl@0
  2211
	_asm push edi
sl@0
  2212
	_asm mov esi, ecx			// this into esi
sl@0
  2213
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2214
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2215
	_asm mov edx, [ecx+4]
sl@0
  2216
	_asm mov ecx, [ecx+8]
sl@0
  2217
	_asm call TRealXAdd			// do addition, result in ecx,edx:ebx, error code in eax
sl@0
  2218
	_asm mov [esi], ebx			// store result in *this
sl@0
  2219
	_asm mov [esi+4], edx
sl@0
  2220
	_asm mov [esi+8], ecx
sl@0
  2221
	_asm test eax, eax
sl@0
  2222
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2223
	_asm mov eax, esi			// return this in eax
sl@0
  2224
	_asm pop edi				// restore registers
sl@0
  2225
	_asm pop esi
sl@0
  2226
	_asm pop ebp
sl@0
  2227
	_asm pop ebx
sl@0
  2228
	_asm ret 4
sl@0
  2229
	}
sl@0
  2230
sl@0
  2231
sl@0
  2232
sl@0
  2233
sl@0
  2234
__NAKED__ EXPORT_C const TRealX& TRealX::operator-=(const TRealX& /*aVal*/)
sl@0
  2235
/**
sl@0
  2236
Subtracts an extended precision value from this extended precision number. 
sl@0
  2237
sl@0
  2238
@param aVal The extended precision value to be subtracted.
sl@0
  2239
sl@0
  2240
@return A reference to this object.
sl@0
  2241
sl@0
  2242
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2243
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2244
*/
sl@0
  2245
	{
sl@0
  2246
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2247
	_asm push ebx				// save registers
sl@0
  2248
	_asm push ebp
sl@0
  2249
	_asm push esi
sl@0
  2250
	_asm push edi
sl@0
  2251
	_asm mov esi, ecx			// this into esi
sl@0
  2252
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2253
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2254
	_asm mov edx, [ecx+4]
sl@0
  2255
	_asm mov ecx, [ecx+8]
sl@0
  2256
	_asm call TRealXSubtract	// do subtraction, result in ecx,edx:ebx, error code in eax
sl@0
  2257
	_asm mov [esi], ebx			// store result in *this
sl@0
  2258
	_asm mov [esi+4], edx
sl@0
  2259
	_asm mov [esi+8], ecx
sl@0
  2260
	_asm test eax, eax
sl@0
  2261
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2262
	_asm mov eax, esi			// return this in eax
sl@0
  2263
	_asm pop edi				// restore registers
sl@0
  2264
	_asm pop esi
sl@0
  2265
	_asm pop ebp
sl@0
  2266
	_asm pop ebx
sl@0
  2267
	_asm ret 4
sl@0
  2268
	}
sl@0
  2269
sl@0
  2270
sl@0
  2271
sl@0
  2272
sl@0
  2273
__NAKED__ EXPORT_C const TRealX& TRealX::operator*=(const TRealX& /*aVal*/)
sl@0
  2274
/**
sl@0
  2275
Multiplies this extended precision number by an extended precision value.
sl@0
  2276
sl@0
  2277
@param aVal The extended precision value to be subtracted.
sl@0
  2278
sl@0
  2279
@return A reference to this object.
sl@0
  2280
sl@0
  2281
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2282
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2283
*/
sl@0
  2284
	{
sl@0
  2285
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2286
	_asm push ebx				// save registers
sl@0
  2287
	_asm push ebp
sl@0
  2288
	_asm push esi
sl@0
  2289
	_asm push edi
sl@0
  2290
	_asm mov esi, ecx			// this into esi
sl@0
  2291
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2292
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2293
	_asm mov edx, [ecx+4]
sl@0
  2294
	_asm mov ecx, [ecx+8]
sl@0
  2295
	_asm call TRealXMultiply	// do multiplication, result in ecx,edx:ebx, error code in eax
sl@0
  2296
	_asm mov [esi], ebx			// store result in *this
sl@0
  2297
	_asm mov [esi+4], edx
sl@0
  2298
	_asm mov [esi+8], ecx
sl@0
  2299
	_asm test eax, eax
sl@0
  2300
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2301
	_asm mov eax, esi			// return this in eax
sl@0
  2302
	_asm pop edi				// restore registers
sl@0
  2303
	_asm pop esi
sl@0
  2304
	_asm pop ebp
sl@0
  2305
	_asm pop ebx
sl@0
  2306
	_asm ret 4
sl@0
  2307
	}
sl@0
  2308
sl@0
  2309
sl@0
  2310
sl@0
  2311
sl@0
  2312
__NAKED__ EXPORT_C const TRealX& TRealX::operator/=(const TRealX& /*aVal*/)
sl@0
  2313
/**
sl@0
  2314
Divides this extended precision number by an extended precision value.
sl@0
  2315
sl@0
  2316
@param aVal The extended precision value to be used as the divisor. 
sl@0
  2317
sl@0
  2318
@return A reference to this object.
sl@0
  2319
sl@0
  2320
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2321
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2322
@panic MATHX KErrDivideByZero if the divisor is zero.
sl@0
  2323
*/
sl@0
  2324
	{
sl@0
  2325
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2326
	_asm push ebx				// save registers
sl@0
  2327
	_asm push ebp
sl@0
  2328
	_asm push esi
sl@0
  2329
	_asm push edi
sl@0
  2330
	_asm mov esi, ecx			// this into esi
sl@0
  2331
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2332
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2333
	_asm mov edx, [ecx+4]
sl@0
  2334
	_asm mov ecx, [ecx+8]
sl@0
  2335
	_asm call TRealXDivide		// do division, result in ecx,edx:ebx, error code in eax
sl@0
  2336
	_asm mov [esi], ebx			// store result in *this
sl@0
  2337
	_asm mov [esi+4], edx
sl@0
  2338
	_asm mov [esi+8], ecx
sl@0
  2339
	_asm test eax, eax
sl@0
  2340
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2341
	_asm mov eax, esi			// return this in eax
sl@0
  2342
	_asm pop edi				// restore registers
sl@0
  2343
	_asm pop esi
sl@0
  2344
	_asm pop ebp
sl@0
  2345
	_asm pop ebx
sl@0
  2346
	_asm ret 4
sl@0
  2347
	}
sl@0
  2348
sl@0
  2349
sl@0
  2350
sl@0
  2351
sl@0
  2352
__NAKED__ EXPORT_C const TRealX& TRealX::operator%=(const TRealX& /*aVal*/)
sl@0
  2353
/**
sl@0
  2354
Modulo-divides this extended precision number by an extended precision value.
sl@0
  2355
sl@0
  2356
@param aVal The extended precision value to be used as the divisor. 
sl@0
  2357
sl@0
  2358
@return A reference to this object.
sl@0
  2359
sl@0
  2360
@panic MATHX KErrTotalLossOfPrecision panic if precision is lost.
sl@0
  2361
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2362
*/
sl@0
  2363
	{
sl@0
  2364
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2365
	_asm push ebx				// save registers
sl@0
  2366
	_asm push ebp
sl@0
  2367
	_asm push esi
sl@0
  2368
	_asm push edi
sl@0
  2369
	_asm mov esi, ecx			// this into esi
sl@0
  2370
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2371
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2372
	_asm mov edx, [ecx+4]
sl@0
  2373
	_asm mov ecx, [ecx+8]
sl@0
  2374
	_asm call TRealXModulo		// do modulo, result in ecx,edx:ebx, error code in eax
sl@0
  2375
	_asm mov [esi], ebx			// store result in *this
sl@0
  2376
	_asm mov [esi+4], edx
sl@0
  2377
	_asm mov [esi+8], ecx
sl@0
  2378
	_asm test eax, eax
sl@0
  2379
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2380
	_asm mov eax, esi			// return this in eax
sl@0
  2381
	_asm pop edi				// restore registers
sl@0
  2382
	_asm pop esi
sl@0
  2383
	_asm pop ebp
sl@0
  2384
	_asm pop ebx
sl@0
  2385
	_asm ret 4
sl@0
  2386
	}
sl@0
  2387
sl@0
  2388
sl@0
  2389
sl@0
  2390
sl@0
  2391
__NAKED__ EXPORT_C TInt TRealX::AddEq(const TRealX& /*aVal*/)
sl@0
  2392
/**
sl@0
  2393
Adds an extended precision value to this extended precision number.
sl@0
  2394
sl@0
  2395
@param aVal The extended precision value to be added.
sl@0
  2396
sl@0
  2397
@return KErrNone, if the operation is successful;
sl@0
  2398
        KErrOverflow,if the operation results in overflow;
sl@0
  2399
        KErrUnderflow, if the operation results in underflow. 
sl@0
  2400
*/
sl@0
  2401
	{
sl@0
  2402
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2403
	_asm push ebx				// save registers
sl@0
  2404
	_asm push ebp
sl@0
  2405
	_asm push esi
sl@0
  2406
	_asm push edi
sl@0
  2407
	_asm mov esi, ecx			// this into esi
sl@0
  2408
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2409
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2410
	_asm mov edx, [ecx+4]
sl@0
  2411
	_asm mov ecx, [ecx+8]
sl@0
  2412
	_asm call TRealXAdd			// do addition, result in ecx,edx:ebx, error code in eax
sl@0
  2413
	_asm mov [esi], ebx			// store result
sl@0
  2414
	_asm mov [esi+4], edx
sl@0
  2415
	_asm mov [esi+8], ecx
sl@0
  2416
	_asm pop edi				// restore registers
sl@0
  2417
	_asm pop esi
sl@0
  2418
	_asm pop ebp
sl@0
  2419
	_asm pop ebx
sl@0
  2420
	_asm ret 4					// return with error code in eax
sl@0
  2421
	}
sl@0
  2422
sl@0
  2423
sl@0
  2424
sl@0
  2425
sl@0
  2426
__NAKED__ EXPORT_C TInt TRealX::SubEq(const TRealX& /*aVal*/)
sl@0
  2427
/**
sl@0
  2428
Subtracts an extended precision value from this extended precision number.
sl@0
  2429
sl@0
  2430
@param aVal The extended precision value to be subtracted.
sl@0
  2431
sl@0
  2432
@return KErrNone, if the operation is successful;
sl@0
  2433
        KErrOverflow, if the operation results in overflow;
sl@0
  2434
        KErrUnderflow, if the operation results in underflow.
sl@0
  2435
*/
sl@0
  2436
	{
sl@0
  2437
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2438
	_asm push ebx				// save registers
sl@0
  2439
	_asm push ebp
sl@0
  2440
	_asm push esi
sl@0
  2441
	_asm push edi
sl@0
  2442
	_asm mov esi, ecx			// this into esi
sl@0
  2443
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2444
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2445
	_asm mov edx, [ecx+4]
sl@0
  2446
	_asm mov ecx, [ecx+8]
sl@0
  2447
	_asm call TRealXSubtract	// do subtraction, result in ecx,edx:ebx, error code in eax
sl@0
  2448
	_asm mov [esi], ebx			// store result
sl@0
  2449
	_asm mov [esi+4], edx
sl@0
  2450
	_asm mov [esi+8], ecx
sl@0
  2451
	_asm pop edi				// restore registers
sl@0
  2452
	_asm pop esi
sl@0
  2453
	_asm pop ebp
sl@0
  2454
	_asm pop ebx
sl@0
  2455
	_asm ret 4					// return with error code in eax
sl@0
  2456
	}
sl@0
  2457
sl@0
  2458
sl@0
  2459
sl@0
  2460
sl@0
  2461
__NAKED__ EXPORT_C TInt TRealX::MultEq(const TRealX& /*aVal*/)
sl@0
  2462
/**
sl@0
  2463
Multiplies this extended precision number by an extended precision value.
sl@0
  2464
sl@0
  2465
@param aVal The extended precision value to be used as the multiplier.
sl@0
  2466
sl@0
  2467
@return KErrNone, if the operation is successful;
sl@0
  2468
        KErrOverflow, if the operation results in overflow;
sl@0
  2469
        KErrUnderflow, if the operation results in underflow
sl@0
  2470
*/
sl@0
  2471
	{
sl@0
  2472
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2473
	_asm push ebx				// save registers
sl@0
  2474
	_asm push ebp
sl@0
  2475
	_asm push esi
sl@0
  2476
	_asm push edi
sl@0
  2477
	_asm mov esi, ecx			// this into esi
sl@0
  2478
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2479
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2480
	_asm mov edx, [ecx+4]
sl@0
  2481
	_asm mov ecx, [ecx+8]
sl@0
  2482
	_asm call TRealXMultiply	// do multiplication, result in ecx,edx:ebx, error code in eax
sl@0
  2483
	_asm mov [esi], ebx			// store result
sl@0
  2484
	_asm mov [esi+4], edx
sl@0
  2485
	_asm mov [esi+8], ecx
sl@0
  2486
	_asm pop edi				// restore registers
sl@0
  2487
	_asm pop esi
sl@0
  2488
	_asm pop ebp
sl@0
  2489
	_asm pop ebx
sl@0
  2490
	_asm ret 4					// return with error code in eax
sl@0
  2491
	}
sl@0
  2492
sl@0
  2493
sl@0
  2494
sl@0
  2495
sl@0
  2496
__NAKED__ EXPORT_C TInt TRealX::DivEq(const TRealX& /*aVal*/)
sl@0
  2497
/**
sl@0
  2498
Divides this extended precision number by an extended precision value.
sl@0
  2499
sl@0
  2500
@param aVal The extended precision value to be used as the divisor.
sl@0
  2501
sl@0
  2502
@return KErrNone, if the operation is successful;
sl@0
  2503
        KErrOverflow, if the operation results in overflow;
sl@0
  2504
        KErrUnderflow, if the operation results in underflow;
sl@0
  2505
        KErrDivideByZero, if the divisor is zero. 
sl@0
  2506
*/
sl@0
  2507
	{
sl@0
  2508
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2509
	_asm push ebx				// save registers
sl@0
  2510
	_asm push ebp
sl@0
  2511
	_asm push esi
sl@0
  2512
	_asm push edi
sl@0
  2513
	_asm mov esi, ecx			// this into esi
sl@0
  2514
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2515
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2516
	_asm mov edx, [ecx+4]
sl@0
  2517
	_asm mov ecx, [ecx+8]
sl@0
  2518
	_asm call TRealXDivide		// do division, result in ecx,edx:ebx, error code in eax
sl@0
  2519
	_asm mov [esi], ebx			// store result
sl@0
  2520
	_asm mov [esi+4], edx
sl@0
  2521
	_asm mov [esi+8], ecx
sl@0
  2522
	_asm pop edi				// restore registers
sl@0
  2523
	_asm pop esi
sl@0
  2524
	_asm pop ebp
sl@0
  2525
	_asm pop ebx
sl@0
  2526
	_asm ret 4					// return with error code in eax
sl@0
  2527
	}
sl@0
  2528
sl@0
  2529
sl@0
  2530
sl@0
  2531
sl@0
  2532
__NAKED__ EXPORT_C TInt TRealX::ModEq(const TRealX& /*aVal*/)
sl@0
  2533
/**
sl@0
  2534
Modulo-divides this extended precision number by an extended precision value.
sl@0
  2535
sl@0
  2536
@param aVal The extended precision value to be used as the divisor. 
sl@0
  2537
sl@0
  2538
@return KErrNone, if the operation is successful;
sl@0
  2539
        KErrTotalLossOfPrecision, if precision is lost;
sl@0
  2540
        KErrUnderflow, if the operation results in underflow.
sl@0
  2541
*/
sl@0
  2542
	{
sl@0
  2543
	// on entry ecx=this, [esp+4]=address of aVal
sl@0
  2544
	_asm push ebx				// save registers
sl@0
  2545
	_asm push ebp
sl@0
  2546
	_asm push esi
sl@0
  2547
	_asm push edi
sl@0
  2548
	_asm mov esi, ecx			// this into esi
sl@0
  2549
	_asm mov ecx, [esp+20]		// address of aVal into ecx
sl@0
  2550
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2551
	_asm mov edx, [ecx+4]
sl@0
  2552
	_asm mov ecx, [ecx+8]
sl@0
  2553
	_asm call TRealXModulo		// do modulo, result in ecx,edx:ebx, error code in eax
sl@0
  2554
	_asm mov [esi], ebx			// store result
sl@0
  2555
	_asm mov [esi+4], edx
sl@0
  2556
	_asm mov [esi+8], ecx
sl@0
  2557
	_asm pop edi				// restore registers
sl@0
  2558
	_asm pop esi
sl@0
  2559
	_asm pop ebp
sl@0
  2560
	_asm pop ebx
sl@0
  2561
	_asm ret 4					// return with error code in eax
sl@0
  2562
	}
sl@0
  2563
sl@0
  2564
sl@0
  2565
sl@0
  2566
sl@0
  2567
__NAKED__ EXPORT_C TRealX TRealX::operator+() const
sl@0
  2568
/**
sl@0
  2569
Returns this extended precision number unchanged.
sl@0
  2570
sl@0
  2571
Note that this may also be referred to as a unary plus operator. 
sl@0
  2572
sl@0
  2573
@return The extended precision number.
sl@0
  2574
*/
sl@0
  2575
	{
sl@0
  2576
	_asm mov eax, [esp+4]		// eax=address to write return value
sl@0
  2577
	_asm mov edx, [ecx]
sl@0
  2578
	_asm mov [eax], edx
sl@0
  2579
	_asm mov edx, [ecx+4]
sl@0
  2580
	_asm mov [eax+4], edx
sl@0
  2581
	_asm mov edx, [ecx+8]
sl@0
  2582
	_asm mov [eax+8], edx
sl@0
  2583
	_asm ret 4					// return address of return value in eax
sl@0
  2584
	}
sl@0
  2585
sl@0
  2586
sl@0
  2587
sl@0
  2588
sl@0
  2589
__NAKED__ EXPORT_C TRealX TRealX::operator-() const
sl@0
  2590
/**
sl@0
  2591
Negates this extended precision number.
sl@0
  2592
sl@0
  2593
This may also be referred to as a unary minus operator.
sl@0
  2594
sl@0
  2595
@return The negative of the extended precision number.
sl@0
  2596
*/
sl@0
  2597
	{
sl@0
  2598
	_asm mov eax, [esp+4]		// eax=address to write return value
sl@0
  2599
	_asm mov edx, [ecx]
sl@0
  2600
	_asm mov [eax], edx
sl@0
  2601
	_asm mov edx, [ecx+4]
sl@0
  2602
	_asm mov [eax+4], edx
sl@0
  2603
	_asm mov edx, [ecx+8]
sl@0
  2604
	_asm xor dl, 1				// change sign bit
sl@0
  2605
	_asm mov [eax+8], edx
sl@0
  2606
	_asm ret 4					// return address of return value in eax
sl@0
  2607
	}
sl@0
  2608
sl@0
  2609
sl@0
  2610
sl@0
  2611
sl@0
  2612
__NAKED__ EXPORT_C TRealX& TRealX::operator++()
sl@0
  2613
/**
sl@0
  2614
Increments this extended precision number by one,
sl@0
  2615
and then returns a reference to it.
sl@0
  2616
sl@0
  2617
This is also referred to as a prefix operator. 
sl@0
  2618
sl@0
  2619
@return A reference to this object.
sl@0
  2620
sl@0
  2621
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2622
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2623
*/
sl@0
  2624
	{
sl@0
  2625
	// pre-increment
sl@0
  2626
	// on entry ecx=this, return this in eax
sl@0
  2627
	_asm push ebx				// save registers
sl@0
  2628
	_asm push ebp
sl@0
  2629
	_asm push esi
sl@0
  2630
	_asm push edi
sl@0
  2631
	_asm mov esi, ecx			// this into esi
sl@0
  2632
	_asm mov ecx, 0x7FFF0000	// set ecx,edx:ebx to 1.0
sl@0
  2633
	_asm mov edx, 0x80000000
sl@0
  2634
	_asm xor ebx, ebx
sl@0
  2635
	_asm call TRealXAdd			// add 1 to *this
sl@0
  2636
	_asm mov [esi], ebx			// store result
sl@0
  2637
	_asm mov [esi+4], edx
sl@0
  2638
	_asm mov [esi+8], ecx
sl@0
  2639
	_asm test eax, eax			// check error code
sl@0
  2640
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2641
	_asm mov eax, esi			// else return this in eax
sl@0
  2642
	_asm pop edi
sl@0
  2643
	_asm pop esi
sl@0
  2644
	_asm pop ebp
sl@0
  2645
	_asm pop ebx
sl@0
  2646
	_asm ret
sl@0
  2647
	}
sl@0
  2648
sl@0
  2649
sl@0
  2650
sl@0
  2651
sl@0
  2652
__NAKED__ EXPORT_C TRealX TRealX::operator++(TInt)
sl@0
  2653
/**
sl@0
  2654
Returns this extended precision number before incrementing it by one.
sl@0
  2655
sl@0
  2656
This is also referred to as a postfix operator. 
sl@0
  2657
sl@0
  2658
@return A reference to this object.
sl@0
  2659
sl@0
  2660
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2661
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2662
*/
sl@0
  2663
	{
sl@0
  2664
	// post-increment
sl@0
  2665
	// on entry ecx=this, [esp+4]=address of return value, [esp+8]=dummy int
sl@0
  2666
	_asm push ebx				// save registers
sl@0
  2667
	_asm push ebp
sl@0
  2668
	_asm push esi
sl@0
  2669
	_asm push edi
sl@0
  2670
	_asm mov esi, ecx			// this into esi
sl@0
  2671
	_asm mov edi, [esp+20]		// address of return value into edi
sl@0
  2672
	_asm mov eax, [ecx]			// copy initial value of *this into [edi]
sl@0
  2673
	_asm mov [edi], eax
sl@0
  2674
	_asm mov eax, [ecx+4]
sl@0
  2675
	_asm mov [edi+4], eax
sl@0
  2676
	_asm mov eax, [ecx+8]
sl@0
  2677
	_asm mov [edi+8], eax
sl@0
  2678
	_asm mov ecx, 0x7FFF0000	// set ecx,edx:ebx to 1.0
sl@0
  2679
	_asm mov edx, 0x80000000
sl@0
  2680
	_asm xor ebx, ebx
sl@0
  2681
	_asm call TRealXAdd			// add 1 to *this
sl@0
  2682
	_asm mov [esi], ebx			// store result in *this
sl@0
  2683
	_asm mov [esi+4], edx
sl@0
  2684
	_asm mov [esi+8], ecx
sl@0
  2685
	_asm test eax, eax			// check error code
sl@0
  2686
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2687
	_asm mov eax, [esp+20]		// address of return value into eax
sl@0
  2688
	_asm pop edi
sl@0
  2689
	_asm pop esi
sl@0
  2690
	_asm pop ebp
sl@0
  2691
	_asm pop ebx
sl@0
  2692
	_asm ret 8
sl@0
  2693
	}
sl@0
  2694
sl@0
  2695
sl@0
  2696
sl@0
  2697
sl@0
  2698
__NAKED__ EXPORT_C TRealX& TRealX::operator--()
sl@0
  2699
/**
sl@0
  2700
Decrements this extended precision number by one,
sl@0
  2701
and then returns a reference to it.
sl@0
  2702
sl@0
  2703
This is also referred to as a prefix operator. 
sl@0
  2704
sl@0
  2705
@return A reference to this object.
sl@0
  2706
sl@0
  2707
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2708
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2709
*/
sl@0
  2710
	{
sl@0
  2711
	// pre-decrement
sl@0
  2712
	// on entry ecx=this, return this in eax
sl@0
  2713
	_asm push ebx				// save registers
sl@0
  2714
	_asm push ebp
sl@0
  2715
	_asm push esi
sl@0
  2716
	_asm push edi
sl@0
  2717
	_asm mov esi, ecx			// this into esi
sl@0
  2718
	_asm mov ecx, 0x7FFF0001		// set ecx,edx:ebx to -1.0
sl@0
  2719
	_asm mov edx, 0x80000000
sl@0
  2720
	_asm xor ebx, ebx
sl@0
  2721
	_asm call TRealXAdd			// add -1 to *this
sl@0
  2722
	_asm mov [esi], ebx			// store result
sl@0
  2723
	_asm mov [esi+4], edx
sl@0
  2724
	_asm mov [esi+8], ecx
sl@0
  2725
	_asm test eax, eax			// check error code
sl@0
  2726
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2727
	_asm mov eax, esi			// else return this in eax
sl@0
  2728
	_asm pop edi
sl@0
  2729
	_asm pop esi
sl@0
  2730
	_asm pop ebp
sl@0
  2731
	_asm pop ebx
sl@0
  2732
	_asm ret
sl@0
  2733
	}
sl@0
  2734
sl@0
  2735
sl@0
  2736
sl@0
  2737
sl@0
  2738
__NAKED__ EXPORT_C TRealX TRealX::operator--(TInt)
sl@0
  2739
/**
sl@0
  2740
Returns this extended precision number before decrementing it by one.
sl@0
  2741
sl@0
  2742
This is also referred to as a postfix operator. 
sl@0
  2743
sl@0
  2744
@return A reference to this object.
sl@0
  2745
sl@0
  2746
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2747
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2748
*/
sl@0
  2749
	{
sl@0
  2750
	// post-decrement
sl@0
  2751
	// on entry ecx=this, [esp+4]=address of return value, [esp+8]=dummy int
sl@0
  2752
	_asm push ebx				// save registers
sl@0
  2753
	_asm push ebp
sl@0
  2754
	_asm push esi
sl@0
  2755
	_asm push edi
sl@0
  2756
	_asm mov esi, ecx			// this into esi
sl@0
  2757
	_asm mov edi, [esp+20]		// address of return value into edi
sl@0
  2758
	_asm mov eax, [ecx]			// copy initial value of *this into [edi]
sl@0
  2759
	_asm mov [edi], eax
sl@0
  2760
	_asm mov eax, [ecx+4]
sl@0
  2761
	_asm mov [edi+4], eax
sl@0
  2762
	_asm mov eax, [ecx+8]
sl@0
  2763
	_asm mov [edi+8], eax
sl@0
  2764
	_asm mov ecx, 0x7FFF0001		// set ecx,edx:ebx to -1.0
sl@0
  2765
	_asm mov edx, 0x80000000
sl@0
  2766
	_asm xor ebx, ebx
sl@0
  2767
	_asm call TRealXAdd			// add -1 to *this
sl@0
  2768
	_asm mov [esi], ebx			// store result in *this
sl@0
  2769
	_asm mov [esi+4], edx
sl@0
  2770
	_asm mov [esi+8], ecx
sl@0
  2771
	_asm test eax, eax			// check error code
sl@0
  2772
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2773
	_asm mov eax, [esp+20]		// address of return value into eax
sl@0
  2774
	_asm pop edi
sl@0
  2775
	_asm pop esi
sl@0
  2776
	_asm pop ebp
sl@0
  2777
	_asm pop ebx
sl@0
  2778
	_asm ret 8
sl@0
  2779
	}
sl@0
  2780
sl@0
  2781
sl@0
  2782
sl@0
  2783
sl@0
  2784
__NAKED__ EXPORT_C TRealX TRealX::operator+(const TRealX& /*aVal*/) const
sl@0
  2785
/**
sl@0
  2786
Adds an extended precision value to this extended precision number.
sl@0
  2787
sl@0
  2788
@param aVal The extended precision value to be added. 
sl@0
  2789
sl@0
  2790
@return An extended precision object containing the result.
sl@0
  2791
sl@0
  2792
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2793
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2794
*/
sl@0
  2795
	{
sl@0
  2796
	// on entry ecx=this, [esp+4]=address of return value, [esp+8]=address of aVal
sl@0
  2797
	_asm push ebx				// save registers
sl@0
  2798
	_asm push ebp
sl@0
  2799
	_asm push esi
sl@0
  2800
	_asm push edi
sl@0
  2801
	_asm mov esi, ecx			// this into esi
sl@0
  2802
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  2803
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2804
	_asm mov edx, [ecx+4]
sl@0
  2805
	_asm mov ecx, [ecx+8]
sl@0
  2806
	_asm call TRealXAdd			// do addition, result in ecx,edx:ebx, error code in eax
sl@0
  2807
	_asm mov esi, [esp+20]		// esi=address of return value
sl@0
  2808
	_asm mov [esi], ebx			// store result
sl@0
  2809
	_asm mov [esi+4], edx
sl@0
  2810
	_asm mov [esi+8], ecx
sl@0
  2811
	_asm test eax, eax
sl@0
  2812
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2813
	_asm mov eax, esi			// return address of return value in eax
sl@0
  2814
	_asm pop edi				// restore registers
sl@0
  2815
	_asm pop esi
sl@0
  2816
	_asm pop ebp
sl@0
  2817
	_asm pop ebx
sl@0
  2818
	_asm ret 8
sl@0
  2819
	}
sl@0
  2820
sl@0
  2821
sl@0
  2822
sl@0
  2823
sl@0
  2824
__NAKED__ EXPORT_C TRealX TRealX::operator-(const TRealX& /*aVal*/) const
sl@0
  2825
/**
sl@0
  2826
Subtracts an extended precision value from this extended precision number. 
sl@0
  2827
sl@0
  2828
@param aVal The extended precision value to be subtracted. 
sl@0
  2829
sl@0
  2830
@return An extended precision object containing the result. 
sl@0
  2831
sl@0
  2832
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2833
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2834
*/
sl@0
  2835
	{
sl@0
  2836
	// on entry ecx=this, [esp+4]=address of return value, [esp+8]=address of aVal
sl@0
  2837
	_asm push ebx				// save registers
sl@0
  2838
	_asm push ebp
sl@0
  2839
	_asm push esi
sl@0
  2840
	_asm push edi
sl@0
  2841
	_asm mov esi, ecx			// this into esi
sl@0
  2842
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  2843
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2844
	_asm mov edx, [ecx+4]
sl@0
  2845
	_asm mov ecx, [ecx+8]
sl@0
  2846
	_asm call TRealXSubtract	// do subtraction, result in ecx,edx:ebx, error code in eax
sl@0
  2847
	_asm mov esi, [esp+20]		// esi=address of return value
sl@0
  2848
	_asm mov [esi], ebx			// store result
sl@0
  2849
	_asm mov [esi+4], edx
sl@0
  2850
	_asm mov [esi+8], ecx
sl@0
  2851
	_asm test eax, eax
sl@0
  2852
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2853
	_asm mov eax, esi			// return address of return value in eax
sl@0
  2854
	_asm pop edi				// restore registers
sl@0
  2855
	_asm pop esi
sl@0
  2856
	_asm pop ebp
sl@0
  2857
	_asm pop ebx
sl@0
  2858
	_asm ret 8
sl@0
  2859
	}
sl@0
  2860
sl@0
  2861
sl@0
  2862
sl@0
  2863
sl@0
  2864
__NAKED__ EXPORT_C TRealX TRealX::operator*(const TRealX& /*aVal*/) const
sl@0
  2865
/**
sl@0
  2866
Multiplies this extended precision number by an extended precision value.
sl@0
  2867
sl@0
  2868
@param aVal The extended precision value to be used as the multiplier. 
sl@0
  2869
sl@0
  2870
@return An extended precision object containing the result. 
sl@0
  2871
sl@0
  2872
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2873
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2874
*/
sl@0
  2875
	{
sl@0
  2876
	// on entry ecx=this, [esp+4]=address of return value, [esp+8]=address of aVal
sl@0
  2877
	_asm push ebx				// save registers
sl@0
  2878
	_asm push ebp
sl@0
  2879
	_asm push esi
sl@0
  2880
	_asm push edi
sl@0
  2881
	_asm mov esi, ecx			// this into esi
sl@0
  2882
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  2883
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2884
	_asm mov edx, [ecx+4]
sl@0
  2885
	_asm mov ecx, [ecx+8]
sl@0
  2886
	_asm call TRealXMultiply	// do multiplication, result in ecx,edx:ebx, error code in eax
sl@0
  2887
	_asm mov esi, [esp+20]		// esi=address of return value
sl@0
  2888
	_asm mov [esi], ebx			// store result
sl@0
  2889
	_asm mov [esi+4], edx
sl@0
  2890
	_asm mov [esi+8], ecx
sl@0
  2891
	_asm test eax, eax
sl@0
  2892
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2893
	_asm mov eax, esi			// return address of return value in eax
sl@0
  2894
	_asm pop edi				// restore registers
sl@0
  2895
	_asm pop esi
sl@0
  2896
	_asm pop ebp
sl@0
  2897
	_asm pop ebx
sl@0
  2898
	_asm ret 8
sl@0
  2899
	}
sl@0
  2900
sl@0
  2901
sl@0
  2902
sl@0
  2903
sl@0
  2904
__NAKED__ EXPORT_C TRealX TRealX::operator/(const TRealX& /*aVal*/) const
sl@0
  2905
/**
sl@0
  2906
Divides this extended precision number by an extended precision value.
sl@0
  2907
sl@0
  2908
@param aVal The extended precision value to be used as the divisor. 
sl@0
  2909
sl@0
  2910
@return An extended precision object containing the result. 
sl@0
  2911
sl@0
  2912
@panic MATHX KErrOverflow if the operation results in overflow.
sl@0
  2913
@panic MATHX KErrUnderflow if  the operation results in underflow.
sl@0
  2914
@panic MATHX KErrDivideByZero if the divisor is zero.
sl@0
  2915
*/
sl@0
  2916
	{
sl@0
  2917
	// on entry ecx=this, [esp+4]=address of return value, [esp+8]=address of aVal
sl@0
  2918
	_asm push ebx				// save registers
sl@0
  2919
	_asm push ebp
sl@0
  2920
	_asm push esi
sl@0
  2921
	_asm push edi
sl@0
  2922
	_asm mov esi, ecx			// this into esi
sl@0
  2923
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  2924
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2925
	_asm mov edx, [ecx+4]
sl@0
  2926
	_asm mov ecx, [ecx+8]
sl@0
  2927
	_asm call TRealXDivide		// do division, result in ecx,edx:ebx, error code in eax
sl@0
  2928
	_asm mov esi, [esp+20]		// esi=address of return value
sl@0
  2929
	_asm mov [esi], ebx			// store result
sl@0
  2930
	_asm mov [esi+4], edx
sl@0
  2931
	_asm mov [esi+8], ecx
sl@0
  2932
	_asm test eax, eax
sl@0
  2933
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2934
	_asm mov eax, esi			// return address of return value in eax
sl@0
  2935
	_asm pop edi				// restore registers
sl@0
  2936
	_asm pop esi
sl@0
  2937
	_asm pop ebp
sl@0
  2938
	_asm pop ebx
sl@0
  2939
	_asm ret 8
sl@0
  2940
	}
sl@0
  2941
sl@0
  2942
sl@0
  2943
sl@0
  2944
sl@0
  2945
__NAKED__ EXPORT_C TRealX TRealX::operator%(const TRealX& /*aVal*/) const
sl@0
  2946
/**
sl@0
  2947
Modulo-divides this extended precision number by an extended precision value.
sl@0
  2948
sl@0
  2949
@param aVal The extended precision value to be used as the divisor. 
sl@0
  2950
sl@0
  2951
@return An extended precision object containing the result. 
sl@0
  2952
sl@0
  2953
@panic MATHX KErrTotalLossOfPrecision if precision is lost.
sl@0
  2954
@panic MATHX KErrUnderflow if the operation results in underflow.
sl@0
  2955
*/
sl@0
  2956
	{
sl@0
  2957
	// on entry ecx=this, [esp+4]=address of return value, [esp+8]=address of aVal
sl@0
  2958
	_asm push ebx				// save registers
sl@0
  2959
	_asm push ebp
sl@0
  2960
	_asm push esi
sl@0
  2961
	_asm push edi
sl@0
  2962
	_asm mov esi, ecx			// this into esi
sl@0
  2963
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  2964
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  2965
	_asm mov edx, [ecx+4]
sl@0
  2966
	_asm mov ecx, [ecx+8]
sl@0
  2967
	_asm call TRealXModulo		// do modulo, result in ecx,edx:ebx, error code in eax
sl@0
  2968
	_asm mov esi, [esp+20]		// esi=address of return value
sl@0
  2969
	_asm mov [esi], ebx			// store result
sl@0
  2970
	_asm mov [esi+4], edx
sl@0
  2971
	_asm mov [esi+8], ecx
sl@0
  2972
	_asm test eax, eax
sl@0
  2973
	_ASM_jn(z,TRealXPanicEax)	// panic if error
sl@0
  2974
	_asm mov eax, esi			// return address of return value in eax
sl@0
  2975
	_asm pop edi				// restore registers
sl@0
  2976
	_asm pop esi
sl@0
  2977
	_asm pop ebp
sl@0
  2978
	_asm pop ebx
sl@0
  2979
	_asm ret 8
sl@0
  2980
	}
sl@0
  2981
sl@0
  2982
sl@0
  2983
sl@0
  2984
sl@0
  2985
__NAKED__ EXPORT_C TInt TRealX::Add(TRealX& /*aResult*/, const TRealX& /*aVal*/) const
sl@0
  2986
/**
sl@0
  2987
Adds an extended precision value to this extended precision number.
sl@0
  2988
sl@0
  2989
@param aResult On return, a reference to an extended precision object
sl@0
  2990
               containing the result of the operation.
sl@0
  2991
@param aVal    The extended precision value to be added. 
sl@0
  2992
sl@0
  2993
@return KErrNone, if the operation is successful;
sl@0
  2994
        KErrOverflow, if the operation results in overflow;
sl@0
  2995
        KErrUnderflow, if the operation results in underflow. 
sl@0
  2996
*/
sl@0
  2997
	{
sl@0
  2998
	// on entry ecx=this, [esp+4]=address of aResult, [esp+8]=address of aVal
sl@0
  2999
	_asm push ebx				// save registers
sl@0
  3000
	_asm push ebp
sl@0
  3001
	_asm push esi
sl@0
  3002
	_asm push edi
sl@0
  3003
	_asm mov esi, ecx			// this into esi
sl@0
  3004
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  3005
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  3006
	_asm mov edx, [ecx+4]
sl@0
  3007
	_asm mov ecx, [ecx+8]
sl@0
  3008
	_asm call TRealXAdd			// do addition, result in ecx,edx:ebx, error code in eax
sl@0
  3009
	_asm mov esi, [esp+20]		// esi=address of aResult
sl@0
  3010
	_asm mov [esi], ebx			// store result
sl@0
  3011
	_asm mov [esi+4], edx
sl@0
  3012
	_asm mov [esi+8], ecx
sl@0
  3013
	_asm pop edi				// restore registers
sl@0
  3014
	_asm pop esi
sl@0
  3015
	_asm pop ebp
sl@0
  3016
	_asm pop ebx
sl@0
  3017
	_asm ret 8					// return with error code in eax
sl@0
  3018
	}
sl@0
  3019
sl@0
  3020
sl@0
  3021
sl@0
  3022
sl@0
  3023
__NAKED__ EXPORT_C TInt TRealX::Sub(TRealX& /*aResult*/, const TRealX& /*aVal*/) const
sl@0
  3024
/**
sl@0
  3025
Subtracts an extended precision value from this extended precision number.
sl@0
  3026
sl@0
  3027
@param aResult On return, a reference to an extended precision object
sl@0
  3028
               containing the result of the operation.
sl@0
  3029
@param aVal    The extended precision value to be subtracted. 
sl@0
  3030
sl@0
  3031
@return KErrNone, if the operation is successful;
sl@0
  3032
        KErrOverflow, if the operation results in overflow;
sl@0
  3033
        KErrUnderflow, if the operation results in underflow. 
sl@0
  3034
*/
sl@0
  3035
	{
sl@0
  3036
	// on entry ecx=this, [esp+4]=address of aResult, [esp+8]=address of aVal
sl@0
  3037
	_asm push ebx				// save registers
sl@0
  3038
	_asm push ebp
sl@0
  3039
	_asm push esi
sl@0
  3040
	_asm push edi
sl@0
  3041
	_asm mov esi, ecx			// this into esi
sl@0
  3042
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  3043
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  3044
	_asm mov edx, [ecx+4]
sl@0
  3045
	_asm mov ecx, [ecx+8]
sl@0
  3046
	_asm call TRealXSubtract	// do subtraction, result in ecx,edx:ebx, error code in eax
sl@0
  3047
	_asm mov esi, [esp+20]		// esi=address of aResult
sl@0
  3048
	_asm mov [esi], ebx			// store result
sl@0
  3049
	_asm mov [esi+4], edx
sl@0
  3050
	_asm mov [esi+8], ecx
sl@0
  3051
	_asm pop edi				// restore registers
sl@0
  3052
	_asm pop esi
sl@0
  3053
	_asm pop ebp
sl@0
  3054
	_asm pop ebx
sl@0
  3055
	_asm ret 8					// return with error code in eax
sl@0
  3056
	}
sl@0
  3057
sl@0
  3058
sl@0
  3059
sl@0
  3060
sl@0
  3061
__NAKED__ EXPORT_C TInt TRealX::Mult(TRealX& /*aResult*/, const TRealX& /*aVal*/) const
sl@0
  3062
/**
sl@0
  3063
Multiplies this extended precision number by an extended precision value.
sl@0
  3064
sl@0
  3065
@param aResult On return, a reference to an extended precision object
sl@0
  3066
               containing the result of the operation.
sl@0
  3067
@param aVal    The extended precision value to be used as the multiplier. 
sl@0
  3068
sl@0
  3069
@return KErrNone, if the operation is successful;
sl@0
  3070
        KErrOverflow, if the operation results in overflow;
sl@0
  3071
        KErrUnderflow, if the operation results in underflow. 
sl@0
  3072
*/
sl@0
  3073
	{
sl@0
  3074
	// on entry ecx=this, [esp+4]=address of aResult, [esp+8]=address of aVal
sl@0
  3075
	_asm push ebx				// save registers
sl@0
  3076
	_asm push ebp
sl@0
  3077
	_asm push esi
sl@0
  3078
	_asm push edi
sl@0
  3079
	_asm mov esi, ecx			// this into esi
sl@0
  3080
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  3081
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  3082
	_asm mov edx, [ecx+4]
sl@0
  3083
	_asm mov ecx, [ecx+8]
sl@0
  3084
	_asm call TRealXMultiply	// do multiplication, result in ecx,edx:ebx, error code in eax
sl@0
  3085
	_asm mov esi, [esp+20]		// esi=address of aResult
sl@0
  3086
	_asm mov [esi], ebx			// store result
sl@0
  3087
	_asm mov [esi+4], edx
sl@0
  3088
	_asm mov [esi+8], ecx
sl@0
  3089
	_asm pop edi				// restore registers
sl@0
  3090
	_asm pop esi
sl@0
  3091
	_asm pop ebp
sl@0
  3092
	_asm pop ebx
sl@0
  3093
	_asm ret 8					// return with error code in eax
sl@0
  3094
	}
sl@0
  3095
sl@0
  3096
sl@0
  3097
sl@0
  3098
sl@0
  3099
__NAKED__ EXPORT_C TInt TRealX::Div(TRealX& /*aResult*/, const TRealX& /*aVal*/) const
sl@0
  3100
/**
sl@0
  3101
Divides this extended precision number by an extended precision value.
sl@0
  3102
sl@0
  3103
@param aResult On return, a reference to an extended precision object
sl@0
  3104
               containing the result of the operation.
sl@0
  3105
@param aVal    The extended precision value to be used as the divisor.
sl@0
  3106
sl@0
  3107
@return KErrNone, if the operation is successful;
sl@0
  3108
        KErrOverflow, if the operation results in overflow;
sl@0
  3109
        KErrUnderflow, if the operation results in underflow;
sl@0
  3110
        KErrDivideByZero, if the divisor is zero.
sl@0
  3111
*/
sl@0
  3112
	{
sl@0
  3113
	// on entry ecx=this, [esp+4]=address of aResult, [esp+8]=address of aVal
sl@0
  3114
	_asm push ebx				// save registers
sl@0
  3115
	_asm push ebp
sl@0
  3116
	_asm push esi
sl@0
  3117
	_asm push edi
sl@0
  3118
	_asm mov esi, ecx			// this into esi
sl@0
  3119
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  3120
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  3121
	_asm mov edx, [ecx+4]
sl@0
  3122
	_asm mov ecx, [ecx+8]
sl@0
  3123
	_asm call TRealXDivide		// do division, result in ecx,edx:ebx, error code in eax
sl@0
  3124
	_asm mov esi, [esp+20]		// esi=address of aResult
sl@0
  3125
	_asm mov [esi], ebx			// store result
sl@0
  3126
	_asm mov [esi+4], edx
sl@0
  3127
	_asm mov [esi+8], ecx
sl@0
  3128
	_asm pop edi				// restore registers
sl@0
  3129
	_asm pop esi
sl@0
  3130
	_asm pop ebp
sl@0
  3131
	_asm pop ebx
sl@0
  3132
	_asm ret 8					// return with error code in eax
sl@0
  3133
	}
sl@0
  3134
sl@0
  3135
sl@0
  3136
sl@0
  3137
sl@0
  3138
__NAKED__ EXPORT_C TInt TRealX::Mod(TRealX& /*aResult*/, const TRealX& /*aVal*/) const
sl@0
  3139
/**
sl@0
  3140
Modulo-divides this extended precision number by an extended precision value.
sl@0
  3141
sl@0
  3142
@param aResult On return, a reference to an extended precision object
sl@0
  3143
               containing the result of the operation.
sl@0
  3144
sl@0
  3145
@param aVal    The extended precision value to be used as the divisor. 
sl@0
  3146
sl@0
  3147
@return KErrNone, if the operation is successful;
sl@0
  3148
        KErrTotalLossOfPrecision, if precision is lost;
sl@0
  3149
        KErrUnderflow, if the operation results in underflow.
sl@0
  3150
*/
sl@0
  3151
	{
sl@0
  3152
	// on entry ecx=this, [esp+4]=address of aResult, [esp+8]=address of aVal
sl@0
  3153
	_asm push ebx				// save registers
sl@0
  3154
	_asm push ebp
sl@0
  3155
	_asm push esi
sl@0
  3156
	_asm push edi
sl@0
  3157
	_asm mov esi, ecx			// this into esi
sl@0
  3158
	_asm mov ecx, [esp+24]		// address of aVal into ecx
sl@0
  3159
	_asm mov ebx, [ecx]			// aVal into ecx,edx:ebx
sl@0
  3160
	_asm mov edx, [ecx+4]
sl@0
  3161
	_asm mov ecx, [ecx+8]
sl@0
  3162
	_asm call TRealXModulo		// do modulo, result in ecx,edx:ebx, error code in eax
sl@0
  3163
	_asm mov esi, [esp+20]		// esi=address of aResult
sl@0
  3164
	_asm mov [esi], ebx			// store result
sl@0
  3165
	_asm mov [esi+4], edx
sl@0
  3166
	_asm mov [esi+8], ecx
sl@0
  3167
	_asm pop edi				// restore registers
sl@0
  3168
	_asm pop esi
sl@0
  3169
	_asm pop ebp
sl@0
  3170
	_asm pop ebx
sl@0
  3171
	_asm ret 8					// return with error code in eax
sl@0
  3172
	}
sl@0
  3173
sl@0
  3174
// Compare TRealX in ecx,edx:ebx (op1) to TRealX at [esi] (op2)
sl@0
  3175
// Return 1 if op1<op2
sl@0
  3176
// Return 2 if op1=op2
sl@0
  3177
// Return 4 if op1>op2
sl@0
  3178
// Return 8 if unordered
sl@0
  3179
// Return value in eax
sl@0
  3180
__NAKED__ LOCAL_C void TRealXCompare(void)
sl@0
  3181
	{
sl@0
  3182
	_asm cmp ecx, 0xFFFF0000	// check if op1=NaN or infinity
sl@0
  3183
	_asm jc short fpcmp1		// branch if not
sl@0
  3184
	_asm cmp edx, 0x80000000		// check for infinity
sl@0
  3185
	_asm jnz short fpcmpunord	// branch if NaN
sl@0
  3186
	_asm test ebx, ebx
sl@0
  3187
	_asm jz short fpcmp1		// if infinity, process normally
sl@0
  3188
	fpcmpunord:					// come here if unordered
sl@0
  3189
	_asm mov eax, 8				// return 8
sl@0
  3190
	_asm ret
sl@0
  3191
	fpcmp1:						// op1 is not a NaN
sl@0
  3192
	_asm mov eax, [esi+8]		// get op2 into eax,edi:ebp
sl@0
  3193
	_asm mov edi, [esi+4]
sl@0
  3194
	_asm mov ebp, [esi]
sl@0
  3195
	_asm cmp eax, 0xFFFF0000	// check for NaN or infinity
sl@0
  3196
	_asm jc short fpcmp2		// branch if neither
sl@0
  3197
	_asm cmp edi, 0x80000000		// check for infinity
sl@0
  3198
	_asm jnz short fpcmpunord	// branch if NaN
sl@0
  3199
	_asm test ebp, ebp
sl@0
  3200
	_asm jnz short fpcmpunord
sl@0
  3201
	fpcmp2:						// neither operand is a NaN
sl@0
  3202
	_asm cmp ecx, 0x10000		// check if op1=0
sl@0
  3203
	_asm jc short fpcmpop1z		// branch if it is
sl@0
  3204
	_asm cmp eax, 0x10000		// check if op2=0
sl@0
  3205
	_asm jc short fpcmp4		// branch if it is
sl@0
  3206
	_asm xor al, cl				// check if signs the same
sl@0
  3207
	_asm test al, 1
sl@0
  3208
	_asm jnz short fpcmp4		// branch if different
sl@0
  3209
	_asm push ecx
sl@0
  3210
	_asm shr ecx, 16			// op1 exponent into cx
sl@0
  3211
	_asm shr eax, 16			// op2 exponent into ax
sl@0
  3212
	_asm cmp ecx, eax			// compare exponents
sl@0
  3213
	_asm pop ecx
sl@0
  3214
	_asm ja short fpcmp4		// if op1 exp > op2 exp op1>op2 if +ve
sl@0
  3215
	_asm jb short fpcmp5		// if op1 exp < op2 exp op1<op2 if +ve
sl@0
  3216
	_asm cmp edx, edi			// else compare mantissa high words
sl@0
  3217
	_asm ja short fpcmp4
sl@0
  3218
	_asm jb short fpcmp5
sl@0
  3219
	_asm cmp ebx, ebp			// if equal compare mantissa low words
sl@0
  3220
	_asm ja short fpcmp4
sl@0
  3221
	_asm jb short fpcmp5
sl@0
  3222
	fpcmp0:
sl@0
  3223
	_asm mov eax, 2				// numbers exactly equal
sl@0
  3224
	_asm ret
sl@0
  3225
	fpcmp4:						// come here if ABS(op1)>ABS(op2) or if signs different
sl@0
  3226
								// or if op2 zero, op1 nonzero
sl@0
  3227
	_asm mov eax, 4				// return 4 if +ve
sl@0
  3228
	_asm test cl, 1				// check sign
sl@0
  3229
	_asm jz short fpcmp4a		// skip if +
sl@0
  3230
	_asm mov al, 1				// return 1 if -ve
sl@0
  3231
	fpcmp4a:
sl@0
  3232
	_asm ret
sl@0
  3233
	fpcmp5:						// come here if ABS(op1)<ABS(op2)
sl@0
  3234
	_asm mov eax, 1				// return 1 if +ve
sl@0
  3235
	_asm test cl, 1				// check sign
sl@0
  3236
	_asm jz short fpcmp5a		// skip if +
sl@0
  3237
	_asm mov al, 4				// return 4 if -ve
sl@0
  3238
	fpcmp5a:
sl@0
  3239
	_asm ret
sl@0
  3240
	fpcmpop1z:					// come here if op1=0
sl@0
  3241
	_asm cmp eax, 0x10000		// check if op2 also zero
sl@0
  3242
	_asm jc short fpcmp0		// if so, they are equal
sl@0
  3243
	_asm test al, 1				// test sign of op 2
sl@0
  3244
	_asm mov eax, 4				// if -, return 4
sl@0
  3245
	_asm jnz short fpcmpop1z2n	// skip if -
sl@0
  3246
	_asm mov al, 1				// else return 1
sl@0
  3247
	fpcmpop1z2n:
sl@0
  3248
	_asm ret
sl@0
  3249
	}
sl@0
  3250
sl@0
  3251
sl@0
  3252
sl@0
  3253
sl@0
  3254
__NAKED__ EXPORT_C TRealX::TRealXOrder TRealX::Compare(const TRealX& /*aVal*/) const
sl@0
  3255
/**
sl@0
  3256
*/
sl@0
  3257
	{
sl@0
  3258
	// On entry ecx=this, [esp+4]=address of aVal
sl@0
  3259
	_asm push ebx				// save registers
sl@0
  3260
	_asm push ebp
sl@0
  3261
	_asm push esi
sl@0
  3262
	_asm push edi
sl@0
  3263
	_asm mov esi, [esp+20]		// address of aVal into esi
sl@0
  3264
	_asm mov ebx, [ecx]			// *this into ecx,edx:ebx
sl@0
  3265
	_asm mov edx, [ecx+4]
sl@0
  3266
	_asm mov ecx, [ecx+8]
sl@0
  3267
	_asm call TRealXCompare		// result in eax
sl@0
  3268
	_asm pop edi
sl@0
  3269
	_asm pop esi
sl@0
  3270
	_asm pop ebp
sl@0
  3271
	_asm pop ebx
sl@0
  3272
	_asm ret 4
sl@0
  3273
	}
sl@0
  3274
sl@0
  3275
sl@0
  3276
sl@0
  3277
sl@0
  3278
#pragma warning (default : 4100)	// unreferenced formal parameter
sl@0
  3279
#pragma warning (default : 4414)	// short jump converted to near
sl@0
  3280
#pragma warning (default : 4700)	// local variable 'this' used without having been initialised
sl@0
  3281