mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-29 01:39:41 +03:00
Clib string & memory functions
git-svn-id: svn://kolibrios.org@553 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
d5f66e011c
commit
836c97f0ac
99
programs/develop/open watcom/trunk/clib/cgsupp/7fu8386.asm
Normal file
99
programs/develop/open watcom/trunk/clib/cgsupp/7fu8386.asm
Normal file
@ -0,0 +1,99 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
.8087
|
||||
modstart _7fu8386
|
||||
|
||||
xdefp __FSU87
|
||||
xdefp __FDU87
|
||||
|
||||
defpe __FSU87
|
||||
sub esp,12
|
||||
mov [esp],eax
|
||||
fld dword ptr [esp]
|
||||
jmp short convert
|
||||
|
||||
defpe __FDU87
|
||||
sub esp,12
|
||||
mov [esp],eax
|
||||
mov 4[esp],edx
|
||||
fld qword ptr [esp]
|
||||
|
||||
; fall through
|
||||
|
||||
convert:
|
||||
push ecx
|
||||
fstp tbyte ptr 4[esp] ; get number out in memory
|
||||
mov ax,12[esp] ; pick up sign/exponent
|
||||
and ax,7fffh ; isolate exponent
|
||||
sub ax,16383 ; remove bias
|
||||
jl ret_zero ; if less than .5, return zero
|
||||
cmp ax,64 ; are we too big?
|
||||
jae ret_inf ; if so, return infinity
|
||||
mov cl,63 ; calculate shift count
|
||||
sub cl,al ; ...
|
||||
mov eax,4[esp] ; pick up mantissa
|
||||
mov edx,8[esp] ; ...
|
||||
je negate ; skip out if no shifting
|
||||
L2:
|
||||
shr edx,1 ; shift down one bit
|
||||
rcr eax,1 ; ...
|
||||
dec cl ; are we done?
|
||||
jne L2 ; do it again if not
|
||||
negate:
|
||||
test byte ptr 13[esp],80h ; is number negative?
|
||||
jns done ; if not, we're done
|
||||
neg edx ; negate number
|
||||
neg eax ; ...
|
||||
sbb edx,0 ; ...
|
||||
done:
|
||||
pop ecx ; ...
|
||||
add esp,12 ; outta here
|
||||
ret ; ...
|
||||
|
||||
ret_zero:
|
||||
xor edx,edx
|
||||
xor eax,eax
|
||||
jmp done
|
||||
|
||||
ret_inf:
|
||||
mov edx,0ffffffffh
|
||||
mov eax,edx
|
||||
jmp done
|
||||
endproc __FDU87
|
||||
endproc __FSU87
|
||||
|
||||
endmod
|
||||
end
|
81
programs/develop/open watcom/trunk/clib/cgsupp/7u8f386.asm
Normal file
81
programs/develop/open watcom/trunk/clib/cgsupp/7u8f386.asm
Normal file
@ -0,0 +1,81 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
.8087
|
||||
modstart _7u8f386
|
||||
|
||||
xdefp __U8FD7
|
||||
xdefp __U8FS7
|
||||
|
||||
;;;;two_to_64 dw 0000h, 0000h, 0000h, 43f0h ; removed by JBS
|
||||
|
||||
ULLMXP1:
|
||||
DB 00H, 00H, 80H, 5FH ; (float)(ULONGLONG_MAX +1)
|
||||
; (only exponent set)
|
||||
|
||||
defpe __U8FS7
|
||||
push edx ; save unsigned int64 (hi)
|
||||
push eax ; save unsigned int64 (lo)
|
||||
fild qword ptr [esp] ; load as int64
|
||||
test byte ptr 07H[esp],80H ; most significant bit set?
|
||||
jns L$2 ; no, jump
|
||||
fadd dword ptr cs:ULLMXP1 ; correct int64 to unsigned int64 as
|
||||
; as float (because expression is exact
|
||||
; in powers of 2, so save 4 bytes)
|
||||
L$2:
|
||||
pop eax ; correct stack
|
||||
fstp dword ptr [esp] ; save float and pop coproc stack
|
||||
pop eax ; return float in eax
|
||||
ret
|
||||
endproc __U8FS7
|
||||
|
||||
defpe __U8FD7
|
||||
push edx ; save unsigned int64 (hi)
|
||||
push eax ; save unsigned int64 (lo)
|
||||
fild qword ptr [esp] ; load as int64
|
||||
test byte ptr 07H[esp],80H ; most significant bit set?
|
||||
jns L$3 ; no, jump
|
||||
fadd dword ptr cs:ULLMXP1 ; correct int64 to unsigned int64 as
|
||||
; as float (because expression is exact
|
||||
; in powers of 2, so save 4 bytes)
|
||||
L$3:
|
||||
fstp qword ptr [esp] ; save double and pop coproc stack
|
||||
pop eax ; return double (lo)
|
||||
pop edx ; return double (hi)
|
||||
ret
|
||||
endproc __U8FD7
|
||||
|
||||
endmod
|
||||
end
|
68
programs/develop/open watcom/trunk/clib/cgsupp/__copy.asm
Normal file
68
programs/develop/open watcom/trunk/clib/cgsupp/__copy.asm
Normal file
@ -0,0 +1,68 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
; char *__COPY( char *dst, char *src, unsigned len );
|
||||
;
|
||||
;
|
||||
include mdef.inc
|
||||
|
||||
name __copy
|
||||
_TEXT segment use32 para public 'CODE'
|
||||
assume cs:_TEXT
|
||||
|
||||
public __COPY
|
||||
public __COPY_
|
||||
|
||||
__COPY proc near
|
||||
__COPY_ proc near
|
||||
push edi ; save regs
|
||||
push esi ; ...
|
||||
push ecx ; ...
|
||||
mov edi,16+0[esp] ; get dst
|
||||
mov esi,16+4[esp] ; get src
|
||||
mov ecx,16+8[esp] ; get len
|
||||
mov eax,edi ; return with dst ptr in eax
|
||||
shr ecx,2 ; calc. # of dwords
|
||||
rep movsd ; do the copy
|
||||
mov ecx,16+8[esp] ; get len
|
||||
and ecx,3 ; plus extra bytes
|
||||
rep movsb ; do the copy
|
||||
pop ecx ; restore regs
|
||||
pop esi ; ...
|
||||
pop edi ; ...
|
||||
ret 12 ; return and remove parms
|
||||
__COPY_ endp
|
||||
__COPY endp
|
||||
|
||||
_TEXT ends
|
||||
end
|
143
programs/develop/open watcom/trunk/clib/cgsupp/__stos.asm
Normal file
143
programs/develop/open watcom/trunk/clib/cgsupp/__stos.asm
Normal file
@ -0,0 +1,143 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
; __STOSB( char *EAX, int EDX, unsigned ECX );
|
||||
; __STOSD( char *EAX, int EDX, unsigned ECX );
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart __stos,para
|
||||
|
||||
xdefp __STOSB
|
||||
xdefp __STOSD
|
||||
|
||||
|
||||
defpe __STOSB
|
||||
or ECX,ECX ; if length not zero
|
||||
_if ne ; then
|
||||
cmp [EAX],DL ; - access cache line
|
||||
_loop ; - loop (get onto 4-byte boundary)
|
||||
test AL,3 ; - - quit if on 4-byte boundary
|
||||
_quif e ; - - ...
|
||||
mov [EAX],DL ; - - store byte
|
||||
inc EAX ; - - increment address
|
||||
ror EDX,8 ; - - (DH can be different from DL)
|
||||
dec ECX ; - - decrement length
|
||||
_until e ; - until done
|
||||
push ECX ; - save length
|
||||
shr ECX,2 ; - calculate number of dwords
|
||||
call __STOSD ; - store dwords
|
||||
pop ECX ; - restore length
|
||||
_guess ; - guess: some bytes left to do
|
||||
and ECX,3 ; - - calculate number of bytes left
|
||||
_quif e ; - - quit if done
|
||||
mov [EAX],DL ; - - store a byte
|
||||
dec ECX ; - - decrement length
|
||||
_quif e ; - - quit if done
|
||||
mov 1[EAX],DH ; - - store a byte
|
||||
dec ECX ; - - decrement length
|
||||
_quif e ; - - quit if done
|
||||
mov 2[EAX],DL ; - - store a byte
|
||||
_endguess ; - endguess
|
||||
_endif ; endif
|
||||
ret ; return
|
||||
endproc __STOSB
|
||||
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
|
||||
defpe __STOSD
|
||||
or ECX,ECX ; if length not zero
|
||||
_if ne ; then
|
||||
_loop ; - loop (get onto 32-byte boundary)
|
||||
test AL,1Fh ; - - quit if on 32-byte boundary
|
||||
_quif e ; - - ...
|
||||
mov [EAX],EDX ; - - store dword
|
||||
lea EAX,4[EAX] ; - - increment address
|
||||
dec ECX ; - - decrement length
|
||||
_until e ; - until done
|
||||
push ECX ; - save length
|
||||
shr ECX,2 ; - calculate number of paragraphs
|
||||
_if ne ; - if at least one paragraph
|
||||
dec ECX ; - - decrement # of paragraphs
|
||||
_if ne ; - - if still have paragraphs to do
|
||||
_loop ; - - - loop
|
||||
mov [EAX],EDX ; - - - - store dword
|
||||
mov 4[EAX],EDX ; - - - - ...
|
||||
dec ECX ; - - - - decrement count
|
||||
mov 8[EAX],EDX ; - - - - store dword
|
||||
mov 12[EAX],EDX ; - - - - ...
|
||||
je short add16 ; - - - - quit if done
|
||||
cmp 32[EAX],DL ; - - - - access next cache line
|
||||
mov 16[EAX],EDX ; - - - - store dword
|
||||
mov 20[EAX],EDX ; - - - - ...
|
||||
dec ECX ; - - - - decrement count
|
||||
mov 24[EAX],EDX ; - - - - store dword
|
||||
mov 28[EAX],EDX ; - - - - ...
|
||||
lea EAX,32[EAX] ; - - - - advance to next 32-byte chunk
|
||||
_until e ; - - - until done
|
||||
lea EAX,-16[EAX] ; - - - back up 16
|
||||
add16: lea EAX,16[EAX] ; - - - advance 16
|
||||
_endif ; - - endif
|
||||
mov [EAX],EDX ; - - fill last full paragraph
|
||||
mov 4[EAX],EDX ; - - ...
|
||||
mov 8[EAX],EDX ; - - ...
|
||||
mov 12[EAX],EDX ; - - ...
|
||||
lea EAX,16[EAX] ; - - advance pointer
|
||||
_endif ; - endif
|
||||
pop ECX ; - restore length
|
||||
_guess ; - guess: some dwords left to do
|
||||
and ECX,3 ; - - calculate number of dwords left
|
||||
_quif e ; - - quit if done
|
||||
mov [EAX],EDX ; - - store dword
|
||||
lea EAX,4[EAX] ; - - advance pointer
|
||||
dec ECX ; - - decrement length
|
||||
_quif e ; - - quit if done
|
||||
mov [EAX],EDX ; - - store dword
|
||||
lea EAX,4[EAX] ; - - advance pointer
|
||||
dec ECX ; - - decrement length
|
||||
_quif e ; - - quit if done
|
||||
mov [EAX],EDX ; - - store dword
|
||||
lea EAX,4[EAX] ; - - advance pointer
|
||||
_endguess ; - endguess
|
||||
_endif ; endif
|
||||
ret ; return
|
||||
endproc __STOSD
|
||||
|
||||
endmod
|
||||
end
|
237
programs/develop/open watcom/trunk/clib/cgsupp/amodf386.asm
Normal file
237
programs/develop/open watcom/trunk/clib/cgsupp/amodf386.asm
Normal file
@ -0,0 +1,237 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
; double modf( double value, double *iptr );
|
||||
;
|
||||
; Description:
|
||||
; The modf function breaks the argument value into integral and
|
||||
; fractional parts, each of which has the same sign as the argument.
|
||||
; It stores the integral part as a double in the object pointed to
|
||||
; by iptr.
|
||||
;
|
||||
; Returns:
|
||||
; The modf function returns the signed fractional part of value.
|
||||
;
|
||||
; 18-oct-86 ... Fraction in Modf not computed right
|
||||
; significant digits
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart amodf386
|
||||
|
||||
xdefp __ModF
|
||||
xdefp __ZBuf2F
|
||||
|
||||
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
|
||||
;[]
|
||||
;[] __ModF
|
||||
;[]
|
||||
;[] void __ModF( double near *AX, double near *DX );
|
||||
;[] Input: EAX - pointer to double precision float
|
||||
;[] EDX - place to store integral part
|
||||
;[] Output: [EAX] - fractional part of value.
|
||||
;[] [EDX] - integral part of value
|
||||
;[]
|
||||
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
|
||||
|
||||
defpe __ModF
|
||||
push EBP ; save BP
|
||||
push ESI ; save SI
|
||||
push EDI ; save DI
|
||||
push ECX ; save CX
|
||||
push EBX ; save BX
|
||||
mov ESI,EDX ; get address for ipart
|
||||
mov EBP,EAX ; get address of float
|
||||
mov EAX,0[EBP] ; get float
|
||||
mov EDX,4[EBP] ; . . .
|
||||
xchg ESI,EBP ; flip pointers
|
||||
mov 0[EBP],EAX ; store integral part of value
|
||||
mov 4[EBP],EDX ; . . .
|
||||
_guess ; guess: fraction is zero
|
||||
mov ECX,EDX ; - get exponent
|
||||
and ECX,7FF00000h ; - get exponent part of R into DI
|
||||
je short done ; - set integer part to 0 if exponent = 0
|
||||
cmp ECX,(3FFh+52) shl 20; - check for exponent > 52
|
||||
_quif b ; - quit if fraction not zero
|
||||
xchg EBP,ESI ; - get address of fractional part
|
||||
done: sub EAX,EAX ; - set fraction(or integer) to 0
|
||||
mov 4[EBP],EAX ; - . . .
|
||||
mov 0[EBP],EAX ; - . . .
|
||||
pop EBX ; - restore BX
|
||||
pop ECX ; - restore CX
|
||||
pop EDI ; - restore DI
|
||||
pop ESI ; - restore SI
|
||||
pop EBP ; - restore BP
|
||||
ret ; - return
|
||||
_endguess ; endguess
|
||||
mov EDI,ECX ; save exponent
|
||||
shr ECX,20 ; move exponent to bottom
|
||||
sub CX,03FFh ; remove bias
|
||||
jb done ; quit if number < 1.0
|
||||
push EDX ; save sign
|
||||
sub EAX,EAX ; initialize mask to 0
|
||||
mov EDX,0FFF00000h ; ...
|
||||
cmp CL,20 ; if exponent > 20
|
||||
_if a ; then
|
||||
sar EDX,21 ; - set ESI to all ones
|
||||
rcr EAX,1 ; - set high bit of EBX
|
||||
sub CL,21 ; - get shift count for second part
|
||||
sar EAX,CL ; - create rest of mask
|
||||
_else ; else
|
||||
sar EDX,CL ; - create mask in high part only
|
||||
_endif ; endif
|
||||
and 4[EBP],EDX ; mask off the remaining fraction bits
|
||||
and 0[EBP],EAX ; . . .
|
||||
not EDX ; complement the mask to get fractional part
|
||||
not EAX ; . . .
|
||||
mov EBP,ESI ; get address of fractional part
|
||||
and EDX,4[EBP] ; get fraction bits
|
||||
and EAX,0[EBP] ; . . .
|
||||
call Norm ; normalize the fraction
|
||||
pop ESI ; restore sign
|
||||
or EDX,EDX ; if fraction is not 0
|
||||
_if ne ; then
|
||||
and ESI,80000000h ; - isolate sign
|
||||
or EDX,ESI ; - set sign in fractional part
|
||||
_endif ; endif
|
||||
mov 4[EBP],EDX ; store fractional part
|
||||
mov 0[EBP],EAX ; . . .
|
||||
pop EBX ; restore BX
|
||||
pop ECX ; restore CX
|
||||
pop EDI ; restore DI
|
||||
pop ESI ; restore SI
|
||||
pop EBP ; restore BP
|
||||
ret ; return
|
||||
endproc __ModF
|
||||
|
||||
|
||||
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
|
||||
;<> <>
|
||||
;<> __ZBuf2F - convert buffer of significant digits into floating <>
|
||||
;<> void __ZBuf2F( char near *buf, double near *value ) <>
|
||||
;<> <>
|
||||
;<> input: EAX - address of buffer of significant digits <>
|
||||
;<> EDX - place to store value <>
|
||||
;<> output: [EDX] - floating point number <>
|
||||
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
|
||||
|
||||
defpe __ZBuf2F
|
||||
push EBP ; save BP
|
||||
push ESI ; save SI
|
||||
push EDI ; save DI
|
||||
push ECX ; save CX
|
||||
push EBX ; save BX
|
||||
push EDX ; save pointer to result
|
||||
mov ESI,EAX ; get address of buffer
|
||||
sub EDX,EDX ; set 54-bit integer to 0
|
||||
sub ECX,ECX ; . . .
|
||||
sub EAX,EAX ; zero out EAX
|
||||
_loop ; loop (convert digits into 54-bit int)
|
||||
mov AL,[ESI] ; - get next digit
|
||||
cmp AL,0 ; - quit if at end of buffer
|
||||
_quif e ; - . . .
|
||||
|
||||
;[] multiply current value in EDX:ECX by 10
|
||||
|
||||
mov EDI,EDX ; - save current value
|
||||
mov EBX,ECX ; - ...
|
||||
_shl ECX,1 ; - multiply number by 4
|
||||
_rcl EDX,1 ; - by shifting left 2 places
|
||||
_shl ECX,1 ; - . . .
|
||||
_rcl EDX,1 ; - . . .
|
||||
add ECX,EBX ; - add original value
|
||||
adc EDX,EDI ; - (this will make it times 5)
|
||||
_shl ECX,1 ; - shift left to make it times 10
|
||||
_rcl EDX,1 ; - . . .
|
||||
and AL,0Fh ; - isolate binary digit
|
||||
add ECX,EAX ; - add in current digit
|
||||
adc EDX,0 ; - . . .
|
||||
inc ESI ; - point to next digit in buffer
|
||||
_endloop ; endloop
|
||||
mov EAX,ECX ; get low order word into EAX
|
||||
|
||||
;[] Turn the integer in EDX:EAX into a real number
|
||||
|
||||
mov EDI,(3FFh+52) shl 20; set exponent
|
||||
call Norm ; convert the 52 bit integer to a float
|
||||
pop EBP ; restore pointer to result
|
||||
mov 4[EBP],EDX ; store result
|
||||
mov 0[EBP],EAX ; . . .
|
||||
pop EBX ; restore BX
|
||||
pop ECX ; restore CX
|
||||
pop EDI ; restore DI
|
||||
pop ESI ; restore SI
|
||||
pop EBP ; restore BP
|
||||
ret ; return to caller
|
||||
endproc __ZBuf2F
|
||||
|
||||
|
||||
;[] Norm normalizes an unsigned real in EDX:EAX
|
||||
;[] expects the exponent to be in EDI. The real returned is in 'packed'
|
||||
;[] format
|
||||
;[] ESI is destroyed
|
||||
|
||||
Norm proc near ; normalize floating point number
|
||||
sub ESI,ESI ; clear out SI
|
||||
or ESI,EAX ; see if the integer is zero
|
||||
or ESI,EDX ; . . .
|
||||
je short Z_52ret ; if integer is zero, return to caller
|
||||
test EDX,0FFF00000h ; see if we have to shift forward or backward
|
||||
_if e ; if (we haven't shifted msb into bit 53)
|
||||
_loop ; - loop
|
||||
sub EDI,00100000h ; - - exp <-- exp - 1
|
||||
_shl EAX,1 ; - - shift integer left by 1 bit
|
||||
_rcl EDX,1 ; - - . . .
|
||||
test EDX,0FFF00000h;
|
||||
_until ne ; - until( msb is shifted into bit 53 )
|
||||
_else ; else (we must shift to the right)
|
||||
test EDX,0FFE00000h ; -
|
||||
je short done1 ; - if msb is bit 53, we are done
|
||||
_loop ; - loop
|
||||
add EDI,00100000h ; - - exp <-- exp + 1
|
||||
shr EDX,1 ; - - shift integer right by 1 bit
|
||||
rcr EAX,1 ; - - . . .
|
||||
rcr ESI,1 ; - - save lsb
|
||||
test EDX,0FFE00000h; -
|
||||
_until e ; - until( msb is bit 53 )
|
||||
_rcl ESI,1 ; - get lsb
|
||||
adc EAX,0 ; - and use it to round off the number
|
||||
adc EDX,0 ; - . . .
|
||||
_endif ; endif
|
||||
done1: and EDX,000FFFFFh ; clear out implied bit
|
||||
or EDX,EDI ; put in exponent
|
||||
Z_52ret:ret ; return
|
||||
endproc Norm
|
||||
|
||||
endmod
|
||||
end
|
307
programs/develop/open watcom/trunk/clib/cgsupp/div386.asm
Normal file
307
programs/develop/open watcom/trunk/clib/cgsupp/div386.asm
Normal file
@ -0,0 +1,307 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
.8087
|
||||
modstart div386
|
||||
|
||||
xref __8087 ; indicate that NDP instructions are present
|
||||
|
||||
datasegment
|
||||
extrn __real87 : byte ; 8087.asm
|
||||
extrn __chipbug: byte
|
||||
enddata
|
||||
|
||||
xref F8DivZero ; Fstatus
|
||||
xref F8OverFlow ; Fstatus
|
||||
xref F8UnderFlow ; Fstatus
|
||||
xref __fdiv_m64
|
||||
|
||||
xdefp __FDD
|
||||
|
||||
; double __FDD( double , double )
|
||||
sign equ -12
|
||||
den equ sign-8
|
||||
quot equ den-12
|
||||
lo equ 0
|
||||
hi equ 4
|
||||
|
||||
defpe __FDD
|
||||
or EBX,EBX ; if low word of divisor is 0
|
||||
_if e ; then
|
||||
_shl ECX,1 ; - shift sign of divisor into carry
|
||||
_if e ; - if divisor is zero
|
||||
jmp F8DivZero ; - - handle divide by zero
|
||||
_endif ; - endif
|
||||
rcr ECX,1 ; - restore sign of divisor
|
||||
_endif ; endif
|
||||
or EAX,EAX ; check dividend for zero
|
||||
_if e ; if so then
|
||||
_shl EDX,1 ; - save sign of dividend
|
||||
_if e ; - if dividend is 0
|
||||
ret ; - - return
|
||||
_endif ; - endif
|
||||
rcr EDX,1 ; - restore sign of dividend
|
||||
_endif ; endif
|
||||
|
||||
cmp byte ptr __real87,0 ; if no 80x87 is present
|
||||
je short __FDDemu ; then emulate
|
||||
|
||||
__FDD87:
|
||||
push EDX ; push operand 1
|
||||
push EAX ; . . .
|
||||
fld qword ptr [ESP] ; load operand 1
|
||||
push ECX ; push operand 2
|
||||
push EBX ; . . .
|
||||
test byte ptr __chipbug,1 ; have we got a bad divider?
|
||||
_if ne ; then
|
||||
call __fdiv_m64 ; - call support rtn for divide
|
||||
_else ; else
|
||||
fdiv qword ptr [ESP] ; - divide operand 1 by operand 2
|
||||
add ESP,8 ; - clean up stack
|
||||
_endif ; endif
|
||||
fstp qword ptr [ESP] ; store result
|
||||
fwait ; wait
|
||||
pop EAX ; load result into DX:AX
|
||||
pop EDX ; . . .
|
||||
cmp EDX,80000000H ; is it a negative zero?
|
||||
_if e ; if it is then
|
||||
sub EDX,EDX ; - make it positive 0.0
|
||||
mov EAX,EDX ; - ...
|
||||
_endif ; endif
|
||||
ret ; return
|
||||
|
||||
__FDDemu:
|
||||
push EBP ; save EBP
|
||||
mov EBP,ESP ; get access to stack
|
||||
push EDI ; save EDI
|
||||
push ESI ; and ESI
|
||||
|
||||
mov EDI,EDX ; get high part of op1
|
||||
mov ESI,ECX ; get high part of op2
|
||||
sar EDI,20 ; shift exponent to bottom, duplicating sign
|
||||
sar ECX,20 ; shift exponent to bottom, duplicating sign
|
||||
and EDI,0800007FFh ; isolate signs and exponent
|
||||
and ECX,0800007FFh ; ...
|
||||
rol EDI,16 ; rotate signs to bottom
|
||||
rol ECX,16 ; ...
|
||||
add DI,CX ; calc sign of result
|
||||
rol EDI,16 ; rotate signs to top
|
||||
rol ECX,16 ; ...
|
||||
and EDX,000FFFFFh ; isolate fraction
|
||||
and ESI,000FFFFFh ; isolate fraction
|
||||
or DI,DI ; if op1 is not a denormal
|
||||
_if ne ; then
|
||||
or EDX,00100000h ; - turn on implied 1 bit
|
||||
_else ; else (denormal)
|
||||
_loop ; - loop (normalize it)
|
||||
_shl EAX,1 ; - - shift fraction left
|
||||
_rcl EDX,1 ; - - . . .
|
||||
dec DI ; - - decrement exponent
|
||||
test EDX,00100000h ; - - until implied 1 bit is on
|
||||
_until ne ; - until implied 1 bit is on
|
||||
_endif ; endif
|
||||
or CX,CX ; if op2 is not a denormal
|
||||
_if ne ; then
|
||||
or ESI,00100000h ; - turn on implied 1 bit
|
||||
_else ; else (denormal)
|
||||
_loop ; - loop (normalize it)
|
||||
_shl EBX,1 ; - - shift fraction left
|
||||
_rcl ESI,1 ; - - . . .
|
||||
dec CX ; - - decrement exponent
|
||||
test ESI,00100000h ; - - until implied 1 bit is on
|
||||
_until ne ; - until implied 1 bit is on
|
||||
_endif ; endif
|
||||
|
||||
sub DI,CX ; calculate exponent of result
|
||||
add DI,03ffh ; add in removed bias
|
||||
_guess ; guess: overflow
|
||||
_quif s ; - quit if exponent is negative
|
||||
cmp DI,07FFh ; - quit if not overflow
|
||||
_quif b ; - . . .
|
||||
mov EAX,ECX ; - put sign into EAX
|
||||
pop ESI ; - restore ESI
|
||||
pop EDI ; - restore EDI
|
||||
pop EBP ; - restore EBP
|
||||
jmp F8OverFlow ; - handle overflow
|
||||
_endguess ; endguess
|
||||
cmp DI,-52 ; if exponent is too small
|
||||
_if l ; then underflow
|
||||
pop ESI ; - restore ESI
|
||||
pop EDI ; - restore EDI
|
||||
pop EBP ; - restore EBP
|
||||
jmp F8UnderFlow ; - handle underflow
|
||||
_endif ; endif
|
||||
|
||||
push EDI ; save sign and exponent
|
||||
mov CL,11 ; shift fractions to top of registers
|
||||
shld EDX,EAX,CL ; ...
|
||||
shld EAX,EBP,CL ; ...
|
||||
and EAX,0FFFFF800h ; ...
|
||||
shld ESI,EBX,CL ; ...
|
||||
shld EBX,EBP,CL ; ...
|
||||
and EBX,0FFFFF800h ; ...
|
||||
push ESI ; save divisor
|
||||
push EBX ; ...
|
||||
mov ECX,ESI ; get top part of divisor
|
||||
mov EDI,EDX ; get dividend
|
||||
mov ESI,EAX ; ...
|
||||
sub EAX,EAX ; assume top bit is 0
|
||||
cmp ECX,EDX ; check high parts
|
||||
_if be ; if hi(divisor) <= hi(dividend)
|
||||
sub EDX,ECX ; - subtract divisor from dividend
|
||||
inc EAX ; - set quotient to 1
|
||||
_endif ; endif
|
||||
push EAX ; save high word of quotient
|
||||
mov EAX,ESI ; get low part of dividend
|
||||
div ECX ; estimate next word of quotient
|
||||
push EAX ; save estimate of quotient (quot+4[EBP])
|
||||
xchg EAX,EBX ; save quot., get low word of divisor
|
||||
mul EBX ; calc. estimate * lo(divisor)
|
||||
xchg EAX,ECX ; ...
|
||||
xchg EBX,EDX ; save partial product
|
||||
mul EDX ; calc. estimate * hi(divisor)
|
||||
add EAX,EBX ; add to partial product
|
||||
adc EDX,0 ; ...
|
||||
mov EBX,den+lo[EBP] ; get low word of divisor
|
||||
test byte ptr quot+8[EBP],1 ; if high word of quot is 1
|
||||
_if ne ; then
|
||||
add EAX,EBX ; - add in divisor
|
||||
adc EDX,den+hi[EBP] ; - ...
|
||||
_endif ; endif
|
||||
; subtract estimate * divisor from dividend
|
||||
neg ECX ; 0 - ECX
|
||||
sbb ESI,EAX ; ...
|
||||
sbb EDI,EDX ; ...
|
||||
_if ne ; if high word not 0 (quotient too big)
|
||||
_loop ; - loop (find correct quotient)
|
||||
sub dword ptr quot+4[EBP],1; - - decrement quotient
|
||||
sbb dword ptr quot+8[EBP],0; - - ...
|
||||
add ECX,EBX ; - - add divisor back to dividend
|
||||
adc ESI,den+hi[EBP] ; - - ...
|
||||
adc EDI,0 ; - - ...
|
||||
_until e ; - until done
|
||||
_endif ; endif
|
||||
mov EDI,ESI ; get new dividend
|
||||
mov ESI,ECX ; ...
|
||||
mov ECX,den+hi[EBP] ; get divisor
|
||||
cmp ECX,EDI ; check high parts 13-aug-90
|
||||
_if be ; if hi(divisor) <= hi(dividend)
|
||||
sub EDI,ECX ; - subtract divisor from dividend
|
||||
add dword ptr quot+4[EBP],1 ; - increment quotient
|
||||
adc dword ptr quot+8[EBP],0 ; - ...
|
||||
_endif ; endif
|
||||
mov EDX,EDI ; get dividend into EDX:EAX
|
||||
mov EAX,ESI ; ...
|
||||
div ECX ; estimate next word of quotient
|
||||
push EAX ; save estimate of quotient (-4[EBP])
|
||||
or EAX,EAX ; if quotient non-zero
|
||||
_if ne ; then
|
||||
xchg EAX,EBX ; - save quot., get low word of divisor
|
||||
mul EBX ; - calc. estimate * lo(divisor)
|
||||
xchg EAX,ECX ; - ...
|
||||
xchg EBX,EDX ; - save partial product
|
||||
mul EDX ; - calc. estimate * hi(divisor)
|
||||
add EAX,EBX ; - add to partial product
|
||||
adc EDX,0 ; - ...
|
||||
; - subtract estimate * divisor from dividend
|
||||
neg ECX ; - 0 - ECX
|
||||
sbb ESI,EAX ; - ...
|
||||
sbb EDI,EDX ; - ...
|
||||
_if ne ; - if high word not 0 (quotient too big)
|
||||
_loop ; - - loop (find correct quotient)
|
||||
sub dword ptr quot+0[EBP],1; - - - decrement quotient
|
||||
sbb dword ptr quot+4[EBP],0; - - - ...
|
||||
sbb dword ptr quot+8[EBP],0; - - - ...
|
||||
add ECX,den+lo[EBP] ; - - - add divisor back to dividend
|
||||
adc ESI,den+hi[EBP] ; - - - ...
|
||||
adc EDI,0 ; - - - ...
|
||||
_until e ; - - until done
|
||||
_endif ; - endif
|
||||
_endif ; endif
|
||||
pop EAX ; get quotient
|
||||
pop EDX ; ...
|
||||
pop EBX ; get high bit
|
||||
add ESP,8 ; remove divisor
|
||||
pop EDI ; restore sign and exponent
|
||||
dec DI ; decrement exponent
|
||||
shr EBX,1 ; if non-zero
|
||||
_if c ; then
|
||||
rcr EDX,1 ; - shift answer right
|
||||
rcr EAX,1 ; - ...
|
||||
inc EDI ; - increment exponent
|
||||
_endif ; endif
|
||||
sub ESI,ESI ; get zero for zero fill
|
||||
mov CL,11 ; shift result over
|
||||
shrd EAX,EDX,CL ; ...
|
||||
rcr ESI,1 ; save carry
|
||||
shrd EDX,ESI,CL ; ...
|
||||
|
||||
or EDX,0FFF00000h ; turn top bits all on
|
||||
_shl ESI,1 ; get guard bit
|
||||
adc EAX,0 ; round up
|
||||
adc EDX,0 ; ...
|
||||
adc EDI,0 ; increment exponent if required
|
||||
or DI,DI ; if exponent <= 0
|
||||
_if le ; then (denormal result)
|
||||
_if e ; - if exponent = 0
|
||||
mov CL,1 ; - - set shift count to 1
|
||||
_else ; - else
|
||||
neg DI ; - - negate to get shift count
|
||||
mov CX,DI ; - - ...
|
||||
_endif ; - endif
|
||||
and EDX,001FFFFFh ; - isolate fraction
|
||||
sub EBX,EBX ; - for zero fill
|
||||
shrd EAX,EDX,CL ; - align the fraction
|
||||
shrd EDX,EBX,CL ; - ...
|
||||
sub DI,DI ; - set exponent to 0
|
||||
_endif ; endif
|
||||
|
||||
and EDX,000FFFFFh ; isolate fraction
|
||||
mov ESI,EDI ; get copy of sign
|
||||
ror EDI,11 ; get exponent
|
||||
_shl ESI,1 ; get sign
|
||||
rcr EDI,1 ; put it in
|
||||
and EDI,0FFF00000h ; isolate sign and exponent
|
||||
or EDX,EDI ; place it in result
|
||||
|
||||
pop ESI ; restore registers
|
||||
pop EDI ; ...
|
||||
pop EBP ; ...
|
||||
ret ; return
|
||||
endproc __FDD
|
||||
|
||||
endmod
|
||||
end
|
85
programs/develop/open watcom/trunk/clib/cgsupp/fdc386.asm
Normal file
85
programs/develop/open watcom/trunk/clib/cgsupp/fdc386.asm
Normal file
@ -0,0 +1,85 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
|
||||
;<>
|
||||
;<> __FDC - floating double comparison
|
||||
;<> input: EDX:EAX - operand 1
|
||||
;<> ECX:EBX - operand 2
|
||||
;<> if op1 > op2, 1 is returned in EAX
|
||||
;<> if op1 < op2, -1 is returned in EAX
|
||||
;<> if op1 = op2, 0 is returned in EAX
|
||||
;<>
|
||||
;<>
|
||||
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fdc386
|
||||
|
||||
xdefp __FDC
|
||||
|
||||
defpe __FDC
|
||||
push EBP ; save BP
|
||||
test EDX,07ff00000h ; check for zero
|
||||
_if e ; if it is then
|
||||
sub EDX,EDX ; - make whole damn thing a zero
|
||||
_endif ; endif
|
||||
test ECX,07ff00000h ; check op2 for zero
|
||||
_if e ; if it is then
|
||||
sub ECX,ECX ; - make whole damn thing a zero
|
||||
_endif ; endif
|
||||
mov EBP,ECX ; save op2 exponent
|
||||
xor EBP,EDX ; see about signs of the operands
|
||||
mov EBP,0 ; clear result
|
||||
js short cmpdone ; quif arg1 & arg2 have diff signs
|
||||
_guess ; guess
|
||||
cmp EDX,ECX ; - compare high words of arg1, arg2
|
||||
_quif ne ; - quif not equal
|
||||
cmp EAX,EBX ; - compare 2nd words of arg1, arg2
|
||||
_endguess ; endguess
|
||||
_if ne ; if arg1 <> arg2
|
||||
rcr ECX,1 ; - save carry in CX
|
||||
xor EDX,ECX ; - sign of BX is sign of result
|
||||
|
||||
cmpdone: _shl EDX,1 ; - get sign of result into carry
|
||||
sbb EBP,0 ; - BP gets sign of result
|
||||
_shl EBP,1 ; - double BP
|
||||
inc EBP ; - make BP -1 or 1
|
||||
_endif ; endif
|
||||
mov EAX,EBP ; get result
|
||||
pop EBP ; restore BP
|
||||
ret ; return to caller
|
||||
endproc __FDC
|
||||
|
||||
endmod
|
||||
end
|
84
programs/develop/open watcom/trunk/clib/cgsupp/fdfs386.asm
Normal file
84
programs/develop/open watcom/trunk/clib/cgsupp/fdfs386.asm
Normal file
@ -0,0 +1,84 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;=========================================================================
|
||||
;== Name: FDFS ==
|
||||
;== Operation: Float double to float single conversion ==
|
||||
;== Inputs: EDX:EAX double precision float ==
|
||||
;== Outputs: EAX single precision float ==
|
||||
;== Volatile: EDX destroyed ==
|
||||
;=========================================================================
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fdfs386
|
||||
|
||||
xdefp __FDFS
|
||||
|
||||
defpe __FDFS
|
||||
push EBX ; save EBX
|
||||
test EDX,07ff00000h ; check exponent
|
||||
je short retzero ; if exponent = 0 then just return 0
|
||||
sub EBX,EBX ; set to 0
|
||||
_shl EAX,1 ; shift number over
|
||||
_rcl EDX,1 ; ...
|
||||
rcr EBX,1 ; save sign
|
||||
add EAX,20000000h ; round floating point number
|
||||
adc EDX,0 ; ...
|
||||
je oflow ; overflow if exponent went to 0
|
||||
cmp EDX,(03ffh+80h) shl 21 ; check for maximum exponent
|
||||
jae oflow ; overflow if above or equal
|
||||
cmp EDX,(03ffh-7eh) shl 21 ; check for minimum exponent
|
||||
jb uflow ; underflow if below
|
||||
sub EDX,(03ffh-7fh) shl 21 ; correct bias
|
||||
_shl EAX,1 ; do rest of shift
|
||||
_rcl EDX,1 ; ...
|
||||
_shl EAX,1 ; ...
|
||||
_rcl EDX,1 ; ...
|
||||
or EDX,EBX ; put in sign bit
|
||||
mov EAX,EDX ; get result into EAX
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
oflow: mov EAX,7F800000h ; return maximum possible number
|
||||
or EAX,EBX ; put in sign bit
|
||||
pop EBX ; restore EBX
|
||||
ret ; and return
|
||||
|
||||
uflow:
|
||||
retzero:sub EAX,EAX ; set result to 0
|
||||
pop EBX ; restore EBX
|
||||
ret
|
||||
endproc __FDFS
|
||||
|
||||
endmod
|
||||
end
|
144
programs/develop/open watcom/trunk/clib/cgsupp/fdi4386.asm
Normal file
144
programs/develop/open watcom/trunk/clib/cgsupp/fdi4386.asm
Normal file
@ -0,0 +1,144 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fdi4386
|
||||
|
||||
xdefp __FDI4
|
||||
xdefp __RDI4
|
||||
|
||||
xdefp __FDU4
|
||||
xdefp __RDU4
|
||||
|
||||
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
|
||||
;[]
|
||||
;[] __FDU4 convert double float EDX:EAX into 32-bit integer EAX
|
||||
;[] Input: EDX:EAX - double precision floating point number
|
||||
;[] Output: EAX - 32-bit integer
|
||||
;[]
|
||||
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
|
||||
; convert floating double to 4-byte integer with rounding
|
||||
|
||||
defpe __RDU4
|
||||
mov AL,80h+20h ; indicate we are rounding
|
||||
jmp short DtoI ; do it
|
||||
|
||||
defpe __RDI4
|
||||
mov AL,80h+1Fh ; indicate we are rounding
|
||||
jmp short DtoI ; do it
|
||||
|
||||
defpe __FDI4
|
||||
mov AL,1Fh ; indicate we are truncating
|
||||
jmp short DtoI ; do it
|
||||
|
||||
; convert floating double to 4-byte integer with truncation
|
||||
|
||||
defpe __FDU4
|
||||
mov AL,20h ; indicate we are truncating
|
||||
|
||||
DtoI: _shl EDX,1 ; get sign
|
||||
rcr AH,1 ; AH <-- sign
|
||||
shr AH,1 ; shift sign bit over 1
|
||||
or AH,AL ; get rounding bit
|
||||
shr EDX,1 ; restore exponent to its place
|
||||
|
||||
; high bit of AH is rounding bit
|
||||
; next bit is the sign bit
|
||||
|
||||
;<~> Shift real right four places so that exponent occupies an entire
|
||||
;<~> word and the mantissa occupies the remaining words. We do not need
|
||||
;<~> AX because we only need 32 sig digits
|
||||
|
||||
push ECX ; save ECX
|
||||
mov ECX,EDX ; get high part
|
||||
sar ECX,20 ; get exponent to the bottom
|
||||
and CX,07FFh ; isolate exponent
|
||||
sub CX,03FEh ; remove bias from exponent
|
||||
jl short DIzero ; if |real| < .5 goto DIzero
|
||||
cmp CX,20h ; if exponent > 32
|
||||
jg short DIo_f ; goto DIo_flow
|
||||
and AL,3Fh ; isolate # of significant bits
|
||||
cmp CL,AL ; quit if number too big
|
||||
jg short DIo_f ; goto DIo_flow
|
||||
mov CH,AH ; save rounding/truncation bit
|
||||
and EDX,000FFFFFh ; isolate top 20 bits of fraction
|
||||
and EAX,0FFF00000h ; isolate next 12 bits of fraction
|
||||
or EDX,EAX ; glue them together
|
||||
rol EDX,12 ; and rotate into position
|
||||
|
||||
stc ; set carry and
|
||||
rcr EDX,1 ; restore implied 1/2 bit
|
||||
|
||||
rcr CH,1 ; save rounding bit
|
||||
cmp CL,32 ; if want 32 bits
|
||||
_if e ; then
|
||||
mov EAX,EDX ; - get them
|
||||
_shl CH,1 ; - get rounding bit
|
||||
_else ; else
|
||||
sub EAX,EAX ; - zero result register
|
||||
shld EAX,EDX,CL ; - shift answer into EAX
|
||||
shl EDX,CL ; - shift rounding bit into position
|
||||
_shl CH,1 ; - get rid of rounding bit from CH
|
||||
_shl EDX,1 ; - get proper rounding bit
|
||||
_endif ; endif
|
||||
mov CL,0FFh ; get mask
|
||||
rcr CL,1 ; get rounding bit
|
||||
and CH,CL ; mask it with rounding control bit
|
||||
_shl CH,1 ; get rounding bit
|
||||
adc EAX,0 ; add it to the integer to round it up
|
||||
_shl CH,1 ; get sign
|
||||
_if c ; if negative
|
||||
neg EAX ; - negate integer
|
||||
_endif ; endif
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
|
||||
DIo_f:
|
||||
mov EAX,80000000h ; set answer to largest negative number
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
; jmp I4OverFlow ; report overflow
|
||||
|
||||
DIzero: sub EAX,EAX ; set result to zero
|
||||
pop ECX ; restore ECX
|
||||
ret
|
||||
|
||||
endproc __FDU4
|
||||
endproc __FDI4
|
||||
endproc __RDI4
|
||||
endproc __RDU4
|
||||
|
||||
endmod
|
||||
end
|
151
programs/develop/open watcom/trunk/clib/cgsupp/fdi8386.asm
Normal file
151
programs/develop/open watcom/trunk/clib/cgsupp/fdi8386.asm
Normal file
@ -0,0 +1,151 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
; from double to signed/unsigned int64
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fdi8386
|
||||
|
||||
xref __U8LS
|
||||
xref __U8RS
|
||||
|
||||
; Convert double precision float to unsigned 64-bit integer with truncation
|
||||
; Input: [EDX, EAX] = 64-bit float
|
||||
; Output: [EDX, EAX] = 64-bit integer
|
||||
|
||||
xdefp __FDU8
|
||||
defp __FDU8
|
||||
push ECX ; save ECX
|
||||
mov CX,3ffh+64 ; maximum number 2^64-1
|
||||
call __FDU ; convert float to unsigned __int64
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
endproc __FDU8
|
||||
|
||||
; Convert double precision float to signed 64-bit integer with truncation
|
||||
; Input: [EDX, EAX] = 64-bit float
|
||||
; Output: [EDX, EAX] = 64-bit integer
|
||||
|
||||
xdefp __FDI8
|
||||
defp __FDI8
|
||||
push ECX ; save ECX
|
||||
mov CX,3ffh+63 ; maximum number 2^63-1
|
||||
call __FDI ; convert float to signed __int64
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
endproc __FDI8
|
||||
|
||||
__FDI proc near
|
||||
__FDU: ; what? they both do the same thing
|
||||
or EDX,EDX ; check sign bit
|
||||
jns short __FDAbs ; treat as unsigned if positive
|
||||
call __FDAbs ; otherwise convert number
|
||||
neg EDX ; negate the result
|
||||
neg EAX ;
|
||||
sbb EDX,0 ;
|
||||
ret ; return
|
||||
endproc __FDI
|
||||
|
||||
__FDAbs proc near
|
||||
or EAX,EAX ; check if number 0
|
||||
jne short notzero ;
|
||||
or EDX,EDX ; check if number 0
|
||||
jne short notzero ;
|
||||
ret
|
||||
notzero:
|
||||
push EBX ; save EBX
|
||||
_shl EDX,1 ; shift mantissa over
|
||||
rol EDX,11 ; get exponent to bottom
|
||||
mov BX,DX ; copy and isolate
|
||||
and BX,07ffh ; exponent
|
||||
cmp BX,3ffh ; quit if number < 1.0
|
||||
jb short dbluflow ; ...
|
||||
stc ; set carry for implied bit
|
||||
rcr EDX,1 ; put implied '1' bit in
|
||||
shr EDX,11 ; remove exponent and extra bit
|
||||
cmp BX,CX ; check if exponent exceeds maximum
|
||||
jae short dblmax ; return maximum value if so
|
||||
sub BX,3ffh+52 ; calculate amount to shift (+ve -> left)
|
||||
jae short dblm_left ; jump if left shift/no shift
|
||||
neg BX ; make positive
|
||||
call __U8RS ; shift mantissa right
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
dblm_left:
|
||||
_if ne ; done if exponent exactly 55
|
||||
call __U8LS ; - shift mantissa left
|
||||
_endif ; endif
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
; CX = 3ffh+64 for unsigned
|
||||
; 3ffh+63 for signed
|
||||
dblmax:
|
||||
mov EAX,0FFFFFFFFh ; return maximum value
|
||||
mov EDX,EAX ;
|
||||
sub CX,3fFh+64 ; subtract bias + 64, results in 0 or -1
|
||||
neg CX ; get shift count
|
||||
mov BX,CX ; set shift count
|
||||
call __U8RS ; shift mantissa right 1 bit for signed
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
dbluflow:
|
||||
sub EAX,EAX ; ensure entire number 0
|
||||
sub EDX,EDX ;
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
endproc __FDAbs
|
||||
|
||||
; Convert double precision float to unsigned 64-bit integer with rounding
|
||||
; Input: [EDX, EAX] = 64-bit float
|
||||
|
||||
; xdefp __RDU8
|
||||
; defp __RDU8
|
||||
; not implemented
|
||||
; endproc __RDU8
|
||||
|
||||
; Convert double precision float to signed 64-bit integer with rounding
|
||||
; Input: [EDX, EAX] = 64-bit float
|
||||
|
||||
; xdefp __RDI8
|
||||
; defp __RDI8
|
||||
; not implemented
|
||||
; endproc __RDI8
|
||||
|
||||
endmod
|
||||
end
|
150
programs/develop/open watcom/trunk/clib/cgsupp/fdmath.asm
Normal file
150
programs/develop/open watcom/trunk/clib/cgsupp/fdmath.asm
Normal file
@ -0,0 +1,150 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
; These compiler support routines are called by the Fast code generator
|
||||
; when compiling with the -fpc option.
|
||||
;
|
||||
name fdmath
|
||||
|
||||
extrn __FDA : near
|
||||
extrn __FDS : near
|
||||
extrn __FDM : near
|
||||
extrn __FDD : near
|
||||
extrn __FDC : near
|
||||
|
||||
_TEXT segment use32 dword public 'CODE'
|
||||
assume cs:_TEXT
|
||||
|
||||
public __FADD
|
||||
__FADD proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ebx,12[esp] ; load op2
|
||||
mov ecx,16[esp] ; ...
|
||||
call __FDA ; do the add
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op2
|
||||
__FADD endp
|
||||
|
||||
public __FSUB
|
||||
__FSUB proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ebx,12[esp] ; load op2
|
||||
mov ecx,16[esp] ; ...
|
||||
call __FDS ; do the subtract
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op2
|
||||
__FSUB endp
|
||||
|
||||
public __FSUBR
|
||||
__FSUBR proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ecx,edx ; load op2
|
||||
mov ebx,eax ; ...
|
||||
mov eax,12[esp] ; load op1
|
||||
mov edx,16[esp] ; ...
|
||||
call __FDS ; do the subtract
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op1
|
||||
__FSUBR endp
|
||||
|
||||
public __FMUL
|
||||
__FMUL proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ebx,12[esp] ; load op2
|
||||
mov ecx,16[esp] ; ...
|
||||
call __FDM ; do the multiply
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op2
|
||||
__FMUL endp
|
||||
|
||||
public __FDIV
|
||||
__FDIV proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ebx,12[esp] ; load op2
|
||||
mov ecx,16[esp] ; ...
|
||||
call __FDD ; do the divide
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op2
|
||||
__FDIV endp
|
||||
|
||||
public __FDIVR
|
||||
__FDIVR proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ecx,edx ; load op2
|
||||
mov ebx,eax ; ...
|
||||
mov eax,12[esp] ; load op1
|
||||
mov edx,16[esp] ; ...
|
||||
call __FDD ; do the divide
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op1
|
||||
__FDIVR endp
|
||||
|
||||
public __FCMP
|
||||
__FCMP proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ebx,12[esp] ; load op2
|
||||
mov ecx,16[esp] ; ...
|
||||
call __FDC ; do the compare
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op2
|
||||
__FCMP endp
|
||||
|
||||
public __FCMPR
|
||||
__FCMPR proc near
|
||||
push ecx ; save regs
|
||||
push ebx ; ...
|
||||
mov ecx,edx ; load op2
|
||||
mov ebx,eax ; ...
|
||||
mov eax,12[esp] ; load op1
|
||||
mov edx,16[esp] ; ...
|
||||
call __FDC ; do the compare
|
||||
pop ebx ; restore regs
|
||||
pop ecx ; ...
|
||||
ret 8 ; return and remove op1
|
||||
__FCMPR endp
|
||||
|
||||
_TEXT ends
|
||||
end
|
484
programs/develop/open watcom/trunk/clib/cgsupp/fdmth386.asm
Normal file
484
programs/develop/open watcom/trunk/clib/cgsupp/fdmth386.asm
Normal file
@ -0,0 +1,484 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: REAL*8 math library.
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
; inputs: EDX,EAX - operand 1 (high word, low word resp. ) (op1)
|
||||
; ECX,EBX - operand 2 (op2)
|
||||
;
|
||||
; operations are performed as op1 (*) op2 where (*) is the selected
|
||||
; operation
|
||||
;
|
||||
; output: EDX,EAX - result (high word, low word resp. )
|
||||
;
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
.8087
|
||||
modstart fdmth386
|
||||
|
||||
xref __8087 ; indicate that NDP instructions are present
|
||||
|
||||
datasegment
|
||||
extrn __real87 : byte ; 8087.asm
|
||||
enddata
|
||||
|
||||
xref F8DivZero ; Fstatus
|
||||
xref F8OverFlow ; Fstatus
|
||||
xref F8UnderFlow ; Fstatus
|
||||
|
||||
xdefp __FDA ; add real*8 to real*8
|
||||
xdefp __FDS ; subtract real*8 from real*8
|
||||
xdefp __FDM ; 8-byte real multiply
|
||||
|
||||
|
||||
defpe __FDS
|
||||
xor ECX,80000000h ; flip the sign of op2 and add
|
||||
|
||||
defpe __FDA
|
||||
or EBX,EBX ; if low word of op2 is 0
|
||||
_if e ; then
|
||||
_shl ECX,1 ; - place sign in carry
|
||||
je ret_op1 ; - if op2 is 0 then return operand 1
|
||||
rcr ECX,1 ; - put sign back
|
||||
_endif ; endif
|
||||
or EAX,EAX ; if op1 is 0
|
||||
_if e ; then
|
||||
_shl EDX,1 ; - place sign in carry
|
||||
_if e ; - if op1 really is 0
|
||||
mov EDX,ECX ; - - return operand 2
|
||||
mov EAX,EBX ; - - . . .
|
||||
ret_op1: ret ; - - return
|
||||
_endif ; - endif
|
||||
rcr EDX,1 ; - put sign back
|
||||
_endif ; endif
|
||||
|
||||
cmp byte ptr __real87,0; if 8087 not to be used
|
||||
je short __FDAemu ; then emulate
|
||||
|
||||
__FDA87:
|
||||
push EDX ; push operand 1
|
||||
push EAX ; . . .
|
||||
fld qword ptr [ESP] ; load operand 1
|
||||
push ECX ; push operand 2
|
||||
push EBX ; . . .
|
||||
fadd qword ptr [ESP] ; add operand 2 to operand 1
|
||||
_ret87:
|
||||
fstp qword ptr 8[ESP]; store result
|
||||
add ESP,8 ; clean up stack
|
||||
fwait ; wait
|
||||
pop EAX ; load result into EDX:EAX
|
||||
pop EDX ; . . .
|
||||
cmp EDX,80000000H ; is it a negative zero?
|
||||
_if e ; if it is then
|
||||
sub EDX,EDX ; - make it positive 0.0
|
||||
mov EAX,EDX ; - ...
|
||||
_endif ; endif
|
||||
ret ; return
|
||||
|
||||
__FDAemu:
|
||||
push EBP ; save EBP
|
||||
push EDI ; save EDI
|
||||
push ESI ; save EDI
|
||||
mov EDI,EDX ; get high part of op1
|
||||
mov ESI,ECX ; get high part of op2
|
||||
sar EDI,20 ; shift exponent to bottom, duplicating sign
|
||||
sar ECX,20 ; shift exponent to bottom, duplicating sign
|
||||
and EDI,0800007FFh ; isolate signs and exponent
|
||||
and ECX,0800007FFh ; ...
|
||||
mov EBP,ECX ; assume op1 < op2
|
||||
rol EDI,16 ; rotate signs to bottom
|
||||
rol ECX,16 ; ...
|
||||
add CX,DI ; calc sign of result
|
||||
rol EDI,16 ; rotate signs to top
|
||||
rol ECX,16 ; ...
|
||||
and EDX,000FFFFFh ; isolate fraction
|
||||
and ESI,000FFFFFh ; isolate fraction
|
||||
or DI,DI ; if op1 is not a denormal
|
||||
_if ne ; then
|
||||
or EDX,00100000h ; - turn on implied 1 bit
|
||||
_endif ; endif
|
||||
or CX,CX ; if op2 is not a denormal
|
||||
_if ne ; then
|
||||
or ESI,00100000h ; - turn on implied 1 bit
|
||||
_endif ; endif
|
||||
_shl EAX,1 ; shift left 1 to make room for guard bit
|
||||
_rcl EDX,1 ; ...
|
||||
_shl EBX,1 ; ...
|
||||
_rcl ESI,1 ; ...
|
||||
sub CX,DI ; calculate difference in exponents
|
||||
_if ne ; if different
|
||||
_if b ; - if op1 < op2
|
||||
mov EBP,EDI ; - - get larger exponent for result
|
||||
neg CX ; - - negate the shift count
|
||||
xchg EAX,EBX ; - - flip operands
|
||||
xchg EDX,ESI ; - - . . .
|
||||
_endif ; - endif
|
||||
cmp CX,53+1 ; - if shift count too big
|
||||
_if a ; - then, return operand 1
|
||||
mov EDX,ESI ; - - get value in correct registers
|
||||
mov EAX,EBX ; - - . . .
|
||||
_shl EBP,1 ; - - get sign
|
||||
rcr EDX,1 ; - - rebuild operand 1
|
||||
rcr EAX,1 ; - - ...
|
||||
and EDX,800FFFFFh ; - - ...
|
||||
ror EBP,13 ; - - rotate exponent into position
|
||||
and EBP,7FF00000h ; - - ...
|
||||
or EDX,EBP ; - - put in exponent
|
||||
pop ESI ; - - restore ESI
|
||||
pop EDI ; - - restore EDI
|
||||
pop EBP ; - - restore EBP
|
||||
ret ; - - return
|
||||
_endif ; - endif
|
||||
_endif ; endif
|
||||
or ECX,ECX ; get bit 0 of sign word - value is 0 if
|
||||
; both operands have same sign, 1 if not
|
||||
_if s ; if signs are different
|
||||
neg ESI ; - negate the fraction of op2
|
||||
neg EBX ; - . . .
|
||||
sbb ESI,0 ; - . . .
|
||||
xor EBP,80000000h ; - flip sign
|
||||
_endif ; endif
|
||||
sub EDI,EDI ; get a zero for sticky bits
|
||||
cmp CL,0 ; if shifting required
|
||||
_if ne ; then
|
||||
push EBX ; - save EBX
|
||||
sub EBX,EBX ; - for zero fill
|
||||
cmp CL,32 ; - if shift count >= 32
|
||||
_if ae ; - then
|
||||
or EAX,EAX ; - - check low order word for 1 bits
|
||||
setne BL ; - - BL=1 if EAX non zero
|
||||
mov EDI,EBX ; - - save sticky bits
|
||||
sub EBX,EBX ; - - for zero fill
|
||||
mov EAX,EDX ; - - shift right 32
|
||||
sub EDX,EDX ; - - zero high word
|
||||
;;; sub CL,32 ; - - adjust shift count
|
||||
_endif ; - endif
|
||||
shrd EBX,EAX,CL ; - get the extra sticky bits
|
||||
or EDI,EBX ; - save them
|
||||
sub EBX,EBX ; - for zero fill
|
||||
shrd EAX,EDX,CL ; - align the fractions
|
||||
shrd EDX,EBX,CL ; - ...
|
||||
pop EBX ; - restore EBX
|
||||
_endif ; endif
|
||||
|
||||
add EAX,EBX ; add the fractions
|
||||
adc EDX,ESI ; . . .
|
||||
_if s ; if answer is negative
|
||||
cmp CL,53 ; - if shift count >= 53
|
||||
_if ae ; - then
|
||||
test EDI,7FFFFFFFh ; - - check the sticky bits
|
||||
setne BL ; - - make single sticky bit
|
||||
shr EBX,1 ; - - carry set if sticky=1
|
||||
adc EAX,0 ; - - round up fraction if required
|
||||
adc EDX,0 ; - - . . .
|
||||
_endif ; - endif
|
||||
neg EDX ; - negate the fraction
|
||||
neg EAX ; - . . .
|
||||
sbb EDX,0 ; - . . .
|
||||
xor EBP,80000000h ; - flip the sign
|
||||
_endif ; endif
|
||||
mov EBX,EAX ; get result
|
||||
or EBX,EDX ; if not zero
|
||||
_if ne ; then
|
||||
or BP,BP ; - if exponent is 0
|
||||
je short denormal ; - denormal when exponent hits 0
|
||||
_loop ; - loop (normalize)
|
||||
test EDX,7FE00000h ; - - stop when bit slides into exponent field
|
||||
_quif ne ; - - ...
|
||||
dec BP ; - - decrement exponent
|
||||
je short denormal; - - denormal when exponent hits 0
|
||||
_shl EAX,1 ; - - shift fraction left one bit
|
||||
_rcl EDX,1 ; - - ...
|
||||
_endloop ; - endloop
|
||||
test EDX,00400000h ; - if we got a carry
|
||||
_if ne ; - then
|
||||
shr EDX,1 ; - - shift fraction right 1
|
||||
rcr EAX,1 ; - - ...
|
||||
adc EDI,0 ; - - keep sticky bit
|
||||
inc BP ; - - increment exponent
|
||||
cmp BP,07FFh ; - - quit if overflow
|
||||
je add_oflow ; - - . . .
|
||||
_endif ; - endif
|
||||
; normalize the fraction
|
||||
shr EDX,1 ; - get guard bit
|
||||
rcr EAX,1 ; - ...
|
||||
_if c ; - if guard bit is on
|
||||
or EDI,EDI ; - - check the sticky bits
|
||||
setne BL ; - - make single sticky bit
|
||||
or EBX,EAX ; - - or sticky bit with bottom bit
|
||||
shr EBX,1 ; - - carry set if sticky=1 or bottom=1
|
||||
adc EAX,0 ; - - round up fraction if required
|
||||
adc EDX,0 ; - - . . .
|
||||
test EDX,00200000h ; - - if we got a carry (02-nov-90)
|
||||
_if ne ; - - then
|
||||
shr EDX,1 ; - - - shift fraction right 1
|
||||
rcr EAX,1 ; - - - ...
|
||||
inc BP ; - - - increment exponent
|
||||
cmp BP,07FFh ; - - - quit if overflow
|
||||
je add_oflow ; - - - . . .
|
||||
_endif ; - - endif
|
||||
_endif ; - endif
|
||||
and EDX,000FFFFFh ; - get rid of implied 1 bit
|
||||
mov ECX,EBP ; - get sign
|
||||
shl EBP,21 ; - shift exponent to top
|
||||
_shl ECX,1 ; - get sign
|
||||
rcr EBP,1 ; - put it in
|
||||
or EDX,EBP ; - put exponent and sign into result
|
||||
_endif ; endif
|
||||
pop ESI ; restore ESI
|
||||
pop EDI ; restore EDI
|
||||
pop EBP ; restore EBP
|
||||
ret ; return
|
||||
|
||||
denormal: ; handle denormal
|
||||
_shl EBP,1 ; get sign
|
||||
rcr EDX,1 ; put it in result
|
||||
rcr EAX,1 ; ...
|
||||
pop ESI ; restore ESI
|
||||
pop EDI ; restore EDI
|
||||
pop EBP ; restore EBP
|
||||
ret ; return
|
||||
|
||||
add_oflow: ; handle overflow
|
||||
mov EAX,EBP ; get proper sign for infinity
|
||||
pop ESI ; restore ESI
|
||||
pop EDI ; restore EDI
|
||||
pop EBP ; restore EBP
|
||||
jmp F8OverFlow ; handle overflow
|
||||
endproc __FDA
|
||||
endproc __FDS
|
||||
;=====================================================================
|
||||
;<> multiplies X by Y and places result in C.
|
||||
;<> X2 and X1 represent the high and low words of X. Similarly for Y and C
|
||||
;<> Special care is taken to use only six registers, so the code is a bit
|
||||
;<> obscure
|
||||
|
||||
defpe __FDM
|
||||
_guess ; guess: one of the operands is 0
|
||||
or EAX,EAX ; - see if first arg is zero
|
||||
_quif ne ; - quit if op1 is not 0
|
||||
_shl EDX,1 ; - place sign in carry
|
||||
_if e ; - if operand one is 0
|
||||
ret ; - - return
|
||||
_endif ; - endif
|
||||
rcr EDX,1 ; - restore sign
|
||||
_endguess ; endguess
|
||||
_guess ; guess: op2 is 0
|
||||
or EBX,EBX ; - quit if op2 is not 0
|
||||
_quif ne ; - . . .
|
||||
_shl ECX,1 ; - place sign in carry
|
||||
_if e ; - if operand 2 is 0
|
||||
sub EAX,EAX ; - - set result to 0
|
||||
sub EDX,EDX ; - - . . .
|
||||
ret ; - - return
|
||||
_endif ; - endif
|
||||
rcr ECX,1 ; - restore sign of op2
|
||||
_endguess ; endguess
|
||||
|
||||
cmp byte ptr __real87,0; if 8087 not to be used
|
||||
je short __FDMemu ; then emulate
|
||||
|
||||
__FDM87:
|
||||
push EDX ; push operand 1
|
||||
push EAX ; . . .
|
||||
fld qword ptr [ESP] ; load operand 1
|
||||
push ECX ; push operand 2
|
||||
push EBX ; . . .
|
||||
fmul qword ptr [ESP] ; multiply operand 1 by operand 2
|
||||
jmp _ret87 ; goto common epilogue
|
||||
|
||||
__FDMemu:
|
||||
push EBP ; save EBP
|
||||
push EDI ; save EDI
|
||||
push ESI ; save EDI
|
||||
mov EDI,EDX ; get high part of op1
|
||||
mov ESI,ECX ; get high part of op2
|
||||
sar EDI,20 ; shift exponent to bottom, duplicating sign
|
||||
sar ECX,20 ; shift exponent to bottom, duplicating sign
|
||||
and EDI,0800007FFh ; isolate signs and exponent
|
||||
and ECX,0800007FFh ; ...
|
||||
rol EDI,16 ; rotate signs to bottom
|
||||
rol ECX,16 ; ...
|
||||
add CX,DI ; calc sign of result
|
||||
rol EDI,16 ; rotate signs to top
|
||||
rol ECX,16 ; ...
|
||||
and EDX,000FFFFFh ; isolate fraction
|
||||
and ESI,000FFFFFh ; isolate fraction
|
||||
or DI,DI ; if op1 is a denormal
|
||||
_if e ; then
|
||||
inc DI ; - adjust exponent by 1
|
||||
_loop ; - loop (normalize it) 27-jul-90
|
||||
dec DI ; - - decrement exponent
|
||||
_shl EAX,1 ; - - shift left 1
|
||||
_rcl EDX,1 ; - - ...
|
||||
test EDX,00100000h ; - - check for implied 1 bit
|
||||
_until ne ; - until normalized
|
||||
_endif ; endif
|
||||
or EDX,00100000h ; turn on implied 1 bit
|
||||
or CX,CX ; if op2 is a denormal
|
||||
_if e ; then
|
||||
inc CX ; - adjust exponent by 1
|
||||
_loop ; - loop (normalize it) 27-jul-90
|
||||
dec CX ; - - decrement exponent
|
||||
_shl EBX,1 ; - - shift left 1
|
||||
_rcl ESI,1 ; - - ...
|
||||
test ESI,00100000h ; - - check for implied 1 bit
|
||||
_until ne ; - until normalized
|
||||
_endif ; endif
|
||||
or ESI,00100000h ; turn on implied 1 bit
|
||||
|
||||
_guess ; guess: overflow
|
||||
add CX,DI ; - determine exponent of result
|
||||
sub CX,03ffh ; - remove extra bias
|
||||
_quif s ; - quit if exponent is negative
|
||||
cmp CX,07FFh ; - quit if not overflow
|
||||
_quif b ; - . . .
|
||||
mov EAX,ECX ; - put sign into EAX
|
||||
pop ESI ; - restore ESI
|
||||
pop EDI ; - restore EDI
|
||||
pop EBP ; - restore EBP
|
||||
jmp F8OverFlow ; - handle overflow
|
||||
_endguess ; endguess
|
||||
cmp CX,-53 ; if exponent is too small
|
||||
_if l ; then underflow
|
||||
pop ESI ; - restore ESI
|
||||
pop EDI ; - restore EDI
|
||||
pop EBP ; - restore EBP
|
||||
jmp F8UnderFlow ; - handle underflow
|
||||
_endif ; endif
|
||||
push ECX ; save sign and exponent
|
||||
mov CL,11 ; shift fractions to top of registers
|
||||
shld EDX,EAX,CL ; ...
|
||||
shld EAX,EBP,CL ; ...
|
||||
and EAX,0FFFFF800h ; ...
|
||||
shld ESI,EBX,CL ; ...
|
||||
shld EBX,EBP,CL ; ...
|
||||
and EBX,0FFFFF800h ; ...
|
||||
|
||||
sub EBP,EBP ; zero EBP
|
||||
push ESI ; save high part of op2
|
||||
push EDX ; save high part of op1
|
||||
push EAX ; save low part of op1
|
||||
mul EBX ; low part of op1 * low part of op2
|
||||
xchg EAX,ESI ; ESI becomes start of the sticky bits
|
||||
mov ECX,EDX ; save high part of result
|
||||
pop EDX ; restore low part of op1
|
||||
mul EDX ; low part of op1 * high part of op2
|
||||
mov EDI,EDX ; save high part of product
|
||||
add ECX,EAX ; add partial product
|
||||
adc EDI,EBP ; ...
|
||||
adc EBP,EBP ; ...
|
||||
pop EAX ; restore high part of op1
|
||||
xchg EAX,EBX ; flip with low part of op2
|
||||
mul EBX ; high part of op1 * low part of op2
|
||||
add ECX,EAX ; add partial product
|
||||
adc EDI,EDX ; ...
|
||||
adc EBP,0 ; ...
|
||||
mov EAX,EBX ; get high part of op1
|
||||
pop EDX ; restore high part of op2
|
||||
mul EDX ; high part of op1 * high part of op2
|
||||
add EAX,EDI ; add partial product
|
||||
adc EDX,EBP ; ...
|
||||
sub EBX,EBX ; get zero for zero fill
|
||||
mov CL,10 ; shift result over
|
||||
shrd EBX,EAX,CL ; ... get sticky bits 18-feb-91
|
||||
shrd EAX,EDX,CL ; ...
|
||||
shrd EDX,EBX,CL ; ...
|
||||
pop ECX ; restore sign and exponent
|
||||
|
||||
_loop ; loop
|
||||
test EDX,00200000h ; - test to see if bit in exponent field
|
||||
_quif e ; - quit if not
|
||||
shr EDX,1 ; - shift result right
|
||||
rcr EAX,1 ; - . . .
|
||||
rcr EBX,1 ; - save carry
|
||||
inc CX ; - inc exponent for every shift
|
||||
cmp CX,07FFh ; - quit if overflow
|
||||
je mul_oflow ; - . . .
|
||||
_endloop ; endloop
|
||||
_shl EBX,1 ; get guard bit
|
||||
_if c ; if set
|
||||
_if e ; - if rest of sticky bits are 0
|
||||
or ESI,ESI ; - - check the bottom sticky bits
|
||||
setne BL ; - - ...
|
||||
shr EBX,1 ; - - if all sticky bits are zero
|
||||
_if nc ; - - then
|
||||
mov ESI,EAX ; - - - get bottom bit of result
|
||||
shr ESI,1 ; - - - as rounding bit
|
||||
_endif ; - - endif
|
||||
_endif ; - endif
|
||||
adc EAX,0 ; - round up
|
||||
adc EDX,0 ; - ...
|
||||
test EDX,00200000h ; - test to see if bit in exponent field
|
||||
_if ne ; - if fraction overflowed
|
||||
shr EDX,1 ; - - shift right
|
||||
rcr EAX,1 ; - - ...
|
||||
inc CX ; - - increment exponent
|
||||
cmp CX,07FFh ; - - quit if overflow
|
||||
je mul_oflow ; - - . . .
|
||||
_endif ; - endif
|
||||
_endif ; endif
|
||||
or CX,CX ; if exponent <= 0
|
||||
_if le ; then (denormal result)
|
||||
_if e ; - if exponent = 0
|
||||
mov CL,1 ; - - set shift count to 1
|
||||
_else ; - else
|
||||
neg CX ; - - negate to get shift count
|
||||
dec CX ; - - adjust
|
||||
_endif ; - endif
|
||||
sub EBX,EBX ; - for zero fill
|
||||
shrd EAX,EDX,CL ; - align the fraction
|
||||
shrd EDX,EBX,CL ; - ...
|
||||
sub CX,CX ; - set exponent to 0
|
||||
_endif ; endif
|
||||
and EDX,000FFFFFh ; isolate fraction
|
||||
mov ESI,ECX ; get copy of sign
|
||||
ror ECX,11 ; get exponent
|
||||
_shl ESI,1 ; get sign
|
||||
rcr ECX,1 ; put it in
|
||||
and ECX,0FFF00000h ; isolate sign and exponent
|
||||
or EDX,ECX ; place it in result
|
||||
pop ESI ; restore ESI
|
||||
pop EDI ; restore EDI
|
||||
pop EBP ; restore EBP
|
||||
ret ; return
|
||||
|
||||
mul_oflow: ; overflow
|
||||
mov EAX,ECX ; get sign of infinity
|
||||
pop ESI ; restore ESI
|
||||
pop EDI ; restore EDI
|
||||
pop EBP ; restore EBP
|
||||
jmp F8OverFlow ; handle overflow
|
||||
endproc __FDM
|
||||
|
||||
endmod
|
||||
end
|
59
programs/develop/open watcom/trunk/clib/cgsupp/fdn386.asm
Normal file
59
programs/develop/open watcom/trunk/clib/cgsupp/fdn386.asm
Normal file
@ -0,0 +1,59 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;========================================================================
|
||||
;== Name: FDN ==
|
||||
;== Operation: Floating double negate ==
|
||||
;== Inputs: EDX high word of float ==
|
||||
;== Outputs: EDX new high word of float ==
|
||||
;== Volatile: none ==
|
||||
;========================================================================
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fdn386
|
||||
|
||||
xdefp __FDN
|
||||
|
||||
defpe __FDN
|
||||
test EDX,EDX ; if non zero number then
|
||||
_if e
|
||||
test EAX,EAX
|
||||
_endif
|
||||
_if ne ; ...
|
||||
xor EDX,80000000h ; - flip the sign bit
|
||||
_endif ; endif
|
||||
ret ; and return!!!
|
||||
endproc __FDN
|
||||
|
||||
endmod
|
||||
end
|
180
programs/develop/open watcom/trunk/clib/cgsupp/fprem386.asm
Normal file
180
programs/develop/open watcom/trunk/clib/cgsupp/fprem386.asm
Normal file
@ -0,0 +1,180 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fprem386
|
||||
|
||||
xdefp __fprem_
|
||||
|
||||
;
|
||||
; EDX:EAX ECX:EBX
|
||||
; void fprem( double x, double modulus, int *quot, double *rem )
|
||||
;
|
||||
defpe __fprem_
|
||||
push EBP ; save BP
|
||||
mov EBP,ESP ; get access to parms
|
||||
push EDX ; save registers
|
||||
push ECX ; ...
|
||||
push EBX ; ...
|
||||
push EAX ; ...
|
||||
mov EAX,8[EBP] ; get argument x
|
||||
mov EDX,12[EBP] ; ...
|
||||
mov EBX,16[EBP] ; get modulus
|
||||
mov ECX,20[EBP] ; ...
|
||||
or ECX,ECX ; if modulus is zero
|
||||
_if e ; then
|
||||
sub EAX,EAX ; - set result to 0
|
||||
mov EBX,24[EBP] ; - quot = 0
|
||||
mov [EBX],EAX ; - ...
|
||||
mov EBX,28[EBP] ; - remainder = 0
|
||||
mov [EBX],EAX ; - ...
|
||||
mov 4[EBX],EAX ; - ...
|
||||
pop EAX ; - restore registers
|
||||
pop EBX ; - ...
|
||||
pop ECX ; - ...
|
||||
pop EDX ; - ...
|
||||
pop EBP ; - restore EBP
|
||||
ret ; - return
|
||||
_endif ; endif
|
||||
push ESI ; save ESI
|
||||
push EDI ; save EDI
|
||||
push EDX ; save sign of operand
|
||||
push ECX ; save high part of modulus
|
||||
|
||||
mov ESI,EDX ; get most sig word of op1
|
||||
mov EDI,ECX ; get most sig word of op2
|
||||
and ESI,7FF00000h ; isolate exponent
|
||||
and EDI,7FF00000h ; isolate exponent of modulus
|
||||
and EDX,000FFFFFh ; isolate mantissa of op1
|
||||
and ECX,000FFFFFh ; isolate mantissa of modulus
|
||||
or EDX,00100000h ; set implied 1 bit
|
||||
or ECX,00100000h ; ...
|
||||
sub ESI,EDI ; calculate difference in exponents
|
||||
_if ge ; if operand >= modulus
|
||||
sub EDI,EDI ; - set quotient to 0
|
||||
_loop ; - loop
|
||||
_guess ; - - guess
|
||||
cmp ECX,EDX ; - - - The purpose of this guess is to
|
||||
_quif ne ; - - - determine if the divisor will subtract
|
||||
cmp EBX,EAX ; - - -
|
||||
je try ; - - -
|
||||
_endguess ; - - endguess
|
||||
_if c ; - - if the carry is set (ie the modulus will
|
||||
; - - - definitely subtract from the dividend
|
||||
; - - - without a borrow
|
||||
try:
|
||||
sub EAX,EBX ; - - - subtract divisor from dividend
|
||||
sbb EDX,ECX ; - - - . . .
|
||||
stc ; - - - set carry to indicate that modulus was
|
||||
; - - - successfully subtracted from dividend
|
||||
_endif ; - - endif
|
||||
didnt_go: _rcl EDI,1 ; - - rotate 1 (if carry set) into quotient word
|
||||
sub ESI,00100000h ; - - adjust difference in exponents
|
||||
jl _done ; - - quit if done
|
||||
_shl EAX,1 ; - - shift dividend left
|
||||
_rcl EDX,1 ; - - . . .
|
||||
cmp EDX,00200000h
|
||||
jae try
|
||||
|
||||
; If bit 5 of dividend is set here, we didnt subtract the modulus from the
|
||||
; dividend (recall that the divisor has a 1 in the msb -- if we subtracted
|
||||
; it from the dividend without a borrow, the dividend would not have a one
|
||||
; in its msb to be shifted into bit 5 tested for in the condition above. If
|
||||
; we are rotating a bit into bit 5, the dividend is now big enough that we
|
||||
; can be sure of subtracting out the divisor without a borrow, as we have
|
||||
; shifted it left one digit.
|
||||
|
||||
cmp EDX,00100000h
|
||||
_until b ; - until
|
||||
|
||||
cmc ; - flip the carry bit
|
||||
jmp short didnt_go ; - continue
|
||||
_done: sub ESI,ESI ; - set SI to 0
|
||||
; normalize the remainder in AL:BX:CX:DX
|
||||
_guess ; - guess: number is zero
|
||||
or EAX,EAX ; - - quit if not zero
|
||||
_quif ne ; - - ...
|
||||
or EDX,EDX ; - - ...
|
||||
_quif ne ; - - ...
|
||||
_admit ; - admit: not zero
|
||||
_loop ; - - loop
|
||||
test EDX,00200000h; - - - quit if number is normalized
|
||||
_quif ne ; - - - . . .
|
||||
_rcl EAX,1 ; - - - shift result left
|
||||
_rcl EDX,1
|
||||
sub ESI,00100000h; - - - decrement exponent
|
||||
_endloop ; - - endloop
|
||||
shr EDX,1 ; - - put in correct position
|
||||
rcr EAX,1 ; - - . . .
|
||||
add ESI,00100000h ; - - increment exponent
|
||||
pop ECX ; - - get high part of modulus
|
||||
push ECX ; - - save it again
|
||||
and ECX,7FF00000h ; - - isolate exponent of modulus
|
||||
add ESI,ECX ; - - adjust exponent of result
|
||||
_endguess ; - endguess
|
||||
_else ; else
|
||||
add ESI,EDI ; - restore exponent
|
||||
sub EDI,EDI ; - set quotient to 0
|
||||
_endif ; endif
|
||||
and EDX,000FFFFFh ; keep just the fraction
|
||||
add EDX,ESI ; update high order word
|
||||
pop ECX ; restore high part of modulus
|
||||
pop ESI ; restore sign
|
||||
and ESI,080000000h ; isolate sign bit
|
||||
or EDX,EDX ; test high word of remainder
|
||||
_if ne ; if remainder is non-zero
|
||||
or EDX,ESI ; - make remainder same sign as original opnd
|
||||
_endif ; endif
|
||||
xor ESI,ECX ; calc sign of quotient
|
||||
_if s ; if quotient should be negative
|
||||
neg EDI ; - negate quotient
|
||||
_endif ; endif
|
||||
mov ESI,24[EBP] ; get address of quotient
|
||||
mov [ESI],EDI ; store quotient
|
||||
mov ESI,28[EBP] ; get address of remainder
|
||||
mov [ESI],EAX ; store remainder
|
||||
mov 4[ESI],EDX ; ...
|
||||
pop EDI ; restore EDI
|
||||
pop ESI ; restore ESI
|
||||
pop EAX ; restore registers
|
||||
pop EBX ; ...
|
||||
pop ECX ; ...
|
||||
pop EDX ; ...
|
||||
pop EBP ; restore EBP
|
||||
ret ; return
|
||||
endproc __fprem_
|
||||
|
||||
|
||||
endmod
|
||||
end
|
71
programs/develop/open watcom/trunk/clib/cgsupp/fsc386.asm
Normal file
71
programs/develop/open watcom/trunk/clib/cgsupp/fsc386.asm
Normal file
@ -0,0 +1,71 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
|
||||
;<>
|
||||
;<> __FSC compares EAX with EDX
|
||||
;<> if EAX > EDX, 1 is returned in EAX
|
||||
;<> if EAX = EDX, 0 is returned in EAX
|
||||
;<> if EAX < EDX, -1 is returned in EAX
|
||||
;<>
|
||||
;<> ========= === =======
|
||||
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fsc386
|
||||
|
||||
xdefp __FSC
|
||||
|
||||
defpe __FSC
|
||||
_guess have_cmp ; guess - comparison done
|
||||
xor EAX,EDX ; - check if signs differ
|
||||
_if ns ; - if signs are the same
|
||||
xor EAX,EDX ; - - restore EAX
|
||||
sub EAX,EDX ; - - find difference, EAX=0 if equal
|
||||
_quif e,have_cmp ; - - done if mantissas also equal
|
||||
; - - carry=1 iff |EAX| < |EDX|
|
||||
rcr EAX,1 ; - - EAX sign set iff |EAX| < |EDX|
|
||||
xor EDX,EAX ; - - EDX sign set iff EAX < EDX
|
||||
not EDX ; - - EDX sign set iff EAX > EDX
|
||||
_endif ; - endif
|
||||
sub EAX,EAX ; - clear result
|
||||
_shl EDX,1 ; - carry=1 iff EAX > EDX
|
||||
adc EAX,EAX ; - EAX = 1 iff EAX > EDX, else EAX = 0
|
||||
_shl EAX,1 ; - EAX = 2 iff EAX > EDX, else EAX = 0
|
||||
dec EAX ; - EAX = 1 iff EAX > EDX, else EAX = -1
|
||||
_endguess ; endguess
|
||||
ret ; return with sign in EAX, conditions set
|
||||
endproc __FSC
|
||||
|
||||
endmod
|
||||
end
|
89
programs/develop/open watcom/trunk/clib/cgsupp/fsfd386.asm
Normal file
89
programs/develop/open watcom/trunk/clib/cgsupp/fsfd386.asm
Normal file
@ -0,0 +1,89 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;=========================================================================
|
||||
;== Name: FSFD ==
|
||||
;== Operation: Float single to float double conversion ==
|
||||
;== Inputs: EAX single precision float ==
|
||||
;== Outputs: EDX:EAX double precision float ==
|
||||
;== Volatile: none ==
|
||||
;=========================================================================
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fsfd386
|
||||
|
||||
xdefp __FSFD
|
||||
|
||||
defpe __FSFD
|
||||
_guess ; guess: number is 0.0 or -0.0
|
||||
mov EDX,EAX ; - get float
|
||||
and EAX,7fffffffh ; - remove sign
|
||||
_quif ne ; - quit if number is not +0.0 or -0.0
|
||||
_admit ; guess: number is +-infinity
|
||||
cmp EAX,7f800000h ; - quit if not +-infinity
|
||||
_quif ne ; - ...
|
||||
or EDX,7ff00000h ; - set double precision infinity
|
||||
sub EAX,EAX ; - ...
|
||||
_admit ; admit: not a special number
|
||||
test EAX,7f800000h ; - if exponent is 0 (denormal number)
|
||||
_if e ; - then
|
||||
or EDX,7F800000h ; - - set exponent to 0xFF
|
||||
_loop ; - - loop (normalize the fraction)
|
||||
sub EDX,00800000h ; - - - subtract 1 from exponent adjustment
|
||||
_shl EAX,1 ; - - - shift fraction left
|
||||
test EAX,00800000h ; - - - check to see if fraction is normalized
|
||||
_until ne ; - - until normalized
|
||||
and EDX,0FF800000h ; - - copy fraction back to EDX
|
||||
and EAX,007FFFFFh ; - - ...
|
||||
or EDX,EAX ; - - ...
|
||||
sar EDX,3 ; - shift over 3
|
||||
and EDX,8FFFFFFFh ; - reset exponent extended bits
|
||||
add EDX,28200000h ; - adjust exponent by (3FF - FF -7F + 1) shl 20
|
||||
_else ; - else
|
||||
sar EDX,3 ; - shift over 3
|
||||
and EDX,8FFFFFFFh ; - reset exponent extended bits
|
||||
cmp EAX,7F800000h ; - if number is not number (NaN)
|
||||
_if a ;
|
||||
or EDX,7FF00000h; - adjust exponent to NaN 7FF shl 20
|
||||
_else
|
||||
add EDX,38000000h; - adjust exponent by (3FF-7F) shl 20
|
||||
_endif
|
||||
_endif ; - endif
|
||||
and EAX,7 ; - get bottom 3 bits of fraction
|
||||
ror EAX,3 ; - shift them to the top
|
||||
_endguess ; endguess
|
||||
ret ; return
|
||||
endproc __FSFD
|
||||
|
||||
endmod
|
||||
end
|
171
programs/develop/open watcom/trunk/clib/cgsupp/fsi4386.asm
Normal file
171
programs/develop/open watcom/trunk/clib/cgsupp/fsi4386.asm
Normal file
@ -0,0 +1,171 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;========================================================================
|
||||
;== Name: FSI4, FSU4, FSI2, FSU2, FSI1, FSU1 ==
|
||||
;== Operation: Convert single precision to integer ==
|
||||
;== Inputs: EAX single precision floating point ==
|
||||
;== Outputs: EAX integer value ==
|
||||
;== Volatile: none ==
|
||||
;== ==
|
||||
;== ==
|
||||
;== handle -1.0 -> 0xffffffff ==
|
||||
;========================================================================
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fsi4386
|
||||
|
||||
xdefp __FSI4
|
||||
xdefp __FSU4
|
||||
xdefp __FSI2
|
||||
xdefp __FSU2
|
||||
xdefp __FSI1
|
||||
xdefp __FSU1
|
||||
|
||||
defpe __FSI4
|
||||
push ECX ; save cx
|
||||
mov cl,7fh+31 ; maximum number 2^31-1
|
||||
call __FSI ; convert to integer
|
||||
pop ECX ; restore cx
|
||||
ret ; return (overflow already handled
|
||||
endproc __FSI4
|
||||
|
||||
defpe __FSU4
|
||||
push ECX ; save cx
|
||||
mov cl,7fh+32 ; maximum number 2^32-1
|
||||
call __FSU ; convert to integer
|
||||
pop ECX ; restore cx
|
||||
ret ; return if no overflow
|
||||
endproc __FSU4
|
||||
|
||||
defpe __FSI2
|
||||
push ECX ; save cx
|
||||
mov cl,7fh+15 ; maximum number 2^15-1
|
||||
call __FSI ; convert to integer
|
||||
pop ECX ; restore cx
|
||||
ret ; return (overflow already handled
|
||||
endproc __FSI2
|
||||
|
||||
defpe __FSU2
|
||||
push ECX ; save cx
|
||||
mov cl,7fh+16 ; maximum number 2^16-1
|
||||
call __FSU ; convert to integer
|
||||
pop ECX ; restore cx
|
||||
ret ; return if no overflow
|
||||
endproc __FSU2
|
||||
|
||||
defpe __FSI1
|
||||
push ECX ; save cx
|
||||
mov cl,7fh+7 ; maximum number 2^7-1
|
||||
call __FSI ; convert to integer
|
||||
pop ECX ; restore cx
|
||||
ret ; return (overflow already handled
|
||||
endproc __FSI1
|
||||
|
||||
|
||||
defpe __FSU1
|
||||
push ECX ; save cx
|
||||
mov cl,7fh+8 ; maximum number 2^8-1
|
||||
call __FSU ; convert to integer
|
||||
pop ECX ; restore cx
|
||||
ret ; return if no overflow
|
||||
endproc __FSU1
|
||||
|
||||
__FSI proc near
|
||||
__FSU:
|
||||
or EAX,EAX ; check sign bit
|
||||
jns short __FSAbs ; treat as unsigned if positive
|
||||
call __FSAbs ; otherwise convert number
|
||||
neg EAX ; negate the result
|
||||
ret ; and return
|
||||
endproc __FSI
|
||||
|
||||
; 18-nov-87 AFS (for WATCOM C)
|
||||
;__FSU proc near
|
||||
; jmp
|
||||
; or dx,dx ; check sign bit
|
||||
; jns __FSAbs ; just convert if positive
|
||||
; sub ax,ax ; return 0 if negative
|
||||
; sub dx,dx ; ...
|
||||
; ret
|
||||
; endproc __FSU
|
||||
|
||||
;========================================================================
|
||||
;== Name: FSAbs_ ==
|
||||
;== Inputs: EAX float ==
|
||||
;== CL maximum exponent excess $7f ==
|
||||
;== Outputs: EAX integer, absolute value of float ==
|
||||
;== if exponent >= maximum then 2^max - 1 ==
|
||||
;== returned ==
|
||||
;========================================================================
|
||||
|
||||
__FSAbs proc near
|
||||
or EAX,EAX ; check if number 0
|
||||
je short retzero ; if so, just return it
|
||||
_shl EAX,1 ; shift mantissa over
|
||||
rol EAX,8 ; get exponent to bottom
|
||||
cmp AL,7fh ; quit if number < 1.0 15-apr-91
|
||||
jb short uflow ; ...
|
||||
mov CH,AL ; save exponent
|
||||
stc ; set carry for implied bit
|
||||
rcr EAX,1 ; put implied '1' bit in
|
||||
shr EAX,8 ; remove exponent
|
||||
cmp CH,CL ; check if exponent exceeds maximum
|
||||
jae short retmax ; return maximum value if so
|
||||
sub CH,7fh+23 ; calculate amount to shift (+ve -> left)
|
||||
jae short m_left ; jump if left shift/no shift
|
||||
xchg CH,CL ; get shift count
|
||||
neg CL ; make positive
|
||||
shr EAX,CL ; shift mantissa
|
||||
ret ; return with number
|
||||
|
||||
m_left:
|
||||
_if ne ; done if exponent exactly 23
|
||||
mov CL,CH ; - get shift count
|
||||
shl EAX,CL ; - shift number left
|
||||
_endif ; endif
|
||||
ret ; return
|
||||
|
||||
retmax: mov EAX,0FFFFFFFFh ; return maximum value
|
||||
sub CL,7Fh+32 ; subtract bias + 32
|
||||
neg CL ; get shift count
|
||||
shr EAX,CL ; compute value
|
||||
ret ; return
|
||||
|
||||
uflow:
|
||||
retzero:sub EAX,EAX ; ensure entire number 0
|
||||
ret ; return
|
||||
endproc __FSAbs
|
||||
|
||||
endmod
|
||||
end
|
150
programs/develop/open watcom/trunk/clib/cgsupp/fsi8386.asm
Normal file
150
programs/develop/open watcom/trunk/clib/cgsupp/fsi8386.asm
Normal file
@ -0,0 +1,150 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
; from float to signed/unsigned int64
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fsi8386
|
||||
|
||||
xref __U8LS
|
||||
xref __U8RS
|
||||
|
||||
; Convert single precision float to unsigned 64-bit integer with truncation
|
||||
; Input: [EAX] = 32-bit float
|
||||
; Output: [EDX, EAX] = 64-bit integer
|
||||
|
||||
xdefp __FSU8
|
||||
defp __FSU8
|
||||
push ECX ; save ECX
|
||||
mov CL,7fh+64 ; maximum number 2^64-1
|
||||
call __FSU ; convert float to unsigned __int64
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
endproc __FSU8
|
||||
|
||||
; Convert single precision float to signed 64-bit integer with truncation
|
||||
; Input: [EAX] = 32-bit float
|
||||
; Output: [EDX, EAX] = 64-bit integer
|
||||
|
||||
xdefp __FSI8
|
||||
defp __FSI8
|
||||
push ECX ; save ECX
|
||||
mov CL,7fh+63 ; maximum number 2^63-1
|
||||
call __FSI ; convert float to signed __int64
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
endproc __FSI8
|
||||
|
||||
__FSI proc near
|
||||
__FSU: ; what? they both do the same thing
|
||||
or EAX,EAX ; check sign bit
|
||||
jns short __FSAbs ; treat as unsigned if positive
|
||||
call __FSAbs ; otherwise convert number
|
||||
neg EDX ; negate the result
|
||||
neg EAX ;
|
||||
sbb EDX,0 ;
|
||||
ret ; return
|
||||
endproc __FSI
|
||||
|
||||
__FSAbs proc near
|
||||
or EAX,EAX ; check if number 0
|
||||
je short fltzero ; if so, just return 0
|
||||
_shl EAX,1 ; shift mantissa over
|
||||
rol EAX,8 ; get exponent to bottom
|
||||
cmp AL,7fh ; quit if number < 1.0
|
||||
jb short fltuflow ; ...
|
||||
push EBX ; save EBX
|
||||
mov CH,AL ; save exponent
|
||||
stc ; set carry for implied bit
|
||||
rcr EAX,1 ; put implied '1' bit in
|
||||
shr EAX,8 ; remove exponent and extra bit
|
||||
mov EDX,EAX ; put into 64-bit hi part
|
||||
xor EAX,EAX ; zero 64-bit lo part
|
||||
cmp CH,CL ; check if exponent exceeds maximum
|
||||
jae short fltmax ; return maximum value if so
|
||||
sub CH,7fh+55 ; calculate amount to shift (+ve -> left)
|
||||
jae short fltm_left ; jump if left shift/no shift
|
||||
xchg CH,CL ; get shift count
|
||||
neg CL ; make positive
|
||||
mov BX,CX
|
||||
call __U8RS ; shift mantissa right
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
fltm_left:
|
||||
_if ne ; done if exponent exactly 55
|
||||
mov BL,CH ; - get shift count
|
||||
call __U8LS ; - shift mantissa left
|
||||
_endif ; endif
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
; CL = 7fh+64 for unsigned
|
||||
; 7fh+63 for signed
|
||||
fltmax:
|
||||
mov EAX,0FFFFFFFFh ; return maximum value
|
||||
mov EDX,EAX ;
|
||||
sub CL,7fh+64 ; subtract bias + 64, results in 0 or -1
|
||||
neg CL ; get shift count
|
||||
mov BL,CL ; set shift count
|
||||
call __U8RS ; shift mantissa right 1 bit for signed
|
||||
pop EBX ; restore EBX
|
||||
ret ; return
|
||||
|
||||
fltuflow:
|
||||
sub EAX,EAX ; ensure entire number 0
|
||||
fltzero:
|
||||
sub EDX,EDX ;
|
||||
ret ; return
|
||||
endproc __FSAbs
|
||||
|
||||
; Convert single precision float to unsigned 64-bit integer with rounding
|
||||
; Input: [EAX] = 32-bit float
|
||||
|
||||
; xdefp __RSU8
|
||||
; defp __RSU8
|
||||
; not implemented
|
||||
; endproc __RSU8
|
||||
|
||||
; Convert single precision float to signed 64-bit integer with rounding
|
||||
; Input: [EAX] = 32-bit float
|
||||
|
||||
; xdefp __RSI8
|
||||
; defp __RSI8
|
||||
; not implemented
|
||||
; endproc __RSI8
|
||||
|
||||
endmod
|
||||
end
|
453
programs/develop/open watcom/trunk/clib/cgsupp/fsmth386.asm
Normal file
453
programs/develop/open watcom/trunk/clib/cgsupp/fsmth386.asm
Normal file
@ -0,0 +1,453 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: REAL*4 math library.
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
; inputs: EAX - operand 1 (high word, low word resp. ) (op1)
|
||||
; EDX - operand 2 (op2)
|
||||
;
|
||||
; operations are performed as op1 (*) op2 where (*) is the selected
|
||||
; operation
|
||||
;
|
||||
; output: EAX - result
|
||||
;
|
||||
; F4Add, F4Sub - written 28-apr-84
|
||||
; - modified by A.Kasapi 15-may-84
|
||||
; - to: Calculate sign of result
|
||||
; - Guard bit in addition for extra accuracy
|
||||
; Add documentation
|
||||
; F4Mul - written 16-may-84
|
||||
; - by Athos Kasapi
|
||||
; F4DIV - written may-84 by "
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
.287
|
||||
modstart fsmth386
|
||||
|
||||
xref __8087 ; indicate that NDP instructions are present
|
||||
|
||||
xref __fdiv_m32
|
||||
|
||||
datasegment
|
||||
extrn __real87 : byte ; cstart
|
||||
extrn __chipbug : byte
|
||||
fsadd dd _chkadd
|
||||
fsmul dd _chkmul
|
||||
fsdiv dd _chkdiv
|
||||
enddata
|
||||
|
||||
|
||||
xref F4DivZero ; Fstatus
|
||||
xref F4OverFlow ; Fstatus
|
||||
xref F4UnderFlow ; Fstatus
|
||||
|
||||
xdefp __FSA ; add real*4 to real*4
|
||||
xdefp __FSS ; subtract real*4 from real*4
|
||||
xdefp __FSM ; 4-byte real multiply
|
||||
xdefp __FSD ; 4-byte real divide
|
||||
|
||||
|
||||
defpe __FSS
|
||||
or EDX,EDX ; if op2 is 0
|
||||
je short ret_op1 ; then return operand 1
|
||||
xor EDX,80000000h ; flip the sign of op2 and add
|
||||
|
||||
defpe __FSA
|
||||
or EDX,EDX ; if op2 is 0
|
||||
je short ret_op1 ; then return operand 1
|
||||
or EAX,EAX ; if op1 is 0
|
||||
_if e ; then
|
||||
mov EAX,EDX ; - return operand 2
|
||||
ret_op1: ret ; - return
|
||||
_endif ; endif
|
||||
jmp fsadd
|
||||
|
||||
__FSA87:
|
||||
push EBP ; save EBP
|
||||
mov EBP,ESP ; get access to stack
|
||||
push EAX ; push operand 1
|
||||
fld dword ptr -4[EBP]; load operand 1
|
||||
push EDX ; push operand 2
|
||||
fadd dword ptr -8[EBP]; add operand 2 to operand 1
|
||||
_ret87:
|
||||
fstp dword ptr -4[EBP]; store result
|
||||
add ESP,4 ; clean up stack
|
||||
fwait ; wait
|
||||
pop EAX ; load result into EAX
|
||||
cmp EAX,80000000H ; is result -0.0
|
||||
_if e ; if it is then
|
||||
xor EAX,EAX ; - make it positive
|
||||
_endif ; endif
|
||||
pop EBP ; restore EBP
|
||||
ret ; return
|
||||
|
||||
__FSAemu:
|
||||
push ECX ; save ECX
|
||||
push EBX ; save EBX
|
||||
;<> Scheme for calculating sign of result:
|
||||
;<> The sign word is built and kept in CL
|
||||
;<> Bits 0 and 1 hold the sum of the sign bits
|
||||
;<> shifted out of op_1 and op_2
|
||||
;<> Bit 2 holds the sign of the larger operand. It is assumed to be
|
||||
;<> op_1 until op_2 is found larger
|
||||
|
||||
sub ECX,ECX ; clear ECX
|
||||
_shl EAX,1 ; get sign of op1
|
||||
_rcl CL,1 ;
|
||||
mov CH,CL ;
|
||||
_shl CL,1 ;
|
||||
_shl CL,1 ;
|
||||
add CL,CH ;
|
||||
rol EAX,8 ; get exponent of op1 into AL
|
||||
_shl EDX,1 ; get sign of op2
|
||||
adc CL,0 ; place in CL
|
||||
rol EDX,8 ; get exponent of op2 in DL
|
||||
mov BL,AL ; get exponent of op1
|
||||
mov BH,DL ; get exponent of op2
|
||||
|
||||
mov AL,0 ; zero rest of fraction
|
||||
stc ; put implied 1 bit into top bit of
|
||||
rcr EAX,1 ; ... fraction
|
||||
mov DL,0 ; zero rest of fraction
|
||||
stc ; put implied 1 bit into top bit
|
||||
rcr EDX,1 ; ... of fraction
|
||||
|
||||
mov CH,BL ; assume op1 > op2
|
||||
sub BL,BH ; calculate difference in exponents
|
||||
_if ne ; if different
|
||||
_if b ; - if op1 < op2
|
||||
mov CH,BH ; - - get larger exponent for result
|
||||
neg BL ; - - negate the shift count
|
||||
xchg EAX,EDX ; - - flip operands
|
||||
xor CL,4
|
||||
|
||||
;<> op_2 is larger, so its sign now occupies bit 2 of sign word. This
|
||||
;<> information is only correct if the signs of op-1 and op-2 are different.
|
||||
;<> Since we look past bit 1 for sign only if the signs are different, bit2
|
||||
;<> will supply the correct information when it is needed. We get the sign of
|
||||
;<> op_2 by flipping the sign of op_1, already in bit 2
|
||||
|
||||
_endif ; - endif
|
||||
xchg CL,BL ; - get shift count
|
||||
cmp CL,32 ; - if count >= 32
|
||||
_if ge ; - then
|
||||
sub EDX,EDX ; - - answer is 0
|
||||
_else ; - else
|
||||
shr EDX,CL ; - - align fraction
|
||||
_endif ; - endif
|
||||
xchg CL,BL ; - put back
|
||||
_endif ; endif
|
||||
shr CL,1 ; get bit 0 of sign word - value is 0 if
|
||||
; both operands have same sign, 1 if not
|
||||
_if nc ; if signs are the same
|
||||
add EAX,EDX ; - add the fractions
|
||||
_if c ; - if carry
|
||||
rcr EAX,1 ; - - shift fraction right 1 bit
|
||||
inc CH ; - - increment exponent
|
||||
_if z ; - - if we overflowed
|
||||
ror CL,1 ; - - - set sign of infinity
|
||||
rcr EAX,1 ; - - - . . .
|
||||
jmp short add_oflow;- - - handle overflow
|
||||
_endif ; - - endif
|
||||
_endif ; - endif
|
||||
_else ; else (signs are different)
|
||||
shr CL,1 ; - skip junk bit
|
||||
sub EAX,EDX ; - subtract the fractions
|
||||
_guess ; - guess
|
||||
_quif nc ; - - quit if no borrow
|
||||
inc CL ; - - sign := sign of op_2
|
||||
neg EAX ; - - negate the fraction
|
||||
_admit ; - admit
|
||||
or EAX,EAX ; - - quit if answer is not 0
|
||||
_quif ne ; - - . . .
|
||||
pop EBX ; - - restore EBX
|
||||
pop ECX ; - - restore ECX
|
||||
ret ; - - return (answer is 0)
|
||||
_endguess ; - endguess
|
||||
_endif ; endif
|
||||
|
||||
; normalize the fraction
|
||||
add EAX,00000080h ; round up fraction if required
|
||||
mov AL,0 ; zero bottom 8 bits 10-jul-89
|
||||
_guess underflow ; guess
|
||||
_quif nc ; - quit if round up didn't overflow frac
|
||||
inc CH ; - adjust exponent
|
||||
_admit ; admit
|
||||
_loop ; - loop (shift until high bit appears)
|
||||
_shl EAX,1 ; - - shift fraction left
|
||||
_quif c,underflow ; - - quit if carry has appeared
|
||||
dec CH ; - - decrement exponent
|
||||
_until e ; - until underflow
|
||||
jmp short add_uflow ; - handle underflow
|
||||
_endguess ; endguess
|
||||
mov AL,CH ; get exponent
|
||||
ror EAX,8 ; rotate into position
|
||||
ror CL,1 ; get sign bit
|
||||
rcr EAX,1 ; shift it into result
|
||||
pop EBX ; restore EBX
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
|
||||
add_uflow: ; handle underflow
|
||||
pop EBX ; restore EBX
|
||||
pop ECX ; restore ECX
|
||||
jmp F4UnderFlow ; goto underflow routine
|
||||
|
||||
add_oflow: ; handle overflow
|
||||
pop EBX ; restore EBX
|
||||
pop ECX ; restore ECX
|
||||
jmp F4OverFlow ; handle overflow
|
||||
endproc __FSA
|
||||
endproc __FSS
|
||||
|
||||
;=====================================================================
|
||||
|
||||
defpe __FSM
|
||||
|
||||
;<> multiplies X by Y and places result in C.
|
||||
;<> X2 and X1 represent the high and low words of X. Similarly for Y and C
|
||||
;<> Special care is taken to use only six registers, so the code is a bit
|
||||
;<> obscure
|
||||
|
||||
_guess ; guess: answer not 0
|
||||
or EAX,EAX ; - see if first arg is zero
|
||||
_quif e ; - quit if op1 is 0
|
||||
or EDX,EDX ; - quit if op2 is 0
|
||||
_quif e ; - . . .
|
||||
jmp fsmul ; - perform multiplication
|
||||
_endguess ; endguess
|
||||
sub EAX,EAX ; set answer to 0
|
||||
ret ; return
|
||||
|
||||
__FSM87:
|
||||
push EBP ; save EBP
|
||||
mov EBP,ESP ; get access to stack
|
||||
push EAX ; push operand 1
|
||||
fld dword ptr -4[EBP]; load operand 1
|
||||
push EDX ; push operand 2
|
||||
fmul dword ptr -8[EBP]; mulitply operand 1 by operand 2
|
||||
jmp _ret87 ; goto common epilogue
|
||||
|
||||
__FSMemu:
|
||||
push ECX ; save ECX
|
||||
_shl EAX,1 ; get sign of op1
|
||||
_rcl ECX,1 ; save it
|
||||
_shl EDX,1 ; get sign of op2
|
||||
adc ECX,0 ; calc sign of result
|
||||
ror ECX,1 ; move to the top
|
||||
rol EAX,8 ; move exponent of op1 into AL
|
||||
rol EDX,8 ; move exponent of op2 into DL
|
||||
sub AL,7Fh ; remove bias from exponents
|
||||
sub DL,7Fh ; . . .
|
||||
add DL,AL ; add exponents
|
||||
_if o ; if over or underflow
|
||||
js short mul_oflow ; - report overflow if signed
|
||||
jmp short mul_uflow ; - handle underflow
|
||||
_endif ; endif
|
||||
cmp DL,81h ; check for underflow
|
||||
jle short mul_uflow ; quit if underflow
|
||||
add DL,7fh+1 ; bias exponent
|
||||
mov CL,DL ; save exponent
|
||||
mov AL,0 ; zero rest of fraction
|
||||
mov DL,0 ; ...
|
||||
stc ; turn on implied 1 bit in fraction
|
||||
rcr EAX,1 ; ...
|
||||
stc ; turn on implied 1 bit in fraction
|
||||
rcr EDX,1 ; ...
|
||||
mul EDX ; calc fraction
|
||||
or EDX,EDX ; check top bit
|
||||
_if ns ; if not set
|
||||
_shl EDX,1 ; - move left 1
|
||||
dec CL ; - decrement exponent
|
||||
_endif ; endif
|
||||
sar EDX,8 ; place fraction in correct location
|
||||
adc EDX,0 ; round up
|
||||
adc CL,0 ; increment exponent if necessary
|
||||
jz short mul_oflow ; report overflow if required
|
||||
shl EDX,9 ; get rid of implied 1 bit
|
||||
mov DL,CL ; get exponent
|
||||
ror EDX,8 ; rotate into position except for sign
|
||||
_shl ECX,1 ; get sign
|
||||
rcr EDX,1 ; place sign in result
|
||||
mov EAX,EDX ; place in correct register
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
|
||||
mul_uflow: ; underflow
|
||||
pop ECX ; restore ECX
|
||||
jmp F4UnderFlow ; . . .
|
||||
|
||||
mul_oflow: ; overflow
|
||||
mov EAX,ECX ; get sign
|
||||
pop ECX ; restore ECX
|
||||
jmp F4OverFlow ; report overflow
|
||||
endproc __FSM
|
||||
|
||||
;====================================================================
|
||||
|
||||
defpe __FSD
|
||||
jmp fsdiv
|
||||
|
||||
__FSDbad_div:
|
||||
push EBP ; save EBP
|
||||
mov EBP,ESP ; get access to stack
|
||||
push EAX ; push operand 1
|
||||
fld dword ptr -4[EBP]; load operand 1
|
||||
push EDX ; push operand 2
|
||||
call __fdiv_m32 ; divide operand 1 by operand 2
|
||||
push EDX ; __fdiv_m32 popped operand 2, _ret87 wants it
|
||||
jmp _ret87 ; goto common epilogue
|
||||
|
||||
__FSD87:
|
||||
push EBP ; save EBP
|
||||
mov EBP,ESP ; get access to stack
|
||||
push EAX ; push operand 1
|
||||
fld dword ptr -4[EBP]; load operand 1
|
||||
push EDX ; push operand 2
|
||||
fdiv dword ptr -8[EBP]; divide operand 1 by operand 2
|
||||
jmp _ret87 ; goto common epilogue
|
||||
|
||||
|
||||
__FSDemu:
|
||||
_shl EDX,1 ; shift sign of divisor into carry
|
||||
_if e ; if divisor is zero
|
||||
jmp F4DivZero ; - handle divide by zero
|
||||
_endif ; endif
|
||||
push ECX ; save ECX
|
||||
_rcl ECX,1 ; save sign in ECX
|
||||
_shl EAX,1 ; shift sign of dividend into carry
|
||||
_if e ; if dividend is 0, then
|
||||
pop ECX ; - restore ECX
|
||||
ret ; - return
|
||||
_endif ; endif
|
||||
adc ECX,0 ; now calculate save sign of result in ECX
|
||||
ror ECX,1 ; rotate sign to top
|
||||
rol EAX,8 ; get exponent into AL
|
||||
rol EDX,8 ; get exponent into DL
|
||||
sub AL,7Fh ; calculate exponent of result
|
||||
sub DL,7Fh ; . . .
|
||||
sub AL,DL ; . . .
|
||||
_if o ; if over or underflow
|
||||
jns short div_uflow ; - handle underflow
|
||||
_shl ECX,1 ; - get sign of infinity
|
||||
rcr EAX,1 ; - . . .
|
||||
jmp short div_oflow ; - handle overflow
|
||||
_endif ; endif
|
||||
cmp AL,81h ; check for underflow
|
||||
jle short div_uflow ; . . .
|
||||
add AL,7Fh ; restore bias to exponent
|
||||
mov CH,AL ; save calculated exponent
|
||||
mov AL,0 ; zero bottom of fraction
|
||||
mov DL,0 ; ...
|
||||
stc ; rotate implied '1'bit back into divisor
|
||||
rcr EDX,1 ; . . .
|
||||
stc ; rotate implied '1' bit into dividend
|
||||
rcr EAX,1 ; . . .
|
||||
push ECX ; save sign and exponent
|
||||
mov ECX,EDX ; save divisor
|
||||
mov EDX,EAX ; place dividend into EDX
|
||||
sub EAX,EAX ; set rest to 0
|
||||
shr EDX,1 ; so we don't get a divide overflow trap
|
||||
div ECX ; do the divide
|
||||
pop ECX ; restore sign and exponent
|
||||
or EAX,EAX ; check top bit
|
||||
_if ns ; if not set
|
||||
_shl EAX,1 ; - move left 1
|
||||
dec CH ; - decrement exponent
|
||||
_endif ; endif
|
||||
sar EAX,8 ; place fraction in correct location
|
||||
adc EAX,0 ; round up
|
||||
_guess ; guess have to inc exponent
|
||||
_quif nc ; - quit if no carry
|
||||
inc CH ; - increment exponent
|
||||
_quif nz ; - quit if no overflow
|
||||
mov EAX,ECX ; - get sign of infinity
|
||||
jmp short div_oflow ; - handle overflow
|
||||
_endguess ; endguess
|
||||
shl EAX,9 ; get rid of implied 1 bit
|
||||
mov AL,CH ; get exponent
|
||||
ror EAX,8 ; rotate into position except for sign
|
||||
_shl ECX,1 ; get sign
|
||||
rcr EAX,1 ; place sign in result
|
||||
pop ECX ; restore ECX
|
||||
ret ; return to caller
|
||||
|
||||
div_uflow: ; handle underflow
|
||||
pop ECX ; restore ECX
|
||||
jmp F4UnderFlow ; handle underflow
|
||||
|
||||
|
||||
div_oflow: ; handle overflow
|
||||
pop ECX ; restore ECX
|
||||
jmp F4OverFlow ; handle overflow
|
||||
endproc __FSD
|
||||
|
||||
|
||||
_chkadd: call _chk8087
|
||||
jmp fsadd
|
||||
|
||||
_chkmul: call _chk8087
|
||||
jmp fsmul
|
||||
|
||||
_chkdiv: call _chk8087
|
||||
jmp fsdiv
|
||||
|
||||
|
||||
_chk8087 proc near
|
||||
push eax ; save AX
|
||||
cmp byte ptr __real87,0 ; if real 80x87 NDP present
|
||||
_if ne ; then
|
||||
mov eax,offset __FSA87 ; - get addr of add rtn
|
||||
mov fsadd,eax ; - ...
|
||||
mov eax,offset __FSM87 ; - get addr of mul rtn
|
||||
mov fsmul,eax ; - ...
|
||||
test byte ptr __chipbug, 1 ; - if we've got a bad divider
|
||||
_if ne ; - then
|
||||
mov eax,offset __FSDbad_div ; - - get addr of div rtn
|
||||
_else ; - else
|
||||
mov eax,offset __FSD87 ; - - get addr of div rtn
|
||||
_endif ; - endif
|
||||
mov fsdiv,eax ; - ...
|
||||
_else ; else
|
||||
mov eax,offset __FSAemu ; - get addr of add rtn
|
||||
mov fsadd,eax ; - ...
|
||||
mov eax,offset __FSMemu ; - get addr of mul rtn
|
||||
mov fsmul,eax ; - ...
|
||||
mov eax,offset __FSDemu ; - get addr of div rtn
|
||||
mov fsdiv,eax ; - ...
|
||||
_endif ; endif
|
||||
pop eax ; restore AX
|
||||
ret ; return
|
||||
endproc _chk8087
|
||||
|
||||
endmod
|
||||
end
|
56
programs/develop/open watcom/trunk/clib/cgsupp/fsn386.asm
Normal file
56
programs/develop/open watcom/trunk/clib/cgsupp/fsn386.asm
Normal file
@ -0,0 +1,56 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;========================================================================
|
||||
;== Name: FSN ==
|
||||
;== Operation: Floating single negate ==
|
||||
;== Inputs: EAX flaot value ==
|
||||
;== Outputs: EAX new float value ==
|
||||
;== Volatile: none ==
|
||||
;========================================================================
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart fsn386
|
||||
|
||||
xdefp __FSN
|
||||
|
||||
defpe __FSN
|
||||
or EAX,EAX ; if number not zero
|
||||
_if ne ; then
|
||||
xor EAX,80000000h ; - flip the sign bit
|
||||
_endif ; endif
|
||||
ret ; and return!!!
|
||||
endproc __FSN
|
||||
|
||||
endmod
|
||||
end
|
136
programs/develop/open watcom/trunk/clib/cgsupp/fstat386.asm
Normal file
136
programs/develop/open watcom/trunk/clib/cgsupp/fstat386.asm
Normal file
@ -0,0 +1,136 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
; of AX:DX
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
include fstatus.inc
|
||||
|
||||
modstart fstat386
|
||||
|
||||
xref "C",__set_ERANGE
|
||||
xref __FPE_exception_
|
||||
|
||||
datasegment
|
||||
enddata
|
||||
assume ss:nothing
|
||||
|
||||
|
||||
FPS_OK = 0
|
||||
FPS_UNDERFLOW = 1
|
||||
FPS_OVERFLOW = 2
|
||||
FPS_DIVIDE_BY_0 = 3
|
||||
FPS_BAD_ARG = 4
|
||||
|
||||
jmps macro dsym
|
||||
jmp short dsym
|
||||
endm
|
||||
|
||||
|
||||
xdefp F8UnderFlow
|
||||
xdefp F4UnderFlow
|
||||
xdefp F8InvalidOp
|
||||
xdefp F8DivZero
|
||||
xdefp F4DivZero
|
||||
xdefp F8OverFlow
|
||||
xdefp F4OverFlow
|
||||
xdefp F8RetInf_
|
||||
xdefp _F8RetInf_
|
||||
|
||||
defpe F8UnderFlow
|
||||
sub EDX,EDX ; . . .
|
||||
|
||||
defpe F4UnderFlow
|
||||
;; mov EAX,FPE_UNDERFLOW; indicate underflow
|
||||
;; call __FPE_exception_;
|
||||
sub EAX,EAX ; return a zero
|
||||
ret ; return
|
||||
endproc F4UnderFlow
|
||||
endproc F8UnderFlow
|
||||
|
||||
|
||||
defpe F8InvalidOp
|
||||
mov EAX,FPE_ZERODIVIDE; indicate divide by 0
|
||||
call __FPE_exception_;
|
||||
jmps F8RetInf9 ; return infinity
|
||||
endproc F8InvalidOp
|
||||
|
||||
defpe F8DivZero
|
||||
mov EAX,FPE_ZERODIVIDE; indicate divide by 0
|
||||
call __FPE_exception_;
|
||||
jmps F8RetInf9 ; return infinity
|
||||
endproc F8DivZero
|
||||
|
||||
defpe F8OverFlow
|
||||
;
|
||||
; F8RetInf( sign : int ) : reallong
|
||||
;
|
||||
defpe F8RetInf_
|
||||
defpe _F8RetInf_
|
||||
push EAX ; save sign of result
|
||||
call __set_ERANGE ; errno = ERANGE
|
||||
mov EAX,FPE_OVERFLOW ; indicate overflow
|
||||
call __FPE_exception_;
|
||||
pop EAX ; restore sign of result
|
||||
F8RetInf9: and EAX,80000000h ; get sign
|
||||
or EAX,7FF00000h ; set infinity
|
||||
mov EDX,EAX ;
|
||||
sub EAX,EAX ; ...
|
||||
ret ; return
|
||||
endproc _F8RetInf_
|
||||
endproc F8RetInf_
|
||||
endproc F8OverFlow
|
||||
|
||||
|
||||
defpe F4DivZero
|
||||
mov EAX,FPE_ZERODIVIDE; indicate divide by 0
|
||||
call __FPE_exception_;
|
||||
jmps F4RetInf9 ; return infinity
|
||||
endproc F4DivZero
|
||||
|
||||
defpe F4OverFlow
|
||||
defp F4RetInf ; return infinity
|
||||
push EAX ; save sign of result
|
||||
call __set_ERANGE ; errno = ERANGE
|
||||
mov EAX,FPE_OVERFLOW ; indicate overflow
|
||||
call __FPE_exception_;
|
||||
pop EAX ; restore sign of result
|
||||
F4RetInf9: and EAX,80000000h ; get sign
|
||||
or EAX,7F800000h
|
||||
ret
|
||||
endproc F4RetInf
|
||||
endproc F4OverFlow
|
||||
|
||||
|
||||
endmod
|
||||
end
|
90
programs/develop/open watcom/trunk/clib/cgsupp/i4fd386.asm
Normal file
90
programs/develop/open watcom/trunk/clib/cgsupp/i4fd386.asm
Normal file
@ -0,0 +1,90 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart i4fd386
|
||||
|
||||
xdefp __I4FD
|
||||
xdefp __U4FD
|
||||
|
||||
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
|
||||
;[]
|
||||
;[] __I4FD convert signed 32-bit integer in EAX into double float
|
||||
;[] __U4FD convert unsigned 32-bit integer in EAX into double float
|
||||
;[] Input: EAX - 32-bit integer
|
||||
;[] Output: EDX:EAX - double precision representation of integer
|
||||
;[]
|
||||
;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
|
||||
|
||||
defpe __I4FD
|
||||
or EAX,EAX ; if number is negative
|
||||
_if s ; then
|
||||
neg EAX ; - negate number
|
||||
mov EDX,00000BFFh ; - set exponent
|
||||
_else ; else
|
||||
|
||||
; convert unsigned 32-bit integer to double
|
||||
|
||||
defpe __U4FD
|
||||
mov EDX,000003FFh ; - set exponent
|
||||
_endif ; endif
|
||||
or EAX,EAX ; if number is not zero
|
||||
_if ne ; then
|
||||
push ECX ; - save ECX
|
||||
bsr ECX,EAX ; - find most significant non-zero bit
|
||||
mov CH,CL ; - save shift count
|
||||
mov CL,31 ; - calculate # of bits to shift by
|
||||
sub CL,CH ; - ...
|
||||
shl EAX,CL ; - shift bits into position
|
||||
_shl EAX,1 ; - one more to get rid of implied 1 bit
|
||||
mov CL,CH ; - get shift count
|
||||
movzx ECX,CH ; - get shift count
|
||||
add ECX,EDX ; - calculate exponent
|
||||
mov EDX,EAX ; - get the bits
|
||||
and EDX,0FFFFF000h ; - keep 20 bits
|
||||
or EDX,ECX ; - get exponent in there
|
||||
ror EDX,12 ; - rotate into position
|
||||
shl EAX,20 ; - get last 12 bits into place
|
||||
pop ECX ; - restore ECX
|
||||
ret ; - return
|
||||
_endif ; endif
|
||||
sub EDX,EDX ; zero EDX
|
||||
ret ; return
|
||||
|
||||
endproc __U4FD
|
||||
endproc __I4FD
|
||||
|
||||
endmod
|
||||
end
|
82
programs/develop/open watcom/trunk/clib/cgsupp/i4fs386.asm
Normal file
82
programs/develop/open watcom/trunk/clib/cgsupp/i4fs386.asm
Normal file
@ -0,0 +1,82 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;========================================================================
|
||||
;== Name: I4FS, U4FS ==
|
||||
;== Operation: Convert Integer types to single precision ==
|
||||
;== Inputs: EAX, unsigned or signed integer ==
|
||||
;== Outputs: EAX single precision floating point ==
|
||||
;== Volatile: none ==
|
||||
;== ==
|
||||
;========================================================================
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart i4fs386
|
||||
|
||||
xdefp __I4FS
|
||||
xdefp __U4FS
|
||||
|
||||
|
||||
defpe __U4FS
|
||||
or EAX,EAX ; if number is not zero
|
||||
_if ne ; then
|
||||
push ECX ; - save ECX
|
||||
bsr ECX,EAX ; - find most significant non-zero bit
|
||||
mov CH,CL ; - save shift count
|
||||
neg CL ; - calculate # of bits to rotate by
|
||||
add CL,23 ; - ...
|
||||
and CL,1fh ; - just keep last 5 bits
|
||||
rol EAX,CL ; - shift bits into position
|
||||
and EAX,007FFFFFh ; - mask out sign and exponent bits
|
||||
mov CL,CH ; - get shift count
|
||||
add CL,7Fh ; - calculate exponent
|
||||
and ECX,0FFh ; - isolate exponent
|
||||
shl ECX,23 ; - shift exponent into position
|
||||
or EAX,ECX ; - place into result
|
||||
pop ECX ; - restore ECX
|
||||
_endif ; endif
|
||||
ret ; return
|
||||
|
||||
endproc __U4FS
|
||||
|
||||
defpe __I4FS
|
||||
or EAX,EAX ; check sign
|
||||
jns __U4FS ; if positive, just convert
|
||||
neg EAX ; take absolute value of number
|
||||
call __U4FS ; convert to FS
|
||||
or EAX,80000000h ; set sign bit on
|
||||
ret ; and return
|
||||
endproc __I4FS
|
||||
|
||||
endmod
|
||||
end
|
224
programs/develop/open watcom/trunk/clib/cgsupp/i8d.asm
Normal file
224
programs/develop/open watcom/trunk/clib/cgsupp/i8d.asm
Normal file
@ -0,0 +1,224 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;========================================================================
|
||||
;== Name: I8D ==
|
||||
;== Operation: Signed 8 byte divide ==
|
||||
;== Inputs: EDX;EAX Dividend ==
|
||||
;== ECX;EBX Divisor ==
|
||||
;== Outputs: EDX;EAX Quotient ==
|
||||
;== ECX;EBX Remainder (same sign as dividend) ==
|
||||
;== Volatile: none ==
|
||||
;== same sign as dividend for ==
|
||||
;== consistency with 8086 idiv ==
|
||||
;== and so (a/b)*b + a%b == a ==
|
||||
;== to get a 64-bit version for 386==
|
||||
;========================================================================
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart i8d
|
||||
|
||||
xdefp __I8D
|
||||
|
||||
defpe __I8D
|
||||
or edx,edx ; check sign of dividend
|
||||
js divneg ; handle case where dividend < 0
|
||||
or ecx,ecx ; check sign of divisor
|
||||
js notU8D ; easy case if it is also positive
|
||||
|
||||
; dividend >= 0, divisor >= 0
|
||||
docall __U8D ; - ...
|
||||
ret ; - ...
|
||||
|
||||
; dividend >= 0, divisor < 0
|
||||
notU8D: neg ecx ; take positive value of divisor
|
||||
neg ebx ; ...
|
||||
sbb ecx,0 ; ...
|
||||
docall __U8D ; do unsigned division
|
||||
neg edx ; negate quotient
|
||||
neg eax ; ...
|
||||
sbb edx,0 ; ...
|
||||
ret ; and return
|
||||
|
||||
divneg: ; dividend is negative
|
||||
neg edx ; take absolute value of dividend
|
||||
neg eax ; ...
|
||||
sbb edx,0 ; ...
|
||||
or ecx,ecx ; check sign of divisor
|
||||
jns negres ; negative result if divisor > 0
|
||||
|
||||
; dividend < 0, divisor < 0
|
||||
neg ecx ; negate divisor too
|
||||
neg ebx ; ...
|
||||
sbb ecx,0 ; ...
|
||||
docall __U8D ; and do unsigned division
|
||||
neg ecx ; negate remainder
|
||||
neg ebx ; ...
|
||||
sbb ecx,0 ; ...
|
||||
ret ; and return
|
||||
|
||||
; dividend < 0, divisor >= 0
|
||||
negres: docall __U8D ; do unsigned division
|
||||
neg ecx ; negate remainder
|
||||
neg ebx ; ...
|
||||
sbb ecx,0 ; ...
|
||||
neg edx ; negate quotient
|
||||
neg eax ; ...
|
||||
sbb edx,0 ; ...
|
||||
ret ; and return
|
||||
|
||||
endproc __I8D
|
||||
|
||||
;========================================================================
|
||||
;== Name: U8D ==
|
||||
;== Operation: Unsigned 8 byte divide ==
|
||||
;== Inputs: EDX;EAX Dividend ==
|
||||
;== ECX;EBX Divisor ==
|
||||
;== Outputs: EDX;EAX Quotient ==
|
||||
;== ECX;EBX Remainder ==
|
||||
;== Volatile: none ==
|
||||
;========================================================================
|
||||
|
||||
xdefp __U8D
|
||||
|
||||
defpe __U8D
|
||||
or ecx,ecx ; check for easy case
|
||||
jne noteasy ; easy if divisor is 16 bit
|
||||
dec ebx ; decrement divisor
|
||||
_if ne ; if not dividing by 1
|
||||
inc ebx ; - put divisor back
|
||||
cmp ebx,edx ; - if quotient will be >= 64K
|
||||
_if be ; - then
|
||||
;
|
||||
; 12-aug-88, added thanks to Eric Christensen from Fox Software
|
||||
; divisor < 64K, dividend >= 64K, quotient will be >= 64K
|
||||
;
|
||||
; *note* this sequence is used in ltoa's #pragmas; any bug fixes
|
||||
; should be reflected in ltoa's code bursts
|
||||
;
|
||||
mov ecx,eax ; - - save low word of dividend
|
||||
mov eax,edx ; - - get high word of dividend
|
||||
sub edx,edx ; - - zero high part
|
||||
div ebx ; - - divide bx into high part of dividend
|
||||
xchg eax,ecx ; - - swap high part of quot,low word of dvdnd
|
||||
_endif ; - endif
|
||||
div ebx ; - calculate low part
|
||||
mov ebx,edx ; - get remainder
|
||||
mov edx,ecx ; - get high part of quotient
|
||||
sub ecx,ecx ; - zero high part of remainder
|
||||
_endif ; endif
|
||||
ret ; return
|
||||
|
||||
|
||||
noteasy: ; have to work to do division
|
||||
;
|
||||
; check for divisor > dividend
|
||||
;
|
||||
_guess ; guess: divisor > dividend
|
||||
cmp ecx,edx ; - quit if divisor <= dividend
|
||||
_quif b ; - . . .
|
||||
_if e ; - if high parts are the same
|
||||
cmp ebx,eax ; - - compare the lower order words
|
||||
_if be ; - - if divisor <= dividend
|
||||
sub eax,ebx ; - - - calulate remainder
|
||||
mov ebx,eax ; - - - ...
|
||||
sub ecx,ecx ; - - - ...
|
||||
sub edx,edx ; - - - quotient = 1
|
||||
mov eax,1 ; - - - ...
|
||||
ret ; - - - return
|
||||
_endif ; - - endif
|
||||
_endif ; - endif
|
||||
sub ecx,ecx ; - set divisor = 0 (this will be quotient)
|
||||
sub ebx,ebx ; - ...
|
||||
xchg eax,ebx ; - return remainder = dividend
|
||||
xchg edx,ecx ; - and quotient = 0
|
||||
ret ; - return
|
||||
_endguess ; endguess
|
||||
push ebp ; save work registers
|
||||
push esi ; ...
|
||||
push edi ; ...
|
||||
sub esi,esi ; zero quotient
|
||||
mov edi,esi ; ...
|
||||
mov ebp,esi ; and shift count
|
||||
moveup: ; loop until divisor > dividend
|
||||
_shl ebx,1 ; - divisor *= 2
|
||||
_rcl ecx,1 ; - ...
|
||||
jc backup ; - know its bigger if carry out
|
||||
inc ebp ; - increment shift count
|
||||
cmp ecx,edx ; - check if its bigger yet
|
||||
jb moveup ; - no, keep going
|
||||
ja divlup ; - if below, know we're done
|
||||
cmp ebx,eax ; - check low parts (high parts equal)
|
||||
jbe moveup ; until divisor > dividend
|
||||
divlup: ; division loop
|
||||
clc ; clear carry for rotate below
|
||||
_loop ; loop
|
||||
_loop ; - loop
|
||||
_rcl esi,1 ; - - shift bit into quotient
|
||||
_rcl edi,1 ; - - . . .
|
||||
dec ebp ; - - quif( -- shift < 0 ) NB carry not changed
|
||||
js donediv ; - - ...
|
||||
backup: ; - - entry to remove last shift
|
||||
rcr ecx,1 ; - - divisor /= 2 (NB also used by 'backup')
|
||||
rcr ebx,1 ; - - ...
|
||||
sub eax,ebx ; - - dividend -= divisor
|
||||
sbb edx,ecx ; - - c=1 iff it won't go
|
||||
cmc ; - - c=1 iff it will go
|
||||
_until nc ; - until it won't go
|
||||
_loop ; - loop
|
||||
_shl esi,1 ; - - shift 0 into quotient
|
||||
_rcl edi,1 ; - - . . .
|
||||
dec ebp ; - - going to add, check if done
|
||||
js toomuch ; - - if done, we subtracted to much
|
||||
shr ecx,1 ; - - divisor /= 2
|
||||
rcr ebx,1 ; - - ...
|
||||
add eax,ebx ; - - dividend += divisor
|
||||
adc edx,ecx ; - - c = 1 iff bit of quotient should be 1
|
||||
_until c ; - until divisor will go into dividend
|
||||
_endloop ; endloop
|
||||
toomuch: ; we subtracted too much
|
||||
add eax,ebx ; dividend += divisor
|
||||
adc edx,ecx ; ...
|
||||
donediv: ; now quotient in di;si, remainder in dx;ax
|
||||
mov ebx,eax ; move remainder to cx;bx
|
||||
mov ecx,edx ; ...
|
||||
mov eax,esi ; move quotient to dx;ax
|
||||
mov edx,edi ; ...
|
||||
pop edi ; restore registers
|
||||
pop esi ; ...
|
||||
pop ebp ; ...
|
||||
ret ; and return
|
||||
endproc __U8D
|
||||
|
||||
endmod
|
||||
end
|
101
programs/develop/open watcom/trunk/clib/cgsupp/i8fd386.asm
Normal file
101
programs/develop/open watcom/trunk/clib/cgsupp/i8fd386.asm
Normal file
@ -0,0 +1,101 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart i8fd386
|
||||
|
||||
xref __I8LS
|
||||
xref __I8RS
|
||||
|
||||
; Convert signed 64-bit integer to double precision float
|
||||
; Input: [EDX, EAX] = 64-bit integer
|
||||
; Output: [EDX, EAX] = double
|
||||
|
||||
xdefp __I8FD
|
||||
defp __I8FD
|
||||
or EDX,EDX ; check sign
|
||||
jns __U8FD ; if positive, just convert
|
||||
neg EDX ;
|
||||
neg EAX ; take absolute value of number
|
||||
sbb EDX,0 ;
|
||||
call __U8FD ; convert to FD
|
||||
or EDX,80000000h ; set sign bit on
|
||||
ret ; return
|
||||
endproc __I8FD
|
||||
|
||||
; Convert unsigned 64-bit integer to double precision float
|
||||
; Input: [EDX, EAX] = 64-bit integer
|
||||
; Output: [EDX, EAX] = double
|
||||
|
||||
xdefp __U8FD
|
||||
defp __U8FD
|
||||
or EAX,EAX ; if lo is zero
|
||||
_if e ;
|
||||
or EDX,EDX ; and if hi is zero
|
||||
_if e ;
|
||||
ret ; - return
|
||||
_endif
|
||||
_endif ; endif
|
||||
push ECX ; save ECX
|
||||
push EBX ; save EBX
|
||||
bsr ECX,EDX ; find most significant non-zero bit in hi
|
||||
_if e ; if all zero bits
|
||||
bsr ECX,EAX ; - find most significant non-zero bit in lo
|
||||
_else ; else
|
||||
add CL,32 ; - adjust shift count since hi was not 0
|
||||
_endif ; endif
|
||||
push ECX ; save shift count
|
||||
neg CL ; calculate # of bits to shift by
|
||||
add CL,63-11 ; ...
|
||||
mov EBX,ECX ; set up for call
|
||||
or CL,CL ; if mantissa should move left
|
||||
_if ge ; then
|
||||
call __I8LS ; - shift left
|
||||
_else ; else
|
||||
neg BL ; - make positive
|
||||
call __I8RS ; - shift right
|
||||
_endif ; endif
|
||||
pop ECX ; restore shift count
|
||||
and EDX,000FFFFFh ; mask out sign and exponent bits
|
||||
add CX,1023 ; calculate exponent (excess 1023)
|
||||
; and ECX,0FFFh ; isolate exponent (not required)
|
||||
shl ECX,20 ; shift exponent into position
|
||||
or EDX,ECX ; place into result
|
||||
pop EBX ; restore EBX
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
endproc __U8FD
|
||||
|
||||
endmod
|
||||
end
|
102
programs/develop/open watcom/trunk/clib/cgsupp/i8fs386.asm
Normal file
102
programs/develop/open watcom/trunk/clib/cgsupp/i8fs386.asm
Normal file
@ -0,0 +1,102 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
modstart i8fs386
|
||||
|
||||
xref __I8LS
|
||||
xref __I8RS
|
||||
|
||||
; Convert signed 64-bit integer to single precision float
|
||||
; Input: [EDX, EAX] = 64-bit integer
|
||||
; Output: [EAX] = 32-bit float
|
||||
|
||||
xdefp __I8FS
|
||||
defp __I8FS
|
||||
or EDX,EDX ; check sign
|
||||
jns __U8FS ; if positive, just convert
|
||||
neg EDX ;
|
||||
neg EAX ; take absolute value of number
|
||||
sbb EDX,0 ;
|
||||
call __U8FS ; convert to FS
|
||||
or EAX,80000000h ; set sign bit on
|
||||
ret ; return
|
||||
endproc __I8FS
|
||||
|
||||
; Convert unsigned 64-bit integer to single precision float
|
||||
; Input: [EDX, EAX] = 64-bit integer
|
||||
; Output: [EAX] = 32-bit float
|
||||
|
||||
xdefp __U8FS
|
||||
defp __U8FS
|
||||
or EAX,EAX ; if lo is zero
|
||||
_if e ;
|
||||
or EDX,EDX ; and if hi is zero
|
||||
_if e ;
|
||||
ret ; - return
|
||||
_endif
|
||||
_endif ; endif
|
||||
push ECX ; save ECX
|
||||
push EBX ; save EBX
|
||||
bsr ECX,EDX ; find most significant non-zero bit in hi
|
||||
_if e ; if all zero bits
|
||||
bsr ECX,EAX ; - find most significant non-zero bit in lo
|
||||
_else ; else
|
||||
add CL,32 ; - adjust shift count since hi was not 0
|
||||
_endif ; endif
|
||||
push ECX ; save shift count
|
||||
neg CL ; calculate # of bits to shift by
|
||||
add CL,63-8 ; ...
|
||||
mov EBX,ECX ; set up for call
|
||||
or CL,CL ; if mantissa should move left
|
||||
_if ge ; then
|
||||
call __I8LS ; - shift left
|
||||
_else ; else
|
||||
neg BL ; - make positive
|
||||
call __I8RS ; - shift right
|
||||
_endif ; endif
|
||||
pop ECX ; restore shift count
|
||||
and EDX,007FFFFFh ; mask out sign and exponent bits
|
||||
add CL,127 ; calculate exponent (excess 127)
|
||||
; and ECX,0FFh ; isolate exponent (not required)
|
||||
shl ECX,23 ; shift exponent into position
|
||||
or EDX,ECX ; place into result
|
||||
mov EAX,EDX ; single precision is only 32 bits
|
||||
pop EBX ; restore EBX
|
||||
pop ECX ; restore ECX
|
||||
ret ; return
|
||||
endproc __U8FS
|
||||
|
||||
endmod
|
||||
end
|
79
programs/develop/open watcom/trunk/clib/cgsupp/ldiv386.asm
Normal file
79
programs/develop/open watcom/trunk/clib/cgsupp/ldiv386.asm
Normal file
@ -0,0 +1,79 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: Signed 4-byte division for 386.
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;========================================================================
|
||||
;== Name: LDIV ==
|
||||
;== Operation: Signed 4 byte divide ==
|
||||
;== Inputs: EAX Dividend ==
|
||||
;== EDX/ECX Divisor ==
|
||||
;== SS:ESI pointer to result structure ==
|
||||
;== Volatile: none ==
|
||||
;========================================================================
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
ifdef _PROFILE
|
||||
include p5prof.inc
|
||||
endif
|
||||
modstart ldiv386
|
||||
|
||||
defpe div
|
||||
xdefp "C",div
|
||||
defpe ldiv
|
||||
xdefp "C",ldiv
|
||||
ifdef _PROFILE
|
||||
P5Prolog
|
||||
endif
|
||||
ifdef __STACK__
|
||||
mov EAX,4[ESP] ; get numerator
|
||||
mov ECX,8[ESP] ; get divisor
|
||||
; we don't need to save/restore ECX
|
||||
else
|
||||
push ECX ; save ECX
|
||||
mov ECX,EDX ; get divisor
|
||||
endif
|
||||
cdq ; sign extend dividend
|
||||
idiv ECX ; do the divide
|
||||
mov [ESI],EAX ; store quotient
|
||||
mov 4[ESI],EDX ; store remainder
|
||||
ifndef __STACK__
|
||||
pop ECX ; restore ECX
|
||||
endif
|
||||
ifdef _PROFILE
|
||||
P5Epilog
|
||||
endif
|
||||
ret ; return
|
||||
endproc ldiv
|
||||
endproc div
|
||||
|
||||
endmod
|
||||
end
|
82
programs/develop/open watcom/trunk/clib/cgsupp/lldiv386.asm
Normal file
82
programs/develop/open watcom/trunk/clib/cgsupp/lldiv386.asm
Normal file
@ -0,0 +1,82 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: Signed 64-bit division for 386.
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
;========================================================================
|
||||
;== Name: LLDIV ==
|
||||
;== Operation: Signed 8 byte divide ==
|
||||
;== Inputs: EAX;EDX Dividend ==
|
||||
;== ECX;EBX Divisor ==
|
||||
;== SS:ESI pointer to result structure ==
|
||||
;== Volatile: none ==
|
||||
;========================================================================
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
ifdef _PROFILE
|
||||
include p5prof.inc
|
||||
endif
|
||||
modstart lldiv386
|
||||
|
||||
xref __I8D
|
||||
|
||||
; defpe imaxdiv
|
||||
; xdefp "C",imaxdiv
|
||||
defpe lldiv
|
||||
xdefp "C",lldiv
|
||||
ifdef _PROFILE
|
||||
P5Prolog
|
||||
endif
|
||||
ifdef __STACK__
|
||||
push EBX ; save EBX
|
||||
mov EAX,08[ESP] ; get numerator
|
||||
mov EDX,12[ESP]
|
||||
mov EBX,16[ESP] ; get denominator
|
||||
mov ECX,20[ESP]
|
||||
endif
|
||||
docall __I8D ; call long division routine
|
||||
|
||||
mov [ESI],EAX ; store quotient
|
||||
mov 4[ESI],EDX
|
||||
mov 8[ESI],EBX ; store remainder
|
||||
mov 12[ESI],ECX
|
||||
ifdef __STACK__
|
||||
pop EBX ; restore EBX
|
||||
endif
|
||||
ifdef _PROFILE
|
||||
P5Epilog
|
||||
endif
|
||||
ret ; return
|
||||
endproc lldiv
|
||||
; endproc imaxdiv
|
||||
|
||||
endmod
|
||||
end
|
45
programs/develop/open watcom/trunk/clib/memory/bcmp.c
Normal file
45
programs/develop/open watcom/trunk/clib/memory/bcmp.c
Normal file
@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
_WCRTLINK int bcmp( const void *s1, const void *s2, size_t n )
|
||||
/************************************************************/
|
||||
{
|
||||
if( memcmp( s1, s2, n ) == 0 ) {
|
||||
return( 0 );
|
||||
} else {
|
||||
return( 1 );
|
||||
}
|
||||
}
|
41
programs/develop/open watcom/trunk/clib/memory/bcopy.c
Normal file
41
programs/develop/open watcom/trunk/clib/memory/bcopy.c
Normal file
@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
_WCRTLINK void bcopy( const void *s1, void *s2, size_t n )
|
||||
/********************************************************/
|
||||
{
|
||||
memmove( s2, s1, n );
|
||||
}
|
41
programs/develop/open watcom/trunk/clib/memory/bzero.c
Normal file
41
programs/develop/open watcom/trunk/clib/memory/bzero.c
Normal file
@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
_WCRTLINK void bzero( void *s, size_t n )
|
||||
/***************************************/
|
||||
{
|
||||
memset( s, 0, n );
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/memory/fmemccpy.c
Normal file
49
programs/develop/open watcom/trunk/clib/memory/fmemccpy.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemccpy( void _WCFAR *d, const void _WCFAR *s, int c, size_t cnt )
|
||||
{
|
||||
char _WCFAR *dst = d;
|
||||
const char _WCFAR *src = s;
|
||||
for(;;) {
|
||||
if( cnt == 0 ) break;
|
||||
*dst = *src;
|
||||
++dst;
|
||||
if( *src == c ) return( dst );
|
||||
++src;
|
||||
--cnt;
|
||||
}
|
||||
return( NULL );
|
||||
}
|
56
programs/develop/open watcom/trunk/clib/memory/fmemchr.c
Normal file
56
programs/develop/open watcom/trunk/clib/memory/fmemchr.c
Normal file
@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fmemchr().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include "xstring.h"
|
||||
|
||||
/* locate the first occurrence of c in the initial n characters of the
|
||||
object pointed to by s.
|
||||
If the character c is not found, NULL is returned.
|
||||
*/
|
||||
|
||||
#undef _fmemchr
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemchr( const void _WCFAR *vs, int c, size_t n )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemchr( vs, c, n ) );
|
||||
#else
|
||||
const char _WCFAR *s = vs;
|
||||
while( n ) {
|
||||
if( *s == c ) return( (void _WCFAR *)s );
|
||||
++s;
|
||||
--n;
|
||||
}
|
||||
return( NULL );
|
||||
#endif
|
||||
}
|
52
programs/develop/open watcom/trunk/clib/memory/fmemcmp.c
Normal file
52
programs/develop/open watcom/trunk/clib/memory/fmemcmp.c
Normal file
@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "xstring.h"
|
||||
#undef _fmemcmp
|
||||
|
||||
_WCRTLINK int _fmemcmp( const void _WCFAR *v1,
|
||||
const void _WCFAR *v2, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemcmp( v1, v2, len ) );
|
||||
#else
|
||||
const unsigned char _WCFAR *s1 = v1;
|
||||
const unsigned char _WCFAR *s2 = v2;
|
||||
for( ; len; --len ) {
|
||||
if( *s1 != *s2 ) return( *s1 - *s2 );
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
#endif
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/memory/fmemcpy.c
Normal file
49
programs/develop/open watcom/trunk/clib/memory/fmemcpy.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "xstring.h"
|
||||
#undef _fmemcpy
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemcpy( void _WCFAR *dst, const void _WCFAR *s, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemcpy( dst, s, len ) );
|
||||
#else
|
||||
const char _WCFAR *src = s;
|
||||
char _WCFAR *p;
|
||||
for( p = dst; len; --len ) {
|
||||
*p++ = *src++;
|
||||
}
|
||||
return( dst );
|
||||
#endif
|
||||
}
|
54
programs/develop/open watcom/trunk/clib/memory/fmemicmp.c
Normal file
54
programs/develop/open watcom/trunk/clib/memory/fmemicmp.c
Normal file
@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
_WCRTLINK int _fmemicmp( const void _WCFAR *v1, const void _WCFAR *v2, size_t len )
|
||||
{
|
||||
unsigned char c1;
|
||||
unsigned char c2;
|
||||
const unsigned char _WCFAR *s1;
|
||||
const unsigned char _WCFAR *s2;
|
||||
|
||||
for( s1 = v1, s2 = v2 ; len; --len ) {
|
||||
c1 = *s1;
|
||||
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
|
||||
c2 = *s2;
|
||||
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
|
||||
if( c1 != c2 ) return( c1 - c2 );
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
}
|
166
programs/develop/open watcom/trunk/clib/memory/fmemmove.c
Normal file
166
programs/develop/open watcom/trunk/clib/memory/fmemmove.c
Normal file
@ -0,0 +1,166 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__386__)
|
||||
|
||||
#if defined(__FLAT__)
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x06 /* push es */\
|
||||
0x8e 0xc2 /* mov es,dx */\
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg esi,eax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0x66 0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
0x07 /* pop es */\
|
||||
parm [dx edi] [si eax] [ecx] \
|
||||
modify exact [edi esi ecx eax];
|
||||
#else
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg esi,eax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0x66 0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es edi] [si eax] [ecx] \
|
||||
modify exact [edi esi ecx eax];
|
||||
#endif
|
||||
|
||||
#elif defined(M_I86)
|
||||
#if defined(__SMALL_DATA__)
|
||||
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movebwd = \
|
||||
0xfd /* std */\
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0x4e /* dec si */\
|
||||
0x4f /* dec di */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0x46 /* inc si */\
|
||||
0x47 /* inc di */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0xfc /* cld */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
#else
|
||||
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movebwd = \
|
||||
0xfd /* std */\
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0x4e /* dec si */\
|
||||
0x4f /* dec di */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0x46 /* inc si */\
|
||||
0x47 /* inc di */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0xfc /* cld */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
#endif
|
||||
#else
|
||||
#error platform not supported
|
||||
#endif
|
||||
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemmove( void _WCFAR *t, const void _WCFAR *f, size_t len )
|
||||
{
|
||||
char _WCFAR *to = t;
|
||||
const char _WCFAR *from = f;
|
||||
if( from == to ) {
|
||||
return( to );
|
||||
}
|
||||
if( from < to && from + len > to ) { /* if buffers are overlapped*/
|
||||
#if defined(__HUGE__) || defined(__386__)
|
||||
to += len;
|
||||
from += len;
|
||||
while( len != 0 ) {
|
||||
to--;
|
||||
from--;
|
||||
*to = *from;
|
||||
len--;
|
||||
}
|
||||
#else
|
||||
movebwd(( to + len ) - 1, ( from + len ) - 1, len );
|
||||
#endif
|
||||
} else {
|
||||
movefwd( to, from, len );
|
||||
}
|
||||
return( to );
|
||||
}
|
||||
|
51
programs/develop/open watcom/trunk/clib/memory/fmemset.c
Normal file
51
programs/develop/open watcom/trunk/clib/memory/fmemset.c
Normal file
@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include "xstring.h"
|
||||
|
||||
#undef _fmemset
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemset( void _WCFAR *dst, int c, size_t len )
|
||||
{
|
||||
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemset( dst, c, len ) );
|
||||
#else
|
||||
char _WCFAR *p;
|
||||
for( p = dst; len; --len ) {
|
||||
*p++ = c;
|
||||
}
|
||||
return( dst );
|
||||
#endif
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/memory/memccpy.c
Normal file
49
programs/develop/open watcom/trunk/clib/memory/memccpy.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
_WCRTLINK void *memccpy( void *d, const void *s, int c, size_t cnt )
|
||||
{
|
||||
char *dst = d;
|
||||
const char *src = s;
|
||||
for(;;) {
|
||||
if( cnt == 0 ) break;
|
||||
*dst = *src;
|
||||
++dst;
|
||||
if( *src == c ) return( dst );
|
||||
++src;
|
||||
--cnt;
|
||||
}
|
||||
return( NULL );
|
||||
}
|
59
programs/develop/open watcom/trunk/clib/memory/memchr.c
Normal file
59
programs/develop/open watcom/trunk/clib/memory/memchr.c
Normal file
@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memchr() and wmemchr().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
/* locate the first occurrence of c in the initial n characters of the
|
||||
object pointed to by s.
|
||||
If the character c is not found, NULL is returned.
|
||||
*/
|
||||
|
||||
_WCRTLINK VOID_WC_TYPE *__F_NAME(memchr,wmemchr)( const VOID_WC_TYPE *s, INT_WC_TYPE c, size_t n )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
|
||||
return( _inline_memchr( s, c, n ) );
|
||||
#else
|
||||
const CHAR_TYPE *cs = s;
|
||||
|
||||
while( n ) {
|
||||
if( *cs == c ) {
|
||||
return( (VOID_WC_TYPE *)cs );
|
||||
}
|
||||
++cs;
|
||||
--n;
|
||||
}
|
||||
return( NULL );
|
||||
#endif
|
||||
}
|
56
programs/develop/open watcom/trunk/clib/memory/memcmp.c
Normal file
56
programs/develop/open watcom/trunk/clib/memory/memcmp.c
Normal file
@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memcmp() and wmemcmp().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(memcmp,wmemcmp)( const VOID_WC_TYPE *in_s1, const VOID_WC_TYPE *in_s2, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
|
||||
return( _inline_memcmp( in_s1, in_s2, len ) );
|
||||
#else
|
||||
const CHAR_TYPE *s1 = in_s1;
|
||||
const CHAR_TYPE *s2 = in_s2;
|
||||
|
||||
for( ; len; --len ) {
|
||||
if( *s1 != *s2 ) {
|
||||
return( *s1 - *s2 );
|
||||
}
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
#endif
|
||||
}
|
75
programs/develop/open watcom/trunk/clib/memory/memcpy_s.c
Normal file
75
programs/develop/open watcom/trunk/clib/memory/memcpy_s.c
Normal file
@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memcpy_s() - bounds-checking memcpy().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
_WCRTLINK errno_t __F_NAME(memcpy_s,wmemcpy_s)( VOID_WC_TYPE * __restrict s1,
|
||||
rsize_t s1max,
|
||||
const VOID_WC_TYPE * __restrict s2,
|
||||
rsize_t n )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
errno_t rc = -1;
|
||||
const char *msg;
|
||||
|
||||
// Verify runtime-constraints
|
||||
// s1 not NULL
|
||||
// s2 not NULL
|
||||
// s1max <= RSIZE_MAX
|
||||
// n <= RSIZE_MAX
|
||||
// n <= s1max
|
||||
// s1 and s2 no overlap
|
||||
if( __check_constraint_nullptr_msg( msg, s1 ) &&
|
||||
__check_constraint_nullptr_msg( msg, s2 ) &&
|
||||
__check_constraint_maxsize_msg( msg, s1max ) &&
|
||||
__check_constraint_maxsize_msg( msg, n ) &&
|
||||
__check_constraint_a_gt_b_msg( msg, n, s1max ) &&
|
||||
__check_constraint_overlap_msg( msg, s1, s1max, s2, n ) ) {
|
||||
|
||||
// now it's safe to use memcpy
|
||||
__F_NAME(memcpy,wmemcpy)( s1, s2, n );
|
||||
rc = 0;
|
||||
} else {
|
||||
// Runtime-constraints violated, zero out destination array
|
||||
if( (s1 != NULL) && __lte_rsizmax( s1max ) ) {
|
||||
__F_NAME(memset,wmemset)( s1, 0, s1max );
|
||||
}
|
||||
// Now call the handler
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
}
|
||||
|
||||
return( rc );
|
||||
}
|
54
programs/develop/open watcom/trunk/clib/memory/memicmp.c
Normal file
54
programs/develop/open watcom/trunk/clib/memory/memicmp.c
Normal file
@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
_WCRTLINK int memicmp( const void *in_s1, const void *in_s2, size_t len )
|
||||
{
|
||||
const unsigned char * s1 = (const unsigned char *)in_s1;
|
||||
const unsigned char * s2 = (const unsigned char *)in_s2;
|
||||
unsigned char c1;
|
||||
unsigned char c2;
|
||||
|
||||
for( ; len; --len ) {
|
||||
c1 = *s1;
|
||||
c2 = *s2;
|
||||
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
|
||||
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
|
||||
if( c1 != c2 ) return( c1 - c2 );
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
}
|
74
programs/develop/open watcom/trunk/clib/memory/memmov_s.c
Normal file
74
programs/develop/open watcom/trunk/clib/memory/memmov_s.c
Normal file
@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memmove_s() - bounds-checking memmove().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
_WCRTLINK errno_t __F_NAME(memmove_s,wmemmove_s)( VOID_WC_TYPE * __restrict s1,
|
||||
rsize_t s1max,
|
||||
const VOID_WC_TYPE * __restrict s2,
|
||||
rsize_t n )
|
||||
/*******************************************************************************/
|
||||
{
|
||||
errno_t rc = -1;
|
||||
const char *msg;
|
||||
|
||||
|
||||
// Verify runtime-constraints
|
||||
// s1 not NULL
|
||||
// s2 not NULL
|
||||
// s1max <= RSIZE_MAX
|
||||
// n <= RSIZE_MAX
|
||||
// n <= s1max
|
||||
if( __check_constraint_nullptr_msg( msg, s1 ) &&
|
||||
__check_constraint_nullptr_msg( msg, s2 ) &&
|
||||
__check_constraint_maxsize_msg( msg, s1max ) &&
|
||||
__check_constraint_maxsize_msg( msg, n ) &&
|
||||
__check_constraint_a_gt_b_msg( msg, n, s1max ) ) {
|
||||
|
||||
/* now it's safe to use memmove */
|
||||
__F_NAME(memmove,wmemmove)( s1, s2, n );
|
||||
rc = 0;
|
||||
} else {
|
||||
// Runtime-constraints violated, zero out destination array
|
||||
if( (s1 != NULL) && __lte_rsizmax( s1max ) ) {
|
||||
__F_NAME(memset,wmemset)( s1, 0, s1max );
|
||||
}
|
||||
// Now call the handler
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
}
|
||||
|
||||
return( rc );
|
||||
}
|
289
programs/develop/open watcom/trunk/clib/memory/memtest.c
Normal file
289
programs/develop/open watcom/trunk/clib/memory/memtest.c
Normal file
@ -0,0 +1,289 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* MEMTEST.C
|
||||
* Non-exhaustive test of the C library memory manipulation functions.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
#include <i86.h>
|
||||
#endif
|
||||
#ifdef __SW_BW
|
||||
#include <wdefwin.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define VERIFY( exp ) if( !(exp) ) { \
|
||||
printf( "%s: ***FAILURE*** at line %d of %s.\n",\
|
||||
ProgramName, __LINE__, \
|
||||
strlwr(__FILE__) ); \
|
||||
NumErrors++; \
|
||||
exit(-1); \
|
||||
}
|
||||
|
||||
void TestCompare( void );
|
||||
void TestCompareF( void );
|
||||
void TestCopy( void );
|
||||
void TestCopyF( void );
|
||||
void TestOverlap( void );
|
||||
void TestOverlapF( void );
|
||||
void TestMisc( void );
|
||||
|
||||
|
||||
char ProgramName[128]; /* executable filename */
|
||||
int NumErrors = 0; /* number of errors */
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Program entry point.
|
||||
****/
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
#ifdef __SW_BW
|
||||
FILE *my_stdout;
|
||||
my_stdout = freopen( "tmp.log", "a", stdout );
|
||||
if( my_stdout == NULL ) {
|
||||
fprintf( stderr, "Unable to redirect stdout\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*** Initialize ***/
|
||||
strcpy( ProgramName, strlwr(argv[0]) ); /* store filename */
|
||||
|
||||
/*** Test various functions ***/
|
||||
TestCompare(); /* comparing stuff */
|
||||
TestCopy(); /* copying stuff */
|
||||
TestOverlap(); /* test overlapping copy */
|
||||
TestMisc(); /* other stuff */
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
TestCompareF();
|
||||
TestCopyF();
|
||||
TestOverlapF();
|
||||
#endif
|
||||
|
||||
/*** Print a pass/fail message and quit ***/
|
||||
if( NumErrors!=0 ) {
|
||||
printf( "%s: SUCCESS.\n", ProgramName );
|
||||
return( EXIT_SUCCESS );
|
||||
}
|
||||
printf( "Tests completed (%s).\n", strlwr( argv[0] ) );
|
||||
#ifdef __SW_BW
|
||||
{
|
||||
fprintf( stderr, "Tests completed (%s).\n", strlwr( argv[0] ) );
|
||||
fclose( my_stdout );
|
||||
_dwShutDown();
|
||||
}
|
||||
#endif
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memcmp(), memicmp(), and memchr().
|
||||
****/
|
||||
|
||||
void TestCompare( void )
|
||||
{
|
||||
char buf[80];
|
||||
char * ptr;
|
||||
int status;
|
||||
|
||||
strcpy( buf, "Foo !" ); /* initialize string */
|
||||
|
||||
status = memcmp( buf, "Foo", 3 ); /* compare */
|
||||
VERIFY( status == 0 );
|
||||
|
||||
status = memcmp( buf, "Foo!", 4 ); /* compare */
|
||||
VERIFY( status != 0 );
|
||||
|
||||
status = memicmp( buf, "FOO", 3 ); /* compare */
|
||||
VERIFY( status == 0 );
|
||||
|
||||
status = memicmp( buf, "fOo!", 4 ); /* compare */
|
||||
VERIFY( status != 0 );
|
||||
|
||||
ptr = memchr( buf, '~', 6 ); /* try to find a tilde */
|
||||
VERIFY( ptr == NULL );
|
||||
|
||||
ptr = memchr( buf, '!', 6 ); /* find the '!' */
|
||||
VERIFY( ptr == buf+4 );
|
||||
}
|
||||
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
void TestCompareF( void )
|
||||
{
|
||||
char buf[80];
|
||||
char __far * ptr;
|
||||
int status;
|
||||
|
||||
strcpy( buf, "Foo !" ); /* initialize string */
|
||||
|
||||
status = _fmemcmp( buf, "Foo", 3 ); /* compare */
|
||||
VERIFY( status == 0 );
|
||||
|
||||
status = _fmemcmp( buf, "Foo!", 4 ); /* compare */
|
||||
VERIFY( status != 0 );
|
||||
|
||||
ptr = _fmemchr( buf, '~', 6 ); /* try to find a tilde */
|
||||
VERIFY( ptr == NULL );
|
||||
|
||||
ptr = _fmemchr( buf, '!', 6 ); /* find the '!' */
|
||||
VERIFY( ptr == buf+4 );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memcpy(), memccpy(), and movedata().
|
||||
****/
|
||||
|
||||
void TestCopy( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
|
||||
strcpy( bufB, "Hello, world!" ); /* initialize bufB */
|
||||
memccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */
|
||||
VERIFY( !memcmp(bufA, "Hello", 5) ); /* ensure copied ok */
|
||||
|
||||
memcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */
|
||||
VERIFY( !strcmp(bufA, bufB) ); /* ensure copied ok */
|
||||
}
|
||||
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
void TestCopyF( void )
|
||||
{
|
||||
char __far bufA[80], bufB[80];
|
||||
char __far testStr[] = "Foo Bar Goober Blah";
|
||||
|
||||
strcpy( bufB, "Hello, world!" ); /* initialize bufB */
|
||||
_fmemccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */
|
||||
VERIFY( !_fmemcmp(bufA, "Hello", 5) ); /* ensure copied ok */
|
||||
|
||||
_fmemcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */
|
||||
VERIFY( !_fstrcmp(bufA, bufB) ); /* ensure copied ok */
|
||||
|
||||
movedata( FP_SEG(bufA), FP_OFF(bufA), /* copy data */
|
||||
FP_SEG(testStr), FP_OFF(testStr),
|
||||
_fstrlen(testStr) );
|
||||
VERIFY( !_fmemcmp(bufA, testStr, _fstrlen(testStr)) );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memmove().
|
||||
****/
|
||||
|
||||
void TestOverlap( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
|
||||
strcpy( bufA, " Hello, world!" ); /* initialize string */
|
||||
|
||||
memmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */
|
||||
VERIFY( !strcmp(bufB, bufA) );
|
||||
|
||||
memmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */
|
||||
VERIFY( !strcmp(bufA, "Hello, world!!") );
|
||||
|
||||
memmove( bufA+1, bufA, strlen(bufA+1) );
|
||||
VERIFY( !strcmp(bufA, "HHello, world!") );
|
||||
}
|
||||
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
void TestOverlapF( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
|
||||
strcpy( bufA, " Hello, world!" ); /* initialize string */
|
||||
|
||||
_fmemmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */
|
||||
VERIFY( !strcmp(bufB, bufA) );
|
||||
|
||||
_fmemmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */
|
||||
VERIFY( !strcmp(bufA, "Hello, world!!") );
|
||||
|
||||
_fmemmove( bufA+1, bufA, strlen(bufA+1) );
|
||||
VERIFY( !strcmp(bufA, "HHello, world!") );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memset(), _fmemset(), and swab().
|
||||
****/
|
||||
|
||||
void TestMisc( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
void * addr;
|
||||
int count;
|
||||
|
||||
addr = memset( bufA, 0x00, 80 ); /* zero out memory */
|
||||
VERIFY( addr == bufA );
|
||||
|
||||
for( count=0; count<80; count++ ) /* ensure all zero bytes */
|
||||
VERIFY( bufA[count] == 0x00 );
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
{
|
||||
void __far * addrFar;
|
||||
addrFar = _fmemset( bufB, 0x00, 80 ); /* zero out memory */
|
||||
VERIFY( addrFar == bufB );
|
||||
|
||||
for( count=0; count<80; count++ ) { /* ensure all zero bytes */
|
||||
VERIFY( bufB[count] == 0x00 );
|
||||
}
|
||||
}
|
||||
#else
|
||||
memset( bufB, 0x00, 80 ); /* zero out memory */
|
||||
#endif
|
||||
|
||||
strcpy( bufA, "eHll,ow rodl" ); /* initialize string */
|
||||
swab( bufA, bufB, strlen(bufA) ); /* swap pairs of characters */
|
||||
VERIFY( !strcmp(bufB, "Hello, world") ); /* ensure swapped ok */
|
||||
}
|
46
programs/develop/open watcom/trunk/clib/memory/movedata.c
Normal file
46
programs/develop/open watcom/trunk/clib/memory/movedata.c
Normal file
@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of movedata().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
/* Inline variant must always be used, no equivalent exists */
|
||||
#ifndef __INLINE_FUNCTIONS__
|
||||
#define __INLINE_FUNCTIONS__
|
||||
#endif
|
||||
#include "xstring.h"
|
||||
|
||||
#undef movedata
|
||||
|
||||
|
||||
_WCRTLINK void movedata( unsigned fromseg, unsigned fromoff,
|
||||
unsigned toseg, unsigned tooff, unsigned len )
|
||||
{
|
||||
_inline_movedata( fromseg, fromoff, toseg, tooff, len );
|
||||
}
|
47
programs/develop/open watcom/trunk/clib/memory/swab.c
Normal file
47
programs/develop/open watcom/trunk/clib/memory/swab.c
Normal file
@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
_WCRTLINK void swab( char *src, char *dst, int n )
|
||||
{
|
||||
char c;
|
||||
|
||||
for( n = n >> 1; n; --n ) {
|
||||
c = src[0]; /* 25-jun-90: just in case src and dst are the same */
|
||||
dst[0] = src[1];
|
||||
dst[1] = c;
|
||||
dst += 2;
|
||||
src += 2;
|
||||
}
|
||||
}
|
83
programs/develop/open watcom/trunk/clib/search/bsearch.c
Normal file
83
programs/develop/open watcom/trunk/clib/search/bsearch.c
Normal file
@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include "extfunc.h"
|
||||
|
||||
/*
|
||||
The old bsearch could SIGSEGV if the compare is done on elements
|
||||
which are not within the given segment. The error occurs if the search
|
||||
key is larger than the 'high' element (or lower than the 'low' member)
|
||||
and 'low','mid' and 'high' are all equal (either from the start or
|
||||
after several iterations).
|
||||
*/
|
||||
|
||||
typedef int bcomp();
|
||||
#if defined(_M_IX86)
|
||||
#pragma aux (__outside_CLIB) bcomp;
|
||||
#endif
|
||||
|
||||
_WCRTLINK void * bsearch( const void * key,
|
||||
const void * base,
|
||||
size_t nmemb,
|
||||
size_t size,
|
||||
int (*cmp)() )
|
||||
{
|
||||
char *low;
|
||||
char *high;
|
||||
char *mid;
|
||||
int cond;
|
||||
bcomp *compar = cmp;
|
||||
|
||||
if( nmemb == 0 ) {
|
||||
return( NULL );
|
||||
}
|
||||
low = (char *) base;
|
||||
high = low + (nmemb-1) * size;
|
||||
// JBS while( low <= high ) {
|
||||
while( low < high ) {
|
||||
mid = low + ( (high-low)/size/2 ) * size;
|
||||
cond = (*compar)( key, mid );
|
||||
if( cond == 0 ) return( mid );
|
||||
if( cond < 0 ) { /* key < mid */
|
||||
// JBS high = mid - size;
|
||||
high = mid;
|
||||
} else { /* key > mid */
|
||||
low = mid + size;
|
||||
}
|
||||
}
|
||||
if (low == high) return( (*compar)(key, low) ? NULL : low );
|
||||
return( NULL );
|
||||
}
|
84
programs/develop/open watcom/trunk/clib/search/bsrch_s.c
Normal file
84
programs/develop/open watcom/trunk/clib/search/bsrch_s.c
Normal file
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of bsearch_s() - bounds-checking bsearch().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include "extfunc.h"
|
||||
|
||||
typedef int bcomp();
|
||||
#ifdef _M_IX86
|
||||
#pragma aux (__outside_CLIB) bcomp;
|
||||
#endif
|
||||
|
||||
_WCRTLINK void * bsearch_s( const void * key, const void * base,
|
||||
rsize_t nmemb, rsize_t size,
|
||||
int (*compar)( const void *k, const void *y, void *context ),
|
||||
void *context )
|
||||
/***********************************************************************/
|
||||
{
|
||||
char *low;
|
||||
char *high;
|
||||
char *mid;
|
||||
int cond;
|
||||
bcomp *comp = compar;
|
||||
|
||||
/* runtime-constraints */
|
||||
// nmemb <= RSIZE_MAX
|
||||
// size <= RSIZE_MAX
|
||||
// if nmemb > 0 then key, base, compar not NULL
|
||||
if( __check_constraint_maxsize( nmemb ) &&
|
||||
__check_constraint_maxsize( size ) &&
|
||||
( (nmemb == 0) || __check_constraint_nullptr( key ) &&
|
||||
__check_constraint_nullptr( base ) &&
|
||||
__check_constraint_nullptr( compar )) ) {
|
||||
|
||||
if( nmemb == 0 ) { /* empty array - nothing to do */
|
||||
return( NULL );
|
||||
}
|
||||
low = (char *) base;
|
||||
high = low + (nmemb - 1) * size;
|
||||
while( low < high ) {
|
||||
mid = low + ( (high - low) / size / 2 ) * size;
|
||||
cond = (*comp)( key, mid, context );
|
||||
if( cond == 0 ) return( mid );
|
||||
if( cond < 0 ) { /* key < mid */
|
||||
high = mid;
|
||||
} else { /* key > mid */
|
||||
low = mid + size;
|
||||
}
|
||||
}
|
||||
if (low == high) return( (*comp)( key, low, context ) ? NULL : low );
|
||||
}
|
||||
return( NULL );
|
||||
}
|
65
programs/develop/open watcom/trunk/clib/search/lfind.c
Normal file
65
programs/develop/open watcom/trunk/clib/search/lfind.c
Normal file
@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "extfunc.h"
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include <stddef.h>
|
||||
#include <search.h>
|
||||
|
||||
typedef int lcomp( const void *, const void * );
|
||||
#if defined(_M_IX86)
|
||||
#pragma aux (__outside_CLIB) lcomp;
|
||||
#endif
|
||||
|
||||
_WCRTLINK void *lfind(
|
||||
const void *key,
|
||||
const void *base,
|
||||
unsigned *num,
|
||||
unsigned width,
|
||||
int (*compare)(
|
||||
const void *,
|
||||
const void *
|
||||
)
|
||||
)
|
||||
{
|
||||
lcomp *cmp = (lcomp *)compare;
|
||||
unsigned n;
|
||||
|
||||
for( n = *num; n; --n )
|
||||
{
|
||||
if( cmp( key, base ) == 0 )
|
||||
return( (void *)base );
|
||||
base = ((const char *)base) + width;
|
||||
}
|
||||
return( NULL );
|
||||
}
|
68
programs/develop/open watcom/trunk/clib/search/lsearch.c
Normal file
68
programs/develop/open watcom/trunk/clib/search/lsearch.c
Normal file
@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "extfunc.h"
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <search.h>
|
||||
|
||||
typedef int lcomp( const void *, const void * );
|
||||
#if defined(_M_IX86)
|
||||
#pragma aux (__outside_CLIB) lcomp;
|
||||
#endif
|
||||
|
||||
_WCRTLINK void *lsearch(
|
||||
const void *key,
|
||||
void *base,
|
||||
unsigned *num,
|
||||
unsigned width,
|
||||
int (*compare)(
|
||||
const void *,
|
||||
const void *
|
||||
)
|
||||
)
|
||||
{
|
||||
lcomp *cmp = (lcomp *)compare;
|
||||
unsigned n;
|
||||
|
||||
for( n = *num; n; --n )
|
||||
{
|
||||
if( cmp( key, base ) == 0 )
|
||||
return( base );
|
||||
base = ((char *)base) + width;
|
||||
}
|
||||
memcpy( base, key, width );
|
||||
++*num;
|
||||
return( base );
|
||||
}
|
83
programs/develop/open watcom/trunk/clib/search/qsort.c
Normal file
83
programs/develop/open watcom/trunk/clib/search/qsort.c
Normal file
@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "extfunc.h"
|
||||
|
||||
typedef int qcomp( const void *, const void * );
|
||||
#if defined(_M_IX86)
|
||||
#pragma aux (__outside_CLIB) qcomp;
|
||||
#endif
|
||||
|
||||
|
||||
/* Function to find the median value */
|
||||
static char *med3( char *a, char *b, char *c, qcomp cmp )
|
||||
{
|
||||
if( cmp( a, b ) > 0 ) {
|
||||
if( cmp( a, c ) > 0 ) {
|
||||
if( cmp( b, c ) > 0 ) {
|
||||
return( b );
|
||||
} else {
|
||||
return( c );
|
||||
}
|
||||
} else {
|
||||
return( a );
|
||||
}
|
||||
} else {
|
||||
if( cmp( a, c ) >= 0 ) {
|
||||
return( a );
|
||||
} else {
|
||||
if( cmp( b, c ) > 0 ) {
|
||||
return( c );
|
||||
} else {
|
||||
return( b );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __AXP__
|
||||
|
||||
#else
|
||||
|
||||
#define FUNCTION_LINKAGE _WCRTLINK
|
||||
#define FUNCTION_NAME qsort
|
||||
#define PTRATTR
|
||||
#define MED3 med3
|
||||
#define BYTESWAP byteswap
|
||||
#include "qsortrtn.c"
|
||||
|
||||
#endif
|
118
programs/develop/open watcom/trunk/clib/search/qsort_s.c
Normal file
118
programs/develop/open watcom/trunk/clib/search/qsort_s.c
Normal file
@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of qsort_s() - bounds-checking qsort().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "extfunc.h"
|
||||
|
||||
typedef int qcomp( const void *, const void *, void * );
|
||||
#if defined(_M_IX86)
|
||||
#pragma aux (__outside_CLIB) qcomp;
|
||||
#endif
|
||||
|
||||
|
||||
/* Function to find the median value */
|
||||
static char *med3( char *a, char *b, char *c, qcomp cmp, void *context )
|
||||
{
|
||||
if( cmp( a, b, context ) > 0 ) {
|
||||
if( cmp( a, c, context ) > 0 ) {
|
||||
if( cmp( b, c, context ) > 0 ) {
|
||||
return( b );
|
||||
} else {
|
||||
return( c );
|
||||
}
|
||||
} else {
|
||||
return( a );
|
||||
}
|
||||
} else {
|
||||
if( cmp( a, c, context ) >= 0 ) {
|
||||
return( a );
|
||||
} else {
|
||||
if( cmp( b, c, context ) > 0 ) {
|
||||
return( c );
|
||||
} else {
|
||||
return( b );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __AXP__
|
||||
|
||||
#define FUNCTION_LINKAGE static
|
||||
#define FUNCTION_NAME aligned_qsort
|
||||
#define PTRATTR
|
||||
#define MED3 med3
|
||||
#define BYTESWAP aligned_byteswap
|
||||
#include "qsortr_s.c"
|
||||
|
||||
#undef FUNCTION_NAME
|
||||
#undef PTRATTR
|
||||
#undef MED3
|
||||
#undef BYTESWAP
|
||||
#define FUNCTION_NAME unaligned_qsort
|
||||
#define PTRATTR __unaligned
|
||||
#define BYTESWAP unaligned_byteswap
|
||||
#define MED3(a,b,c,f,x) med3( (char*)(a), (char*)(b), (char*)(c), (f), (x) )
|
||||
#include "qsortr_s.c"
|
||||
|
||||
_WCRTLINK errno_t qsort_s( void *in_base, rsize_t n, rsize_t size,
|
||||
int (*compar)( const void *, const void *, void * ),
|
||||
void *context )
|
||||
/*****************************************************************/
|
||||
{
|
||||
/*
|
||||
* If size%4 is 0 and the input base pointer is on a word boundary,
|
||||
* call the aligned version of qsort. Otherwise, call the version
|
||||
* that knows its pointers will be unaligned, so all the fixups can
|
||||
* be done by qsort rather than by expensive OS exceptions.
|
||||
*/
|
||||
if( (size&3) == 0 && (((unsigned)in_base)&3) == 0 ) {
|
||||
return( aligned_qsort( in_base, n, size, compar, context ) );
|
||||
} else {
|
||||
return( unaligned_qsort( (__unaligned void *)in_base, n, size, compar, context ) );
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define FUNCTION_LINKAGE _WCRTLINK
|
||||
#define FUNCTION_NAME qsort_s
|
||||
#define PTRATTR
|
||||
#define MED3 med3
|
||||
#define BYTESWAP byteswap
|
||||
#include "qsortr_s.c"
|
||||
|
||||
#endif
|
360
programs/develop/open watcom/trunk/clib/search/qsortr_s.c
Normal file
360
programs/develop/open watcom/trunk/clib/search/qsortr_s.c
Normal file
@ -0,0 +1,360 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of qsort_s() - bounds-checking qsort().
|
||||
* Included by qsort_s.c.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/* Support OS/2 16-bit protected mode - will never get stack overflow */
|
||||
#define MAXDEPTH (sizeof( long ) * 8)
|
||||
|
||||
#define SHELL 3 /* Shell constant used in shell sort */
|
||||
|
||||
typedef int WORD;
|
||||
#define W sizeof( WORD )
|
||||
|
||||
/*
|
||||
swap() is a macro that chooses between an in_line function call and
|
||||
an exchange macro.
|
||||
*/
|
||||
#define exch( a, b, t) ( t = a, a = b, b = t )
|
||||
#define swap( a, b ) \
|
||||
swaptype != 0 ? BYTESWAP( a, b, size ) : \
|
||||
( void ) exch( *( WORD* )( a ), *( WORD* )( b ), t )
|
||||
|
||||
/*
|
||||
Note: The following assembly was timed against several other methods
|
||||
of doing the same thing. The pragmas here were either fastest on all
|
||||
machines tested, or fastest on most machines tested. (including an 8088,
|
||||
386 16mhz, 386 33mhz, and 486 25mhz).
|
||||
*/
|
||||
|
||||
#if defined( __386__ )
|
||||
/* this is intended for 386 only... */
|
||||
void inline_swap( char *p, char *q, size_t size );
|
||||
#pragma aux inline_swap = \
|
||||
0x06 /* push es */ \
|
||||
0x1e /* push ds */ \
|
||||
0x07 /* pop es */ \
|
||||
0x0f 0xb6 0xd1 /* movzx edx,cl */ \
|
||||
0xc1 0xe9 0x02 /* shr ecx,02H */ \
|
||||
0x74 0x0b /* je L1 */ \
|
||||
0x8b 0x07 /*L2 mov eax,[edi] */ \
|
||||
0x87 0x06 /* xchg eax,[esi] */ \
|
||||
0xab /* stosd */ \
|
||||
0x83 0xc6 0x04 /* add esi,0004H */ \
|
||||
0x49 /* dec ecx */ \
|
||||
0x75 0xf5 /* jne L2 */ \
|
||||
0x80 0xe2 0x03 /*L1 and dl,03H */ \
|
||||
0x74 0x09 /* je L3 */ \
|
||||
0x8a 0x07 /*L4 mov al,[edi] */ \
|
||||
0x86 0x06 /* xchg al,[esi] */ \
|
||||
0xaa /* stosb */ \
|
||||
0x46 /* inc esi */ \
|
||||
0x4a /* dec edx */ \
|
||||
0x75 0xf7 /* jne L4 */ \
|
||||
/*L3 */ \
|
||||
0x07 /* pop es */ \
|
||||
parm caller [esi] [edi] [ecx] \
|
||||
value \
|
||||
modify exact [esi edi ecx eax edx];
|
||||
#pragma aux byteswap parm [esi] [edi] [ecx] \
|
||||
modify exact [esi edi ecx eax edx];
|
||||
static void _WCNEAR byteswap( char *p, char *q, size_t size ) {
|
||||
inline_swap( p, q, size );
|
||||
}
|
||||
|
||||
#elif defined( M_I86 ) && defined( __BIG_DATA__ )
|
||||
void inline_swap( char _WCFAR *p, char _WCFAR *q, size_t size );
|
||||
#pragma aux inline_swap = \
|
||||
0x1e /* push ds */ \
|
||||
0x8e 0xda /* mov ds,dx */ \
|
||||
0xd1 0xe9 /* shr cx,1 */ \
|
||||
0x74 0x0b /* je L1 */ \
|
||||
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
|
||||
0x87 0x04 /* xchg ax,[si] */ \
|
||||
0xab /* stosw */ \
|
||||
0x46 /* inc si */ \
|
||||
0x46 /* inc si */ \
|
||||
0x49 /* dec cx */ \
|
||||
0x75 0xf5 /* jne L2 */ \
|
||||
0x73 0x07 /*L1 jnc L3 */ \
|
||||
0x8a 0x04 /* mov al,[si] */ \
|
||||
0x26 0x86 0x05 /* xchg al,es:[di] */ \
|
||||
0x88 0x04 /* mov [si],al */ \
|
||||
0x1f /*L3 pop ds */ \
|
||||
parm caller [dx si] [es di] [cx] \
|
||||
value \
|
||||
modify exact [si di cx ax];
|
||||
#pragma aux byteswap parm [dx si] [es di] [cx] modify exact [si di cx ax];
|
||||
static void _WCNEAR byteswap( char _WCFAR *p, char _WCFAR *q, size_t size ) {
|
||||
inline_swap( p, q, size );
|
||||
}
|
||||
|
||||
#elif defined( M_I86 ) && defined( __SMALL_DATA__ )
|
||||
/* we'll ask for char __far *q to save us writing code to load es */
|
||||
void inline_swap( char *p, char _WCFAR *q, size_t size );
|
||||
#pragma aux inline_swap = \
|
||||
0xd1 0xe9 /* shr cx,1 */ \
|
||||
0x74 0x0b /* je L1 */ \
|
||||
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
|
||||
0x87 0x04 /* xchg ax,[si] */ \
|
||||
0xab /* stosw */ \
|
||||
0x46 /* inc si */ \
|
||||
0x46 /* inc si */ \
|
||||
0x49 /* dec cx */ \
|
||||
0x75 0xf5 /* jne L2 */ \
|
||||
0x73 0x07 /*L1 jnc L3 */ \
|
||||
0x8a 0x04 /* mov al,[si] */ \
|
||||
0x26 0x86 0x05 /* xchg al,es:[di] */ \
|
||||
0x88 0x04 /* mov [si],al */ \
|
||||
/*L3 */ \
|
||||
parm caller [si] [es di] [cx] \
|
||||
value \
|
||||
modify exact [si di cx ax];
|
||||
#pragma aux byteswap parm [si] [es di] [cx] modify exact [si di cx ax];
|
||||
static void _WCNEAR byteswap( char *p, char _WCFAR *q, size_t size ) {
|
||||
inline_swap( p, q, size );
|
||||
}
|
||||
|
||||
#else
|
||||
/* this is an optimized version of a simple byteswap */
|
||||
#define inline_swap BYTESWAP
|
||||
static void _WCNEAR BYTESWAP( PTRATTR char *p, PTRATTR char *q, size_t size ) {
|
||||
long dword;
|
||||
short word;
|
||||
char byte;
|
||||
|
||||
#if 1 /* this is for 32 bit machines */
|
||||
while( size > 3 ) {
|
||||
dword = *(PTRATTR long *)p;
|
||||
*(PTRATTR long *)p = *(PTRATTR long *)q;
|
||||
*(PTRATTR long *)q = dword;
|
||||
p += 4;
|
||||
q += 4;
|
||||
size -= 4;
|
||||
}
|
||||
if( size > 1 ) {
|
||||
word = *(PTRATTR short *)p;
|
||||
*(PTRATTR short *)p = *(PTRATTR short *)q;
|
||||
*(PTRATTR short *)q = word;
|
||||
p += 2;
|
||||
q += 2;
|
||||
size -= 2;
|
||||
}
|
||||
#else /* this is for 16 bit machines */
|
||||
while( size > 1 ) {
|
||||
word = *(PTRATTR short *)p;
|
||||
*(PTRATTR short *)p = *(PTRATTR short *)q;
|
||||
*(PTRATTR short *)q = word;
|
||||
p += 2;
|
||||
q += 2;
|
||||
size -= 2;
|
||||
}
|
||||
#endif
|
||||
if( size ) {
|
||||
byte = *p;
|
||||
*p = *q;
|
||||
*q = byte;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
FUNCTION_LINKAGE errno_t FUNCTION_NAME( PTRATTR void *in_base,
|
||||
rsize_t n, rsize_t size,
|
||||
int (*compar)( const void *, const void *, void * ),
|
||||
void *context )
|
||||
/*****************************************************************/
|
||||
{
|
||||
PTRATTR char *base = (PTRATTR char*) in_base;
|
||||
PTRATTR char *p1;
|
||||
PTRATTR char *p2;
|
||||
PTRATTR char *pa;
|
||||
PTRATTR char *pb;
|
||||
PTRATTR char *pc;
|
||||
PTRATTR char *pd;
|
||||
PTRATTR char *pn;
|
||||
PTRATTR char *pv;
|
||||
PTRATTR char *mid;
|
||||
WORD v; /* used in pivot initialization */
|
||||
WORD t; /* used in exch() macro */
|
||||
int comparison, swaptype, shell;
|
||||
size_t count, r, s;
|
||||
unsigned sp;
|
||||
auto char *base_stack[MAXDEPTH];
|
||||
unsigned n_stack[MAXDEPTH];
|
||||
qcomp *cmp = (qcomp*)compar;
|
||||
errno_t rc = -1;
|
||||
|
||||
/* runtime-constraints */
|
||||
// n <= RSIZE_MAX
|
||||
// size <= RSIZE_MAX
|
||||
// if n > 0 then in_base, compar not NULL
|
||||
if( __check_constraint_maxsize( n ) &&
|
||||
__check_constraint_maxsize( size ) &&
|
||||
((n == 0) || __check_constraint_nullptr( in_base ) &&
|
||||
__check_constraint_nullptr( compar )) ) {
|
||||
|
||||
if( n == 0 ) { /* empty array - nothing to do */
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
Initialization of the swaptype variable, which determines which
|
||||
type of swapping should be performed when swap() is called.
|
||||
0 for single-word swaps, 1 for general swapping by words, and
|
||||
2 for swapping by bytes. W (it's a macro) = sizeof(WORD).
|
||||
*/
|
||||
swaptype = ( ( base - (char *)0 ) | size ) % W ? 2 : size > W ? 1 : 0;
|
||||
sp = 0;
|
||||
for( ;; ) {
|
||||
while( n > 1 ) {
|
||||
if( n < 16 ) { /* 2-shell sort on smallest arrays */
|
||||
for( shell = (size * SHELL) ;
|
||||
shell > 0 ;
|
||||
shell -= ((SHELL-1) * size) ) {
|
||||
p1 = base + shell;
|
||||
for( ; p1 < base + n * size; p1 += shell ) {
|
||||
for( p2 = p1;
|
||||
p2 > base && cmp( p2 - shell, p2, context ) > 0;
|
||||
p2 -= shell ) {
|
||||
swap( p2, p2 - shell );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else { /* n >= 16 */
|
||||
/* Small array (15 < n < 30), mid element */
|
||||
mid = base + (n >> 1) * size;
|
||||
if( n > 29 ) {
|
||||
p1 = base;
|
||||
p2 = base + ( n - 1 ) * size;
|
||||
if( n > 42 ) { /* Big array, pseudomedian of 9 */
|
||||
s = (n >> 3) * size;
|
||||
p1 = MED3( p1, p1 + s, p1 + (s << 1), cmp, context );
|
||||
mid = MED3( mid - s, mid, mid + s, cmp, context );
|
||||
p2 = MED3( p2 - (s << 1), p2 - s, p2, cmp, context );
|
||||
}
|
||||
/* Mid-size (29 < n < 43), med of 3 */
|
||||
mid = MED3( p1, mid, p2, cmp, context );
|
||||
}
|
||||
/*
|
||||
The following sets up the pivot (pv) for partitioning.
|
||||
It's better to store the pivot value out of line
|
||||
instead of swapping it to base. However, it's
|
||||
inconvenient in C unless the element size is fixed.
|
||||
So, only the important special case of word-size
|
||||
objects has utilized it.
|
||||
*/
|
||||
if( swaptype != 0 ) { /* Not word-size objects */
|
||||
pv = base;
|
||||
swap( pv, mid );
|
||||
} else { /* Storing the pivot out of line (at v) */
|
||||
pv = (char *)&v;
|
||||
v = *(WORD *)mid;
|
||||
}
|
||||
|
||||
pa = pb = base;
|
||||
pc = pd = base + ( n - 1 ) * size;
|
||||
count = n;
|
||||
/*
|
||||
count keeps track of how many entries we have
|
||||
examined. Once we have looked at all the entries
|
||||
then we know that the partitioning is complete.
|
||||
We use count to terminate the looping, rather than
|
||||
a pointer comparison, to handle 16bit pointer
|
||||
limitations that may lead pb or pc to wrap.
|
||||
i.e. pc = 0x0000;
|
||||
pc -= 0x0004;
|
||||
pc == 0xfffc;
|
||||
pc is no longer less that 0x0000;
|
||||
*/
|
||||
for( ;; ) {
|
||||
while( count && (comparison = cmp(pb, pv, context )) <= 0 ) {
|
||||
if( comparison == 0 ) {
|
||||
swap( pa, pb );
|
||||
pa += size;
|
||||
}
|
||||
pb += size;
|
||||
count--;
|
||||
}
|
||||
while( count && (comparison = cmp(pc, pv, context )) >= 0 ) {
|
||||
if( comparison == 0 ) {
|
||||
swap( pc, pd );
|
||||
pd -= size;
|
||||
}
|
||||
pc -= size;
|
||||
count--;
|
||||
}
|
||||
if( !count ) break;
|
||||
swap( pb, pc );
|
||||
pb += size;
|
||||
count--;
|
||||
if( !count ) break;
|
||||
pc -= size;
|
||||
count--;
|
||||
}
|
||||
pn = base + n * size;
|
||||
s = min( pa - base, pb - pa );
|
||||
if( s > 0 ) {
|
||||
inline_swap( base, pb - s, s );
|
||||
}
|
||||
s = min( pd - pc, pn - pd - size);
|
||||
if( s > 0 ) {
|
||||
inline_swap( pb, pn - s, s );
|
||||
}
|
||||
/* Now, base to (pb-pa) needs to be sorted */
|
||||
/* Also, pn-(pd-pc) needs to be sorted */
|
||||
/* The middle 'chunk' contains all elements=pivot value */
|
||||
r = pb - pa;
|
||||
s = pd - pc;
|
||||
if( s >= r ) { /* Stack up the larger chunk */
|
||||
base_stack[sp] = pn - s; /* Stack up base */
|
||||
n_stack[sp] = s / size; /* Stack up n */
|
||||
n = r / size; /* Set up n for next 'call' */
|
||||
/* next base is still base */
|
||||
} else {
|
||||
if( r <= size ) break;
|
||||
base_stack[sp] = base; /* Stack up base */
|
||||
n_stack[sp] = r / size; /* Stack up n */
|
||||
base = pn - s; /* Set up base and n for */
|
||||
n = s / size; /* next 'call' */
|
||||
}
|
||||
++sp;
|
||||
}
|
||||
}
|
||||
if( sp == 0 ) break;
|
||||
--sp;
|
||||
base = base_stack[sp];
|
||||
n = n_stack[sp];
|
||||
}
|
||||
rc = 0;
|
||||
}
|
||||
return( rc );
|
||||
}
|
349
programs/develop/open watcom/trunk/clib/search/qsortrtn.c
Normal file
349
programs/develop/open watcom/trunk/clib/search/qsortrtn.c
Normal file
@ -0,0 +1,349 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* This file is #included by qsort.c.
|
||||
*/
|
||||
|
||||
|
||||
/* Support OS/2 16-bit protected mode - will never get stack overflow */
|
||||
#define MAXDEPTH (sizeof(long) * 8)
|
||||
|
||||
#define SHELL 3 /* Shell constant used in shell sort */
|
||||
|
||||
typedef int WORD;
|
||||
#define W sizeof( WORD )
|
||||
|
||||
/*
|
||||
swap() is a macro that chooses between an in_line function call and
|
||||
an exchange macro.
|
||||
*/
|
||||
#define exch( a, b, t) ( t = a, a = b, b = t )
|
||||
#define swap( a, b ) \
|
||||
swaptype != 0 ? BYTESWAP( a, b, size ) : \
|
||||
( void ) exch( *( WORD* )( a ), *( WORD* )( b ), t )
|
||||
|
||||
/*
|
||||
Note: The following assembly was timed against several other methods
|
||||
of doing the same thing. The pragmas here were either fastest on all
|
||||
machines tested, or fastest on most machines tested. (including an 8088,
|
||||
386 16mhz, 386 33mhz, and 486 25mhz).
|
||||
*/
|
||||
|
||||
#if defined( __386__ )
|
||||
/* this is intended for 386 only... */
|
||||
void inline_swap( char *p, char *q, size_t size );
|
||||
#pragma aux inline_swap = \
|
||||
0x06 /* push es */ \
|
||||
0x1e /* push ds */ \
|
||||
0x07 /* pop es */ \
|
||||
0x0f 0xb6 0xd1 /* movzx edx,cl */ \
|
||||
0xc1 0xe9 0x02 /* shr ecx,02H */ \
|
||||
0x74 0x0b /* je L1 */ \
|
||||
0x8b 0x07 /*L2 mov eax,[edi] */ \
|
||||
0x87 0x06 /* xchg eax,[esi] */ \
|
||||
0xab /* stosd */ \
|
||||
0x83 0xc6 0x04 /* add esi,0004H */ \
|
||||
0x49 /* dec ecx */ \
|
||||
0x75 0xf5 /* jne L2 */ \
|
||||
0x80 0xe2 0x03 /*L1 and dl,03H */ \
|
||||
0x74 0x09 /* je L3 */ \
|
||||
0x8a 0x07 /*L4 mov al,[edi] */ \
|
||||
0x86 0x06 /* xchg al,[esi] */ \
|
||||
0xaa /* stosb */ \
|
||||
0x46 /* inc esi */ \
|
||||
0x4a /* dec edx */ \
|
||||
0x75 0xf7 /* jne L4 */ \
|
||||
/*L3 */ \
|
||||
0x07 /* pop es */ \
|
||||
parm caller [esi] [edi] [ecx] \
|
||||
value \
|
||||
modify exact [esi edi ecx eax edx];
|
||||
#pragma aux byteswap parm [esi] [edi] [ecx] \
|
||||
modify exact [esi edi ecx eax edx];
|
||||
static void _WCNEAR byteswap( char *p, char *q, size_t size ) {
|
||||
inline_swap( p, q, size );
|
||||
}
|
||||
|
||||
#elif defined( M_I86 ) && defined( __BIG_DATA__ )
|
||||
void inline_swap( char _WCFAR *p, char _WCFAR *q, size_t size );
|
||||
#pragma aux inline_swap = \
|
||||
0x1e /* push ds */ \
|
||||
0x8e 0xda /* mov ds,dx */ \
|
||||
0xd1 0xe9 /* shr cx,1 */ \
|
||||
0x74 0x0b /* je L1 */ \
|
||||
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
|
||||
0x87 0x04 /* xchg ax,[si] */ \
|
||||
0xab /* stosw */ \
|
||||
0x46 /* inc si */ \
|
||||
0x46 /* inc si */ \
|
||||
0x49 /* dec cx */ \
|
||||
0x75 0xf5 /* jne L2 */ \
|
||||
0x73 0x07 /*L1 jnc L3 */ \
|
||||
0x8a 0x04 /* mov al,[si] */ \
|
||||
0x26 0x86 0x05 /* xchg al,es:[di] */ \
|
||||
0x88 0x04 /* mov [si],al */ \
|
||||
0x1f /*L3 pop ds */ \
|
||||
parm caller [dx si] [es di] [cx] \
|
||||
value \
|
||||
modify exact [si di cx ax];
|
||||
#pragma aux byteswap parm [dx si] [es di] [cx] modify exact [si di cx ax];
|
||||
static void _WCNEAR byteswap( char _WCFAR *p, char _WCFAR *q, size_t size ) {
|
||||
inline_swap( p, q, size );
|
||||
}
|
||||
|
||||
#elif defined( M_I86 ) && defined( __SMALL_DATA__ )
|
||||
/* we'll ask for char __far *q to save us writing code to load es */
|
||||
void inline_swap( char *p, char _WCFAR *q, size_t size );
|
||||
#pragma aux inline_swap = \
|
||||
0xd1 0xe9 /* shr cx,1 */ \
|
||||
0x74 0x0b /* je L1 */ \
|
||||
0x26 0x8b 0x05 /*L2 mov ax,es:[di] */ \
|
||||
0x87 0x04 /* xchg ax,[si] */ \
|
||||
0xab /* stosw */ \
|
||||
0x46 /* inc si */ \
|
||||
0x46 /* inc si */ \
|
||||
0x49 /* dec cx */ \
|
||||
0x75 0xf5 /* jne L2 */ \
|
||||
0x73 0x07 /*L1 jnc L3 */ \
|
||||
0x8a 0x04 /* mov al,[si] */ \
|
||||
0x26 0x86 0x05 /* xchg al,es:[di] */ \
|
||||
0x88 0x04 /* mov [si],al */ \
|
||||
/*L3 */ \
|
||||
parm caller [si] [es di] [cx] \
|
||||
value \
|
||||
modify exact [si di cx ax];
|
||||
#pragma aux byteswap parm [si] [es di] [cx] modify exact [si di cx ax];
|
||||
static void _WCNEAR byteswap( char *p, char _WCFAR *q, size_t size ) {
|
||||
inline_swap( p, q, size );
|
||||
}
|
||||
|
||||
#else
|
||||
/* this is an optimized version of a simple byteswap */
|
||||
#define inline_swap BYTESWAP
|
||||
static void _WCNEAR BYTESWAP( PTRATTR char *p, PTRATTR char *q, size_t size ) {
|
||||
long dword;
|
||||
short word;
|
||||
char byte;
|
||||
|
||||
#if 1 /* this is for 32 bit machines */
|
||||
while( size > 3 ) {
|
||||
dword = *(PTRATTR long *)p;
|
||||
*(PTRATTR long *)p = *(PTRATTR long *)q;
|
||||
*(PTRATTR long *)q = dword;
|
||||
p += 4;
|
||||
q += 4;
|
||||
size -= 4;
|
||||
}
|
||||
if( size > 1 ) {
|
||||
word = *(PTRATTR short *)p;
|
||||
*(PTRATTR short *)p = *(PTRATTR short *)q;
|
||||
*(PTRATTR short *)q = word;
|
||||
p += 2;
|
||||
q += 2;
|
||||
size -= 2;
|
||||
}
|
||||
#else /* this is for 16 bit machines */
|
||||
while( size > 1 ) {
|
||||
word = *(PTRATTR short *)p;
|
||||
*(PTRATTR short *)p = *(PTRATTR short *)q;
|
||||
*(PTRATTR short *)q = word;
|
||||
p += 2;
|
||||
q += 2;
|
||||
size -= 2;
|
||||
}
|
||||
#endif
|
||||
if( size ) {
|
||||
byte = *p;
|
||||
*p = *q;
|
||||
*q = byte;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
FUNCTION_LINKAGE void FUNCTION_NAME(
|
||||
PTRATTR void *in_base, size_t n,
|
||||
size_t size,
|
||||
int (*compar)(const void *, const void *)
|
||||
)
|
||||
/**********************************************************************/
|
||||
{
|
||||
PTRATTR char * base = (PTRATTR char*) in_base;
|
||||
PTRATTR char * p1;
|
||||
PTRATTR char * p2;
|
||||
PTRATTR char * pa;
|
||||
PTRATTR char * pb;
|
||||
PTRATTR char * pc;
|
||||
PTRATTR char * pd;
|
||||
PTRATTR char * pn;
|
||||
PTRATTR char * pv;
|
||||
PTRATTR char * mid;
|
||||
WORD v; /* used in pivot initialization */
|
||||
WORD t; /* used in exch() macro */
|
||||
int comparison, swaptype, shell;
|
||||
size_t count, r, s;
|
||||
unsigned int sp;
|
||||
auto char * base_stack[MAXDEPTH];
|
||||
auto unsigned int n_stack[MAXDEPTH];
|
||||
qcomp * cmp = (qcomp*) compar;
|
||||
|
||||
/*
|
||||
Initialization of the swaptype variable, which determines which
|
||||
type of swapping should be performed when swap() is called.
|
||||
0 for single-word swaps, 1 for general swapping by words, and
|
||||
2 for swapping by bytes. W (it's a macro) = sizeof(WORD).
|
||||
*/
|
||||
swaptype = ( ( base - (char *)0 ) | size ) % W ? 2 : size > W ? 1 : 0;
|
||||
sp = 0;
|
||||
for(;;) {
|
||||
while( n > 1 ) {
|
||||
if( n < 16 ) { /* 2-shell sort on smallest arrays */
|
||||
for( shell = (size * SHELL) ;
|
||||
shell > 0 ;
|
||||
shell -= ((SHELL-1) * size) ) {
|
||||
p1 = base + shell;
|
||||
for( ; p1 < base + n * size; p1 += shell ) {
|
||||
for( p2 = p1;
|
||||
p2 > base && cmp( p2 - shell, p2 ) > 0;
|
||||
p2 -= shell ) {
|
||||
swap( p2, p2 - shell );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else { /* n >= 16 */
|
||||
/* Small array (15 < n < 30), mid element */
|
||||
mid = base + (n >> 1) * size;
|
||||
if( n > 29 ) {
|
||||
p1 = base;
|
||||
p2 = base + ( n - 1 ) * size;
|
||||
if( n > 42 ) { /* Big array, pseudomedian of 9 */
|
||||
s = (n >> 3) * size;
|
||||
p1 = MED3( p1, p1 + s, p1 + (s << 1), cmp );
|
||||
mid = MED3( mid - s, mid, mid + s, cmp );
|
||||
p2 = MED3( p2 - (s << 1), p2 - s, p2, cmp );
|
||||
}
|
||||
/* Mid-size (29 < n < 43), med of 3 */
|
||||
mid = MED3( p1, mid, p2, cmp );
|
||||
}
|
||||
/*
|
||||
The following sets up the pivot (pv) for partitioning.
|
||||
It's better to store the pivot value out of line
|
||||
instead of swapping it to base. However, it's
|
||||
inconvenient in C unless the element size is fixed.
|
||||
So, only the important special case of word-size
|
||||
objects has utilized it.
|
||||
*/
|
||||
if( swaptype != 0 ) { /* Not word-size objects */
|
||||
pv = base;
|
||||
swap( pv, mid );
|
||||
} else { /* Storing the pivot out of line (at v) */
|
||||
pv = ( char* )&v;
|
||||
v = *( WORD* )mid;
|
||||
}
|
||||
|
||||
pa = pb = base;
|
||||
pc = pd = base + ( n - 1 ) * size;
|
||||
count = n;
|
||||
/*
|
||||
count keeps track of how many entries we have
|
||||
examined. Once we have looked at all the entries
|
||||
then we know that the partitioning is complete.
|
||||
We use count to terminate the looping, rather than
|
||||
a pointer comparison, to handle 16bit pointer
|
||||
limitations that may lead pb or pc to wrap.
|
||||
i.e. pc = 0x0000;
|
||||
pc -= 0x0004;
|
||||
pc == 0xfffc;
|
||||
pc is no longer less that 0x0000;
|
||||
*/
|
||||
for(;;) {
|
||||
while(count && (comparison = cmp(pb, pv)) <= 0) {
|
||||
if( comparison == 0 ) {
|
||||
swap( pa, pb );
|
||||
pa += size;
|
||||
}
|
||||
pb += size;
|
||||
count--;
|
||||
}
|
||||
while(count && (comparison = cmp(pc, pv)) >= 0) {
|
||||
if( comparison == 0 ) {
|
||||
swap( pc, pd );
|
||||
pd -= size;
|
||||
}
|
||||
pc -= size;
|
||||
count--;
|
||||
}
|
||||
if( !count ) break;
|
||||
swap( pb, pc );
|
||||
pb += size;
|
||||
count--;
|
||||
if( !count ) break;
|
||||
pc -= size;
|
||||
count--;
|
||||
}
|
||||
pn = base + n * size;
|
||||
s = min( pa - base, pb - pa );
|
||||
if( s > 0 ) {
|
||||
inline_swap( base, pb - s, s );
|
||||
}
|
||||
s = min( pd - pc, pn - pd - size);
|
||||
if( s > 0 ) {
|
||||
inline_swap( pb, pn - s, s );
|
||||
}
|
||||
/* Now, base to (pb-pa) needs to be sorted */
|
||||
/* Also, pn-(pd-pc) needs to be sorted */
|
||||
/* The middle 'chunk' contains all elements=pivot value*/
|
||||
r = pb - pa;
|
||||
s = pd - pc;
|
||||
if( s >= r ) { /* Stack up the larger chunk */
|
||||
base_stack[sp] = pn - s;/* Stack up base */
|
||||
n_stack[sp] = s / size; /* Stack up n */
|
||||
n = r / size; /* Set up n for next 'call'*/
|
||||
/* next base is still base */
|
||||
} else {
|
||||
if( r <= size ) break;
|
||||
base_stack[sp] = base; /* Stack up base */
|
||||
n_stack[sp] = r / size; /* Stack up n */
|
||||
base = pn - s; /* Set up base and n for */
|
||||
n = s / size; /* next 'call' */
|
||||
}
|
||||
++sp;
|
||||
}
|
||||
}
|
||||
if( sp == 0 ) break;
|
||||
--sp;
|
||||
base = base_stack[sp];
|
||||
n = n_stack[sp];
|
||||
}
|
||||
}
|
47
programs/develop/open watcom/trunk/clib/src/fstatus.inc
Normal file
47
programs/develop/open watcom/trunk/clib/src/fstatus.inc
Normal file
@ -0,0 +1,47 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
;* DESCRIBE IT HERE!
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
FPE_OK equ 0
|
||||
FPE_INVALID equ 81h
|
||||
FPE_DENORMAL equ 82h
|
||||
FPE_ZERODIVIDE equ 83h
|
||||
FPE_OVERFLOW equ 84h
|
||||
FPE_UNDERFLOW equ 85h
|
||||
FPE_INEXACT equ 86h
|
||||
FPE_UNEMULATED equ 87h
|
||||
FPE_SQRTNEG equ 88h
|
||||
FPE_STACKOVERFLOW equ 8ah
|
||||
FPE_STACKUNDERFLOW equ 8bh
|
||||
FPE_EXPLICITGEN equ 8ch
|
||||
FPE_IOVERFLOW equ 8dh
|
||||
FPE_LOGERR equ 8eh
|
||||
FPE_MODERR equ 8fh
|
103
programs/develop/open watcom/trunk/clib/src/saferlib.h
Normal file
103
programs/develop/open watcom/trunk/clib/src/saferlib.h
Normal file
@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Internal data and routines for "Safer C", or bounds-checking
|
||||
* library extension.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef _SAFERLIB_H_INCLUDED
|
||||
#define _SAFERLIB_H_INCLUDED
|
||||
|
||||
#define __STDC_WANT_LIB_EXT1__ 1
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Maximum length of runtime-constraint error message
|
||||
#define RTCT_MSG_MAX 128
|
||||
|
||||
#define _RWD_rtcthandler __runtime_constraint_handler
|
||||
|
||||
extern constraint_handler_t __runtime_constraint_handler;
|
||||
|
||||
extern void __rtct_fail( const char *fn, const char *reason, void *reserved );
|
||||
|
||||
// Runtime-constraint validation macros. Call the handler and return zero if check
|
||||
// failed, return non-zero value if check succeeded.
|
||||
|
||||
#define __check_constraint_nullptr( arg ) \
|
||||
((arg == NULL) ? __rtct_fail( __func__, #arg " == NULL", NULL ), 0 : 1)
|
||||
|
||||
#define __check_constraint_maxsize( arg ) \
|
||||
((arg > RSIZE_MAX) ? __rtct_fail( __func__, #arg " > RSIZE_MAX", NULL ), 0 : 1)
|
||||
|
||||
#define __check_constraint_zero( arg ) \
|
||||
((arg == 0) ? __rtct_fail( __func__, #arg " == 0", NULL ), 0 : 1)
|
||||
|
||||
#define __check_constraint_toosmall( name, left ) \
|
||||
((left == 0) ? __rtct_fail( __func__, #name " is too small to hold data", NULL ), 0 : 1)
|
||||
|
||||
|
||||
// Runtime-constraint validation macros. Construct the message and return
|
||||
// zero if check failed, return non-zero value if check succeeded.
|
||||
// __rtct_fail has to be explicitly called later.
|
||||
|
||||
#define __check_constraint_nullptr_msg( msg, arg ) \
|
||||
((arg == NULL) ? ( msg = #arg " == NULL" ), 0 : 1)
|
||||
|
||||
#define __check_constraint_maxsize_msg( msg, arg ) \
|
||||
((arg > RSIZE_MAX) ? ( msg = #arg " > RSIZE_MAX" ), 0 : 1)
|
||||
|
||||
#define __check_constraint_zero_msg( msg, arg ) \
|
||||
((arg == 0) ? ( msg = #arg " == 0" ), 0 : 1)
|
||||
|
||||
#define __check_constraint_toosmall_msg( msg, name, left ) \
|
||||
((left == 0) ? ( msg = #name " is too small to hold data" ), 0 : 1)
|
||||
|
||||
#define __check_constraint_a_gt_b_msg( msg, a, b ) \
|
||||
((a > b) ? ( msg = #a " > " #b ), 0 : 1)
|
||||
|
||||
#define __check_constraint_overlap_msg( msg, p1, len1, p2, len2 ) \
|
||||
(((p1 == p2) || ( (p1 > p2) && ( p1 < (CHAR_TYPE *)p2 + len2 * sizeof( CHAR_TYPE ))) \
|
||||
|| ( (p2 > p1) && ( p2 < (CHAR_TYPE *)p1 + len1 * sizeof( CHAR_TYPE )))) \
|
||||
? ( msg = #p1 " overlap " #p2 ), 0 : 1)
|
||||
|
||||
|
||||
// For 16-bit targets, the RSIZE_MAX check is effectively no-op. Object sizes
|
||||
// up to SIZE_MAX are legal and not uncommon.
|
||||
#if RSIZE_MAX == SIZE_MAX
|
||||
#undef __check_constraint_maxsize
|
||||
#define __check_constraint_maxsize( arg ) 1
|
||||
#undef __check_constraint_maxsize_msg
|
||||
#define __check_constraint_maxsize_msg( msg, arg ) 1
|
||||
|
||||
#define __lte_rsizmax( arg ) 1
|
||||
#else
|
||||
#define __lte_rsizmax( arg ) (arg <= RSIZE_MAX)
|
||||
#endif
|
||||
|
||||
#endif // _SAFERLIB_H_INCLUDED
|
41
programs/develop/open watcom/trunk/clib/src/strdup.h
Normal file
41
programs/develop/open watcom/trunk/clib/src/strdup.h
Normal file
@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __STRDUP_H_INCLUDED
|
||||
#define __STRDUP_H_INCLUDED
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
|
||||
_WCRTLINK extern char *__clib_strdup( const char *str );
|
||||
_WCRTLINK extern wchar_t *__clib_wcsdup( const wchar_t *str );
|
||||
#endif
|
48
programs/develop/open watcom/trunk/clib/string/bits.c
Normal file
48
programs/develop/open watcom/trunk/clib/string/bits.c
Normal file
@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
#include "setbits.h"
|
||||
|
||||
const unsigned char _HUGEDATA _Bits[] =
|
||||
{ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
|
||||
|
||||
void __setbits( unsigned char vector[32], const char *charset )
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
memset( vector, 0, 32 );
|
||||
for( ; c = *charset; ++charset ) {
|
||||
vector[ c >> 3 ] |= _Bits[ c & 0x07 ];
|
||||
}
|
||||
}
|
139
programs/develop/open watcom/trunk/clib/string/bprintf.c
Normal file
139
programs/develop/open watcom/trunk/clib/string/bprintf.c
Normal file
@ -0,0 +1,139 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: This module supports formatted output to a character buffer.
|
||||
* Both character and wide character formatting are included.
|
||||
* For added library granularity, this module could be split
|
||||
* into two, with "bprintf" functions in one file and the
|
||||
* "snprintf" functions in another.
|
||||
*
|
||||
* C library functions:
|
||||
* _bprintf, _vbprintf
|
||||
* _bwprintf, _vbwprintf
|
||||
* _snprintf, _snwprintf
|
||||
* _vsnprintf, _vsnwprintf
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "printf.h"
|
||||
|
||||
struct buf_limit {
|
||||
CHAR_TYPE *bufptr;
|
||||
size_t bufsize;
|
||||
int bufover;
|
||||
};
|
||||
|
||||
/*
|
||||
* buf_putc -- append a character to a string in memory
|
||||
*/
|
||||
static slib_callback_t buf_putc; // setup calling convention
|
||||
static void __SLIB_CALLBACK buf_putc( SPECS __SLIB *specs, int op_char )
|
||||
{
|
||||
struct buf_limit *bufinfo;
|
||||
|
||||
bufinfo = (struct buf_limit *)specs->_dest;
|
||||
if( specs->_output_count < bufinfo->bufsize ) {
|
||||
*( bufinfo->bufptr++ ) = op_char;
|
||||
specs->_output_count++;
|
||||
} else {
|
||||
bufinfo->bufover = -1;
|
||||
}
|
||||
}
|
||||
|
||||
_WCRTLINK int __F_NAME(_vbprintf,_vbwprintf) ( CHAR_TYPE *s, size_t bufsize,
|
||||
const CHAR_TYPE *format, va_list arg)
|
||||
{
|
||||
register int len;
|
||||
auto struct buf_limit bufinfo;
|
||||
slib_callback_t *tmp;
|
||||
|
||||
bufinfo.bufptr = s;
|
||||
bufinfo.bufsize = bufsize - 1;
|
||||
bufinfo.bufover = 0;
|
||||
#if defined( __386__ ) && defined( __QNX__ )
|
||||
/* avoid some segment relocations for 32-bit QNX */
|
||||
tmp = (void (*)())buf_putc;
|
||||
#else
|
||||
tmp = buf_putc;
|
||||
#endif
|
||||
len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, tmp );
|
||||
s[len] = '\0';
|
||||
return( len );
|
||||
}
|
||||
|
||||
_WCRTLINK int __F_NAME(_bprintf,_bwprintf) ( CHAR_TYPE *dest, size_t bufsize,
|
||||
const CHAR_TYPE *format, ... )
|
||||
{
|
||||
auto va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return( __F_NAME(_vbprintf,_vbwprintf)( dest, bufsize, format, args ) );
|
||||
}
|
||||
|
||||
// Notes:
|
||||
// _vsnprintf, _vsnwprintf must return an error (-1) when buffer too small
|
||||
// If a NULL character can fit, append it. If not, no error.
|
||||
|
||||
_WCRTLINK int __F_NAME(_vsnprintf,_vsnwprintf) ( CHAR_TYPE *s, size_t bufsize,
|
||||
const CHAR_TYPE *format, va_list arg)
|
||||
{
|
||||
register int len;
|
||||
auto struct buf_limit bufinfo;
|
||||
slib_callback_t *tmp;
|
||||
|
||||
bufinfo.bufptr = s;
|
||||
bufinfo.bufsize = bufsize;
|
||||
bufinfo.bufover = 0;
|
||||
#if defined( __386__ ) && defined( __QNX__ )
|
||||
/* avoid some segment relocations for 32-bit QNX */
|
||||
tmp = (void (*)())buf_putc;
|
||||
#else
|
||||
tmp = buf_putc;
|
||||
#endif
|
||||
len = __F_NAME(__prtf,__wprtf)( &bufinfo, format, arg, tmp );
|
||||
if( len < bufsize ) {
|
||||
s[len] = '\0';
|
||||
}
|
||||
if( bufinfo.bufover == 0 ) {
|
||||
return( len );
|
||||
} else {
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
_WCRTLINK int __F_NAME(_snprintf,_snwprintf) ( CHAR_TYPE *dest, size_t bufsize,
|
||||
const CHAR_TYPE *format, ... )
|
||||
{
|
||||
auto va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return( __F_NAME(_vsnprintf,_vsnwprintf)( dest, bufsize, format, args ) );
|
||||
}
|
213
programs/develop/open watcom/trunk/clib/string/cmp386.asm
Normal file
213
programs/develop/open watcom/trunk/clib/string/cmp386.asm
Normal file
@ -0,0 +1,213 @@
|
||||
;*****************************************************************************
|
||||
;*
|
||||
;* Open Watcom Project
|
||||
;*
|
||||
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* This file contains Original Code and/or Modifications of Original
|
||||
;* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
;* Public License version 1.0 (the 'License'). You may not use this file
|
||||
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
;* provided with the Original Code and Modifications, and is also
|
||||
;* available at www.sybase.com/developer/opensource.
|
||||
;*
|
||||
;* The Original Code and all software distributed under the License are
|
||||
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
;* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
;* governing rights and limitations under the License.
|
||||
;*
|
||||
;* ========================================================================
|
||||
;*
|
||||
;* Description: Intel 386 implementation strcmp().
|
||||
;*
|
||||
;*****************************************************************************
|
||||
|
||||
|
||||
include mdef.inc
|
||||
include struct.inc
|
||||
|
||||
ifdef _PROFILE
|
||||
include p5prof.inc
|
||||
endif
|
||||
|
||||
modstart _strcmp,para
|
||||
|
||||
cmp4 macro off
|
||||
mov ebx,off[eax] ; get dword from op1
|
||||
mov ecx,off[edx] ; get dword from op2
|
||||
cmp ecx,ebx ; compare them
|
||||
jne unequal ; quit if not equal
|
||||
ife off-12
|
||||
add eax,off+4 ; point to next group of dwords
|
||||
add edx,off+4 ; ...
|
||||
endif
|
||||
not ecx ; ...
|
||||
add ebx,0FEFEFEFFh ; determine if '\0' is one of bytes
|
||||
and ebx,ecx ; ...
|
||||
and ebx,80808080h ; ebx will be non-zero if '\0' found
|
||||
endm
|
||||
|
||||
defpe strcmp
|
||||
xdefp "C",strcmp
|
||||
ifdef _PROFILE
|
||||
P5Prolog
|
||||
endif
|
||||
ifdef __STACK__
|
||||
mov eax,4[esp] ; get p1
|
||||
mov edx,8[esp] ; get p2
|
||||
endif
|
||||
cmp eax,edx ; pointers equal ?
|
||||
je equalnorst ; yes, return 0
|
||||
ifndef __STACK__
|
||||
push ecx ; save register
|
||||
endif
|
||||
test al,3 ; p1 aligned ?
|
||||
jne realign ; no, go and realign
|
||||
test dl,3 ; p2 aligned ?
|
||||
jne slowcpy ; no, do the slow copy (impossible to align both)
|
||||
|
||||
fastcpy:
|
||||
push ebx ; save register
|
||||
|
||||
align 4
|
||||
_loop ; - loop
|
||||
cmp4 0 ; - - compare first dword
|
||||
_quif ne ; - - quit if end of string
|
||||
cmp4 4 ; - - compare second dword
|
||||
_quif ne ; - - quit if end of string
|
||||
cmp4 8 ; - - compare third dword
|
||||
_quif ne ; - - quit if end of string
|
||||
cmp4 12 ; - - compare fourth dword
|
||||
_until ne ; - until end of string
|
||||
equalrst: ; strings equal, restore registers
|
||||
pop ebx ; restore register
|
||||
ifndef __STACK__
|
||||
pop ecx ; ...
|
||||
endif
|
||||
equalnorst: ; strings equal, skip register restore
|
||||
sub eax,eax ; indicate strings equal
|
||||
ifdef _PROFILE
|
||||
P5Epilog
|
||||
endif
|
||||
ret ; return
|
||||
|
||||
unequal: ; dword was not equal
|
||||
_guess ; guess strings are equal
|
||||
cmp bl,cl ; - check low bytes
|
||||
_quif ne ; - quit if not equal
|
||||
cmp bl,0 ; - stop if end of string
|
||||
je equalrst ; - ...
|
||||
cmp bh,ch ; - check next bytes
|
||||
_quif ne ; - quit if not equal
|
||||
cmp bh,0 ; - stop if end of string
|
||||
je equalrst ; - ...
|
||||
shr ebx,16 ; - shift top 2 bytes to bottom
|
||||
shr ecx,16 ; - ...
|
||||
cmp bl,cl ; - check third byte
|
||||
_quif ne ; - quit if not equal
|
||||
cmp bl,0 ; - stop if end of string
|
||||
je equalrst ; - ...
|
||||
cmp bh,ch ; - check high order byte
|
||||
;; we know at this point that bh != ch, just have to do the compare
|
||||
;; _quif ne ; - quit if not equal
|
||||
;; cmp bh,0 ; - stop if end of string
|
||||
;; je equalrst ; - ...
|
||||
_endguess ; endguess
|
||||
sbb eax,eax ; eax = 0 if op1>op2, -1 if op1<op2
|
||||
or al,1 ; eax = 1 if op1>op2, -1 if op1<op2
|
||||
pop ebx ; restore registers
|
||||
ifndef __STACK__
|
||||
pop ecx ; ...
|
||||
endif
|
||||
ifdef _PROFILE
|
||||
P5Epilog
|
||||
endif
|
||||
ret ; return
|
||||
|
||||
align 4
|
||||
realign:
|
||||
_loop ; - loop
|
||||
mov cl,[eax] ; get byte from p1
|
||||
inc eax ; point to next byte
|
||||
mov ch,[edx] ; get byte from p2
|
||||
inc edx ; point to next byte
|
||||
cmp cl,ch ; bytes equal?
|
||||
jne unequal2 ; unequal, quit
|
||||
or cl,cl ; end of string ?
|
||||
je equal2 ; yes, quit
|
||||
test al,3 ; check alignment
|
||||
_until e ; until aligned
|
||||
test dl,3 ; p2 aligned ?
|
||||
je fastcpy ; yes
|
||||
|
||||
align 4
|
||||
slowcpy:
|
||||
_loop
|
||||
mov ecx,[eax] ; get aligned 4 bytes
|
||||
cmp cl,[edx] ; check 1st byte
|
||||
jne unequal2 ; bytes not equal
|
||||
or cl,cl ; end of string?
|
||||
je equal2 ; yes, quit
|
||||
cmp ch,[edx+1] ; check 2nd byte
|
||||
jne unequal2 ; bytes not equal
|
||||
or ch,ch ; end of string?
|
||||
je equal2 ; yes, quit
|
||||
shr ecx,16 ; move next pair of bytes to be tested
|
||||
cmp cl,[edx+2] ; check 3rd byte
|
||||
jne unequal2 ; bytes not equal
|
||||
or cl,cl ; end of string?
|
||||
je equal2 ; yes, quit
|
||||
cmp ch,[edx+3] ; check 4th byte
|
||||
jne unequal2 ; bytes not equal
|
||||
or ch,ch ; end of string?
|
||||
je equal2 ; yes, quit
|
||||
mov ecx,[eax+4] ; get next aligned 4 bytes
|
||||
cmp cl,[edx+4] ; check 5th byte
|
||||
jne unequal2 ; bytes not equal
|
||||
or cl,cl ; end of string?
|
||||
je equal2 ; yes, quit
|
||||
cmp ch,[edx+5] ; check 6th byte
|
||||
jne unequal2 ; bytes not equal
|
||||
or ch,ch ; end of string?
|
||||
je equal2 ; yes, quit
|
||||
shr ecx,16 ; move next pair of bytes to be tested
|
||||
cmp cl,[edx+6] ; check 7th byte
|
||||
jne unequal2 ; bytes not equal
|
||||
or cl,cl ; end of string?
|
||||
je equal2 ; yes, quit
|
||||
cmp ch,[edx+7] ; check 8th byte
|
||||
jne unequal2 ; bytes not equal
|
||||
add eax,8 ; next 8 bytes
|
||||
add edx,8 ; next 8 bytes
|
||||
or ch,ch ; end of string?
|
||||
_until e ; until equal
|
||||
equal2:
|
||||
xor eax,eax ; return 0
|
||||
ifndef __STACK__
|
||||
pop ecx ; restore registers
|
||||
endif
|
||||
ifdef _PROFILE
|
||||
P5Epilog
|
||||
endif
|
||||
ret ; return
|
||||
|
||||
unequal2:
|
||||
sbb eax,eax ; eax = 0 if op1>op2, -1 if op1<op2
|
||||
or al,1 ; eax = 1 if op1>op2, -1 if op1<op2
|
||||
ifndef __STACK__
|
||||
pop ecx ; restore registers
|
||||
endif
|
||||
ifdef _PROFILE
|
||||
P5Epilog
|
||||
endif
|
||||
ret ; return
|
||||
endproc strcmp
|
||||
|
||||
endmod
|
||||
end
|
46
programs/develop/open watcom/trunk/clib/string/errstr.h
Normal file
46
programs/develop/open watcom/trunk/clib/string/errstr.h
Normal file
@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Internal definitions for strerror() and friends.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#if defined(__NETWARE__) || defined(__WIDECHAR__)
|
||||
|
||||
extern int _WCNEAR sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
#define _sys_nerr sys_nerr
|
||||
#define _sys_errlist sys_errlist
|
||||
|
||||
#else
|
||||
|
||||
extern char *_sys_errlist[];
|
||||
extern int _WCNEAR _sys_nerr;
|
||||
|
||||
#endif
|
||||
|
||||
#define UNKNOWN_ERROR "unknown error"
|
45
programs/develop/open watcom/trunk/clib/string/fsetbits.c
Normal file
45
programs/develop/open watcom/trunk/clib/string/fsetbits.c
Normal file
@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
#include "setbits.h"
|
||||
|
||||
void __fsetbits( unsigned char _WCFAR *vector, const char _WCFAR *charset )
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
_fmemset( vector, 0, 32 );
|
||||
for( ; c = *charset; ++charset ) {
|
||||
vector[ c >> 3 ] |= _Bits[ c & 0x07 ];
|
||||
}
|
||||
}
|
51
programs/develop/open watcom/trunk/clib/string/fstrcat.c
Normal file
51
programs/develop/open watcom/trunk/clib/string/fstrcat.c
Normal file
@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "xstring.h"
|
||||
|
||||
#undef _fstrcat
|
||||
/* concatenate t to the end of dst */
|
||||
|
||||
_WCRTLINK char _WCFAR *_fstrcat( char _WCFAR *dst, const char _WCFAR *t )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fstrcat( dst, t ) );
|
||||
#else
|
||||
char _WCFAR *s;
|
||||
s = dst;
|
||||
while( *s != '\0' ) ++s;
|
||||
while( *s++ = *t++ ) ;
|
||||
return( dst );
|
||||
#endif
|
||||
}
|
91
programs/develop/open watcom/trunk/clib/string/fstrchr.c
Normal file
91
programs/develop/open watcom/trunk/clib/string/fstrchr.c
Normal file
@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef M_I86
|
||||
|
||||
extern char _WCFAR * _scan1( char _WCFAR *s, int c );
|
||||
|
||||
/* use scan1 to find the char we are looking for */
|
||||
|
||||
#pragma aux _scan1 = 0x1e /* push ds */\
|
||||
0x8e 0xda /* mov ds,dx */\
|
||||
0xad /* L1:lodsw */\
|
||||
0x38 0xd8 /* cmp al,bl */\
|
||||
0x74 0x22 /* je L3 */\
|
||||
0x84 0xc0 /* test al,al*/\
|
||||
0x74 0x19 /* je L2 */\
|
||||
0x38 0xdc /* cmp ah,bl */\
|
||||
0x74 0x1b /* je L4 */\
|
||||
0x84 0xe4 /* test ah,ah*/\
|
||||
0x74 0x11 /* je L2 */\
|
||||
0xad /* lodsw */\
|
||||
0x38 0xd8 /* cmp al,bl */\
|
||||
0x74 0x11 /* je L3 */\
|
||||
0x84 0xc0 /* test al,al*/\
|
||||
0x74 0x08 /* je L2 */\
|
||||
0x38 0xdc /* cmp ah,bl */\
|
||||
0x74 0x0a /* je L4 */\
|
||||
0x84 0xe4 /* test ah,ah*/\
|
||||
0x75 0xde /* jne L1 */\
|
||||
0x31 0xf6 /* L2:xor si,si*/\
|
||||
0x89 0xf2 /* mov dx,si */\
|
||||
0xa9 /* test ax,... */\
|
||||
0x4e /* L3:dec si */\
|
||||
0x4e /* L4:dec si */\
|
||||
0x1f /* pop ds */\
|
||||
parm caller [dx si] [bl]\
|
||||
value [dx si]\
|
||||
modify [ax dx si];
|
||||
#endif
|
||||
|
||||
|
||||
/* locate the first occurrence of c in the initial n characters of the
|
||||
string pointed to by s. The terminating null character is considered
|
||||
to be part of the string.
|
||||
If the character c is not found, NULL is returned.
|
||||
*/
|
||||
#undef _fstrchr
|
||||
|
||||
_WCRTLINK char _WCFAR *_fstrchr( const char _WCFAR *s, int c )
|
||||
{
|
||||
//#if defined(M_I86)
|
||||
//return( _scan1( (char _WCFAR *)s, c ) );
|
||||
//#else
|
||||
do {
|
||||
if( *s == c ) return( (char _WCFAR *)s );
|
||||
} while( *s++ != '\0' );
|
||||
return( NULL );
|
||||
//#endif
|
||||
}
|
50
programs/develop/open watcom/trunk/clib/string/fstrcmp.c
Normal file
50
programs/develop/open watcom/trunk/clib/string/fstrcmp.c
Normal file
@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "xstring.h"
|
||||
|
||||
#undef _fstrcmp
|
||||
|
||||
/* return <0 if s<t, 0 if s==t, >0 if s>t */
|
||||
|
||||
_WCRTLINK int _fstrcmp( const char _WCFAR *s, const char _WCFAR *t )
|
||||
{
|
||||
#if /*defined(M_I86) &&*/ defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fstrcmp( s, t ) );
|
||||
#else
|
||||
for( ; *s == *t; s++, t++ )
|
||||
if( *s == '\0' )
|
||||
return( 0 );
|
||||
return( *s - *t );
|
||||
#endif
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/string/fstrcpy.c
Normal file
49
programs/develop/open watcom/trunk/clib/string/fstrcpy.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "xstring.h"
|
||||
|
||||
#undef _fstrcpy
|
||||
/* copy string t to string s */
|
||||
|
||||
_WCRTLINK char _WCFAR *_fstrcpy( char _WCFAR *s, const char _WCFAR *t )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fstrcpy( s, t ) );
|
||||
#else
|
||||
char _WCFAR *dst;
|
||||
dst = s;
|
||||
while( *dst++ = *t++ );
|
||||
return( s );
|
||||
#endif
|
||||
}
|
57
programs/develop/open watcom/trunk/clib/string/fstrcspn.c
Normal file
57
programs/develop/open watcom/trunk/clib/string/fstrcspn.c
Normal file
@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "setbits.h"
|
||||
|
||||
/* The strcspn function computes the length of the initial segment of the
|
||||
string pointed to by str which consists entirely of characters not from
|
||||
the string pointed to by charset. The terminating NULL character is not
|
||||
considered part of charset.
|
||||
*/
|
||||
|
||||
_WCRTLINK size_t _fstrcspn( const char _WCFAR *str, const char _WCFAR *charset )
|
||||
{
|
||||
unsigned /*char*/ tc;
|
||||
unsigned char vector[32];
|
||||
size_t len;
|
||||
|
||||
__fsetbits( vector, charset );
|
||||
len = 0;
|
||||
for( ; tc = (unsigned char) *str; ++len, ++str ) {
|
||||
/* quit if we find any char in charset */
|
||||
if( ( vector[ tc >> 3 ] & _Bits[ tc & 0x07 ] ) != 0 ) break;
|
||||
}
|
||||
return( len );
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/string/fstrdup.c
Normal file
49
programs/develop/open watcom/trunk/clib/string/fstrdup.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "liballoc.h"
|
||||
|
||||
_WCRTLINK char _WCFAR *_fstrdup( const char _WCFAR *str )
|
||||
{
|
||||
char _WCFAR *mem;
|
||||
int len;
|
||||
|
||||
len = _fstrlen( str ) + 1;
|
||||
mem = lib_malloc( len );
|
||||
if( mem ) {
|
||||
(_fmemcpy)( mem, str, len );
|
||||
}
|
||||
return( mem );
|
||||
}
|
55
programs/develop/open watcom/trunk/clib/string/fstricmp.c
Normal file
55
programs/develop/open watcom/trunk/clib/string/fstricmp.c
Normal file
@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/* return <0 if s<t, 0 if s==t, >0 if s>t */
|
||||
|
||||
_WCRTLINK int _fstricmp( const char _WCFAR *s, const char _WCFAR *t )
|
||||
{
|
||||
unsigned char c1;
|
||||
unsigned char c2;
|
||||
|
||||
for(;;) {
|
||||
c1 = *s;
|
||||
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
|
||||
c2 = *t;
|
||||
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
|
||||
if( c1 != c2 ) break;
|
||||
if( c1 == '\0' ) break;
|
||||
++s;
|
||||
++t;
|
||||
}
|
||||
return( c1 - c2 );
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user