Standard Libraries for EDK II.

This set of three packages: AppPkg, StdLib, StdLibPrivateInternalFiles; contains the implementation of libraries based upon non-UEFI standards such as ISO/IEC-9899, the library portion of the C Language Standard, POSIX, etc.

AppPkg contains applications that make use of the standard libraries defined in the StdLib Package.

StdLib contains header (include) files and the implementations of the standard libraries.

StdLibPrivateInternalFiles contains files for the exclusive use of the library implementations in StdLib.  These files should never be directly referenced from applications or other code.


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11600 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
darylm503
2011-04-27 21:42:16 +00:00
parent 98790d8148
commit 2aa62f2bc9
503 changed files with 67344 additions and 0 deletions

196
StdLib/LibC/CRT/Gcc.c Normal file
View File

@@ -0,0 +1,196 @@
/** @file
Integer Arithmetic Run-time support functions for GCC.
The integer arithmetic routines are used on platforms that don't provide
hardware support for arithmetic operations on some modes..
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <sys/EfiCdefs.h>
#include <Library/BaseLib.h>
// Shift Datum left by Count bits.
// ===========================================================================
//int __ashlsi3(int Datum, int Count)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);
//}
INT64 __ashldi3(INT64 Datum, int Count)
{
DebugPrint(DEBUG_INFO, "%a:\n", __func__);
return LShiftU64 (Datum, (UINTN)Count);
}
//long long __ashlti3(long long Datum, int Count)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);
//}
// Arithmetically shift Datum right by Count bits.
// ===========================================================================
//int __ashrsi3(int Datum, int Count)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
//}
INT64 __ashrdi3(INT64 Datum, int Count)
{
DebugPrint(DEBUG_INFO, "%a:\n", __func__);
return ARShiftU64 ( Datum, (UINTN)Count);
}
//long long __ashrti3(long long Datum, int Count)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);
//}
// Return the quotient of the signed division of Dividend and Divisor
// ===========================================================================
//int __divsi3(int Dividend, int Divisor)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
//}
INT64 __divdi3(INT64 Dividend, INT64 Divisor)
{
INT64 Quotient;
Quotient = DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
DebugPrint(DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient);
return Quotient;
}
//long long __divti3(long long Dividend, long long Divisor)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);
//}
// Logically shift Datum right by Count bits
// ===========================================================================
//int __lshrsi3(int Datum, int Count)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);
//}
INT64 __lshrdi3(INT64 Datum, int Count)
{
DebugPrint(DEBUG_INFO, "%a:\n", __func__);
return RShiftU64 ( Datum, (UINTN)Count);
}
//long long __lshrti3(int Datum, int Count)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);
//}
// Return the remainder of the signed division of Dividend and Divisor
// ===========================================================================
//int __modsi3(int Dividend, int Divisor)
//{
// INT64 Remainder;
// (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
// DebugPrint(DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder);
// return (int) Remainder;
//}
INT64 __moddi3(INT64 Dividend, INT64 Divisor)
{
INT64 Remainder;
(void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
DebugPrint(DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder);
return Remainder;
}
//long long __modti3(long long Dividend, long long Divisor)
//{
// INT64 Remainder;
// (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);
// DebugPrint(DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder);
// return (long long) Remainder;
//}
// These functions return the product of the Multiplicand and Multiplier.
// ===========================================================================
//long long __multi3(long long Multiplicand, long long Multiplier)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);
//}
// Return the quotient of the unsigned division of a and b.
// ===========================================================================
//unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
//}
UINT64 __udivdi3(UINT64 Dividend, UINT64 Divisor)
{
DebugPrint(DEBUG_INFO, "%a:\n", __func__);
return DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
}
//unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)
//{
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);
//}
// ===========================================================================
//unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)
//{
// UINT64 Remainder;
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
// return (unsigned int) Remainder;
//}
UINT64 __umoddi3(UINT64 Dividend, UINT64 Divisor)
{
UINT64 Remainder;
DebugPrint(DEBUG_INFO, "%a:\n", __func__);
(void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
return Remainder;
}
//unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)
//{
// UINT64 Remainder;
// DebugPrint(DEBUG_INFO, "%a:\n", __func__);
// (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);
// return (unsigned long long) Remainder;
//}

View File

@@ -0,0 +1,66 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# MathRShiftU64.S
#
# Abstract:
#
# 64-bit Math Worker Function.
# Shifts a 64-bit unsigned value right by a certain number of bits.
#
#------------------------------------------------------------------------------
.686:
.code:
ASM_GLOBAL ASM_PFX(__ashrdi3)
#------------------------------------------------------------------------------
#
# void __cdecl __ashrdi3 (void)
#
#------------------------------------------------------------------------------
ASM_PFX(__ashrdi3):
#
# Checking: Only handle 64bit shifting or more
#
cmpb $64, %cl
jae _Exit
#
# Handle shifting between 0 and 31 bits
#
cmpb $32, %cl
jae More32
shrd %cl, %edx, %eax
shr %cl, %edx
ret
#
# Handle shifting of 32-63 bits
#
More32:
movl %edx, %eax
xor %edx, %edx
and $32, %cl
shr %cl, %eax
ret
#
# Invalid number (less then 32bits), return 0
#
_Exit:
xor %eax, %eax
xor %edx, %edx
ret

View File

@@ -0,0 +1,97 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Divides a 64-bit signed value with a 64-bit signed value and returns
* a 64-bit signed result.
*/
__declspec(naked) void __cdecl _alldiv (void)
{
//
// Wrapper Implementation over EDKII DivS64x64Remainder() routine
// INT64
// EFIAPI
// DivS64x64Remainder (
// IN UINT64 Dividend,
// IN UINT64 Divisor,
// OUT UINT64 *Remainder OPTIONAL
// )
//
_asm {
;Entry:
; Arguments are passed on the stack:
; 1st pushed: divisor (QWORD)
; 2nd pushed: dividend (QWORD)
;
;Exit:
; EDX:EAX contains the quotient (dividend/divisor)
; NOTE: this routine removes the parameters from the stack.
;
; Original local stack when calling _alldiv
; -----------------
; | |
; |---------------|
; | |
; |-- Divisor --|
; | |
; |---------------|
; | |
; |-- Dividend --|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; Set up the local stack for NULL Reminder pointer
;
xor eax, eax
push eax
;
; Set up the local stack for Divisor parameter
;
mov eax, [esp + 20]
push eax
mov eax, [esp + 20]
push eax
;
; Set up the local stack for Dividend parameter
;
mov eax, [esp + 20]
push eax
mov eax, [esp + 20]
push eax
;
; Call native DivS64x64Remainder of BaseLib
;
call DivS64x64Remainder
;
; Adjust stack
;
add esp, 20
ret 16
}
}

View File

@@ -0,0 +1,100 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Divides a 64-bit signed value by another 64-bit signed value and returns
* the 64-bit signed result and the 64-bit signed remainder.
*/
__declspec(naked) void __cdecl _alldvrm(void)
{
//
// Wrapper Implementation over EDKII DivS64x64Remainder() routine
// INT64
// EFIAPI
// DivS64x64Remainder (
// IN INT64 Dividend,
// IN INT64 Divisor,
// OUT INT64 *Remainder
// )
//
_asm {
; Original local stack when calling _alldvrm
; -----------------
; | |
; |---------------|
; | |
; |-- Divisor --|
; | |
; |---------------|
; | |
; |-- Dividend --|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; On Exit:
; EDX:EAX contains the quotient (dividend/divisor)
; EBX:ECX contains the remainder (divided % divisor)
; NOTE: this routine removes the parameters from the stack.
;
;
; Set up the local stack for Reminder pointer
;
sub esp, 8
push esp
;
; Set up the local stack for Divisor parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Set up the local stack for Dividend parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Call native DivS64x64Remainder of BaseLib
;
call DivS64x64Remainder
;
; EDX:EAX contains the quotient (dividend/divisor)
; Put the Remainder in EBX:ECX
;
mov ecx, [esp + 20]
mov ebx, [esp + 24]
;
; Adjust stack
;
add esp, 28
ret 16
}
}

View File

@@ -0,0 +1,79 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value
* and returns a 64-bit result.
*/
__declspec(naked) void __cdecl _allmul (void)
{
//
// Wrapper Implementation over EDKII MultS64x64() routine
// INT64
// EFIAPI
// MultS64x64 (
// IN INT64 Multiplicand,
// IN INT64 Multiplier
// )
//
_asm {
; Original local stack when calling _allmul
; -----------------
; | |
; |---------------|
; | |
; |--Multiplier --|
; | |
; |---------------|
; | |
; |--Multiplicand-|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; Set up the local stack for Multiplicand parameter
;
mov eax, [esp + 16]
push eax
mov eax, [esp + 16]
push eax
;
; Set up the local stack for Multiplier parameter
;
mov eax, [esp + 16]
push eax
mov eax, [esp + 16]
push eax
;
; Call native MulS64x64 of BaseLib
;
call MultS64x64
;
; Adjust stack
;
add esp, 16
ret 16
}
}

View File

@@ -0,0 +1,93 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Divides a 64-bit signed value by another 64-bit signed value and returns
* the 64-bit signed remainder.
*/
__declspec(naked) void __cdecl _allrem(void)
{
//
// Wrapper Implementation over EDKII DivS64x64Remainder() routine
// UINT64
// EFIAPI
// DivS64x64Remainder (
// IN UINT64 Dividend,
// IN UINT64 Divisor,
// OUT UINT64 *Remainder
// )
//
_asm {
; Original local stack when calling _allrem
; -----------------
; | |
; |---------------|
; | |
; |-- Divisor --|
; | |
; |---------------|
; | |
; |-- Dividend --|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; Set up the local stack for Reminder pointer
;
sub esp, 8
push esp
;
; Set up the local stack for Divisor parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Set up the local stack for Dividend parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Call native DivS64x64Remainder of BaseLib
;
call DivS64x64Remainder
;
; Put the Reminder in EDX:EAX as return value
;
mov eax, [esp + 20]
mov edx, [esp + 24]
;
; Adjust stack
;
add esp, 28
ret 16
}
}

View File

@@ -0,0 +1,54 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
/*
* Shifts a 64-bit signed value left by a particular number of bits.
*/
__declspec(naked) void __cdecl _allshl (void)
{
_asm {
;
; Handle shifting of 64 or more bits (return 0)
;
cmp cl, 64
jae short ReturnZero
;
; Handle shifting of between 0 and 31 bits
;
cmp cl, 32
jae short More32
shld edx, eax, cl
shl eax, cl
ret
;
; Handle shifting of between 32 and 63 bits
;
More32:
mov edx, eax
xor eax, eax
and cl, 31
shl edx, cl
ret
ReturnZero:
xor eax,eax
xor edx,edx
ret
}
}

View File

@@ -0,0 +1,77 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# MathMultS64x64.S
#
# Abstract:
#
# 64-bit Math Worker Function.
# Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value
# and returns a 64-bit result
#
#------------------------------------------------------------------------------
.686:
.code:
ASM_GLOBAL ASM_PFX(_mulll), ASM_PFX(MultS64x64)
#------------------------------------------------------------------------------
#
# void __cdecl __mulll (void)
#
#------------------------------------------------------------------------------
ASM_PFX(__mulll):
# Original local stack when calling __mulll
# -----------------
# | |
# |---------------|
# | |
# |--Multiplier --|
# | |
# |---------------|
# | |
# |--Multiplicand-|
# | |
# |---------------|
# | ReturnAddr** |
# ESP---->|---------------|
#
#
# Set up the local stack for Multiplicand parameter
#
movl 16(%esp), %eax
push %eax
movl 16(%esp), %eax
push %eax
#
# Set up the local stack for Multiplier parameter
#
movl 16(%esp), %eax
push %eax
movl 16(%esp), %eax
push %eax
#
# Call native MulS64x64 of BaseLib
#
jmp ASM_PFX(MultS64x64)
#
# Adjust stack
#
add $16, %esp
ret $16

View File

@@ -0,0 +1,62 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# MathLShiftS64.S
#
# Abstract:
#
# 64-bit Math Worker Function.
# Shifts a 64-bit signed value left by a certain number of bits.
#
#------------------------------------------------------------------------------
.686:
.code:
ASM_GLOBAL ASM_PFX(__ashldi3)
#------------------------------------------------------------------------------
#
# void __cdecl __ashldi3 (void)
#
#------------------------------------------------------------------------------
ASM_PFX(__ashldi3):
#
# Handle shifting of 64 or more bits (return 0)
#
cmpb $64, %cl
jae ReturnZero
#
# Handle shifting of between 0 and 31 bits
#
cmpb $32, %cl
jae More32
shld %cl, %eax, %edx
shl %cl, %eax
ret
#
# Handle shifting of between 32 and 63 bits
#
More32:
movl %eax, %edx
xor %eax, %eax
and $31, %cl
shl %cl, %edx
ret
ReturnZero:
xor %eax, %eax
xor %edx, %edx
ret

View File

@@ -0,0 +1,83 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# MathDivU64x64.S
#
# Abstract:
#
# 64-bit Math Worker Function.
# Divides a 64-bit unsigned value with a 64-bit unsigned value and returns
# a 64-bit unsigned result.
#
#------------------------------------------------------------------------------
.686:
.code:
ASM_GLOBAL ASM_PFX(__udivdi3), ASM_PFX(DivU64x64Remainder)
#------------------------------------------------------------------------------
#
# void __cdecl __udivdi3 (void)
#
#------------------------------------------------------------------------------
ASM_PFX(__udivdi3):
# Original local stack when calling __udivdi3
# -----------------
# | |
# |---------------|
# | |
# |-- Divisor --|
# | |
# |---------------|
# | |
# |-- Dividend --|
# | |
# |---------------|
# | ReturnAddr** |
# ESP---->|---------------|
#
#
# Set up the local stack for NULL Reminder pointer
#
xorl %eax, %eax
push %eax
#
# Set up the local stack for Divisor parameter
#
movl 20(%esp), %eax
push %eax
movl 20(%esp), %eax
push %eax
#
# Set up the local stack for Dividend parameter
#
movl 20(%esp), %eax
push %eax
movl 20(%esp), %eax
push %eax
#
# Call native DivU64x64Remainder of BaseLib
#
jmp ASM_PFX(DivU64x64Remainder)
#
# Adjust stack
#
addl $20, %esp
ret $16

View File

@@ -0,0 +1,88 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Divides a 64-bit unsigned value with a 64-bit unsigned value and returns
* a 64-bit unsigned result.
*/
__declspec(naked) void __cdecl _aulldiv (void)
{
//
// Wrapper Implementation over EDKII DivU64x64Reminder() routine
// UINT64
// EFIAPI
// DivU64x64Remainder (
// IN UINT64 Dividend,
// IN UINT64 Divisor,
// OUT UINT64 *Remainder OPTIONAL
// )
//
_asm {
; Original local stack when calling _aulldiv
; -----------------
; | |
; |---------------|
; | |
; |-- Divisor --|
; | |
; |---------------|
; | |
; |-- Dividend --|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; Set up the local stack for NULL Reminder pointer
;
xor eax, eax
push eax
;
; Set up the local stack for Divisor parameter
;
mov eax, [esp + 20]
push eax
mov eax, [esp + 20]
push eax
;
; Set up the local stack for Dividend parameter
;
mov eax, [esp + 20]
push eax
mov eax, [esp + 20]
push eax
;
; Call native DivU64x64Remainder of BaseLib
;
call DivU64x64Remainder
;
; Adjust stack
;
add esp, 20
ret 16
}
}

View File

@@ -0,0 +1,100 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Divides a 64-bit signed value by another 64-bit signed value and returns
* the 64-bit signed result and the 64-bit signed remainder.
*/
__declspec(naked) void __cdecl _aulldvrm(void)
{
//
// Wrapper Implementation over EDKII DivU64x64Remainder() routine
// UINT64
// EFIAPI
// DivU64x64Remainder (
// IN UINT64 Dividend,
// IN UINT64 Divisor,
// OUT UINT64 *Remainder
// )
//
_asm {
; Original local stack when calling _aulldvrm
; -----------------
; | |
; |---------------|
; | |
; |-- Divisor --|
; | |
; |---------------|
; | |
; |-- Dividend --|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; On Exit:
; EDX:EAX contains the quotient (dividend/divisor)
; EBX:ECX contains the remainder (divided % divisor)
; NOTE: this routine removes the parameters from the stack.
;
;
; Set up the local stack for Remainder pointer
;
sub esp, 8
push esp
;
; Set up the local stack for Divisor parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Set up the local stack for Dividend parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Call native DivU64x64Remainder of BaseLib
;
call DivU64x64Remainder
;
; EDX:EAX contains the quotient (dividend/divisor)
; Put the Remainder in EBX:ECX
;
mov ecx, [esp + 20]
mov ebx, [esp + 24]
;
; Adjust stack
;
add esp, 28
ret 16
}
}

View File

@@ -0,0 +1,93 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
* the 64-bit unsigned remainder.
*/
__declspec(naked) void __cdecl _aullrem(void)
{
//
// Wrapper Implementation over EDKII DivU64x64Remainder() routine
// UINT64
// EFIAPI
// DivU64x64Remainder (
// IN UINT64 Dividend,
// IN UINT64 Divisor,
// OUT UINT64 *Remainder OPTIONAL
// )
//
_asm {
; Original local stack when calling _aullrem
; -----------------
; | |
; |---------------|
; | |
; |-- Divisor --|
; | |
; |---------------|
; | |
; |-- Dividend --|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; Set up the local stack for Reminder pointer
;
sub esp, 8
push esp
;
; Set up the local stack for Divisor parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Set up the local stack for Dividend parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Call native DivU64x64Remainder of BaseLib
;
call DivU64x64Remainder
;
; Put the Reminder in EDX:EAX as return value
;
mov eax, [esp + 20]
mov edx, [esp + 24]
;
; Adjust stack
;
add esp, 28
ret 16
}
}

View File

@@ -0,0 +1,57 @@
/** @file
64-bit Math Worker Function.
The 32-bit versions of C compiler generate calls to library routines
to handle 64-bit math. These functions use non-standard calling conventions.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
/*
* Shifts a 64-bit unsigned value right by a certain number of bits.
*/
__declspec(naked) void __cdecl _aullshr (void)
{
_asm {
;
; Checking: Only handle 64bit shifting or more
;
cmp cl, 64
jae _Exit
;
; Handle shifting between 0 and 31 bits
;
cmp cl, 32
jae More32
shrd eax, edx, cl
shr edx, cl
ret
;
; Handle shifting of 32-63 bits
;
More32:
mov eax, edx
xor edx, edx
and cl, 31
shr eax, cl
ret
;
; Invalid number (less then 32bits), return 0
;
_Exit:
xor eax, eax
xor edx, edx
ret
}
}

View File

@@ -0,0 +1,89 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# MathReminderU64x64.S
#
# Abstract:
#
# 64-bit Math Worker Function.
# Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
# the 64-bit unsigned remainder
#
#------------------------------------------------------------------------------
.686:
.code:
ASM_GLOBAL ASM_PFX(__umoddi3), ASM_PFX(DivU64x64Remainder)
#------------------------------------------------------------------------------
#
# void __cdecl __umoddi3 (void)
#
#------------------------------------------------------------------------------
ASM_PFX(__umoddi3):
# Original local stack when calling __umoddi3
# -----------------
# | |
# |---------------|
# | |
# |-- Divisor --|
# | |
# |---------------|
# | |
# |-- Dividend --|
# | |
# |---------------|
# | ReturnAddr** |
# ESP---->|---------------|
#
#
# Set up the local stack for Reminder pointer
#
sub $8, %esp
push %esp
#
# Set up the local stack for Divisor parameter
#
movl 28(%esp), %eax
push %eax
movl 28(%esp), %eax
push %eax
#
# Set up the local stack for Dividend parameter
#
movl 28(%esp), %eax
push %eax
movl 28(%esp), %eax
push %eax
#
# Call native DivU64x64Remainder of BaseLib
#
jmp ASM_PFX(DivU64x64Remainder)
#
# Put the Reminder in EDX:EAX as return value
#
movl 20(%esp), %eax
movl 24(%esp), %edx
#
# Adjust stack
#
add $28, %esp
ret $16

140
StdLib/LibC/Ctype/CClass.c Normal file
View File

@@ -0,0 +1,140 @@
/** @file
Character classification and case conversion functions for <ctype.h>.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <LibConfig.h>
#define NO_CTYPE_MACROS // So that we don't define the classification macros
#include <ctype.h>
int
__isCClass( int _c, unsigned int mask)
{
return ((_c < 0 || _c > 127) ? 0 : (_cClass[_c] & mask));
}
/**
@return
**/
int isalnum(int c)
{
return (__isCClass( c, (_CD | _CU | _CL | _XA)));
}
/**
@return
**/
int isalpha(int c)
{
return (__isCClass( c, (_CU | _CL | _XA)));
}
/**
@return
**/
int iscntrl(int c)
{
return (__isCClass( c, (_CC)));
}
/**
@return
**/
int isdigit(int c)
{
return (__isCClass( c, (_CD)));
}
/**
@return
**/
int isgraph(int c)
{
return (__isCClass( c, (_CG)));
}
/**
@return
**/
int islower(int c)
{
return (__isCClass( c, (_CL)));
}
/**
@return
**/
int isprint(int c)
{
return (__isCClass( c, (_CS | _CG)));
}
/**
@return
**/
int ispunct(int c)
{
return (__isCClass( c, (_CP)));
}
/**
@return
**/
int isspace(int c)
{
return (__isCClass( c, (_CW)));
}
/**
@return
**/
int isupper(int c)
{
return (__isCClass( c, (_CU)));
}
/**
@return
**/
int isxdigit(int c)
{
return (__isCClass( c, (_CD | _CX)));
}
#if defined(_NETBSD_SOURCE)
int
isblank(int c)
{
return (__isCClass( c, _CB));
}
#endif
/** The isascii function tests that a character is one of the 128 ASCII characters.
@param[in] c The character to test.
@return Returns nonzero (true) if c is a valid ASCII character. Otherwize,
zero (false) is returned.
**/
int isascii(int c){
return ((c >= 0) && (c < 128));
}

48
StdLib/LibC/Ctype/CConv.c Normal file
View File

@@ -0,0 +1,48 @@
/** @file
Case conversion functions for <ctype.h>
The tolower function converts an uppercase letter to a corresponding
lowercase letter. If the argument is a character for which isupper
is true and there are one or more corresponding characters, as
specified by the current locale, for which islower is true, the tolower
function returns one of the corresponding characters (always the same one
for any given locale); otherwise, the argument is returned unchanged.
The toupper function converts a lowercase letter to a corresponding
uppercase letter. If the argument is a character for which islower is true
and there are one or more corresponding characters, as specified by the
current locale, for which isupper is true, the toupper function returns one
of the corresponding characters (always the same one for any given locale);
otherwise, the argument is returned unchanged.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <LibConfig.h>
#define NO_CTYPE_MACROS // So that we don't define the classification macros
#include <ctype.h>
int
tolower(
int _c
)
{
// return ((_c < 0 || _c > 127) ? _c : _lConvT[_c]);
return (isupper(_c) ? _lConvT[_c] : _c);
}
int toupper(
int _c
)
{
// return ((_c < 0 || _c > 127) ? _c : _uConvT[_c]);
return (islower(_c) ? _uConvT[_c] : _c);
}

View File

@@ -0,0 +1,50 @@
## @file
#
# Character Classification library implementing the functionality described
# by the <ctype.h> header of the C Standard Library, ISO/IEC 9899:1990 with
# Amendment 1 (C95).
#
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THIS PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = LibCtype
FILE_GUID = dcc64575-fa7d-4b7b-b1ad-48427c97c74d
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = LibCtype
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF
#
[Sources]
iCtype.c
CClass.c
CConv.c
[Packages]
StdLib/StdLib.dec
StdLibPrivateInternalFiles/DoNotUse.dec
MdePkg/MdePkg.dec
################################################################
#
# The Build Options, below, are only used when building the C library.
# DO NOT use them when building your application!
# Nasty things could happen if you do.
#
[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /GL-

303
StdLib/LibC/Ctype/iCtype.c Normal file
View File

@@ -0,0 +1,303 @@
/** @file
Character classification and case conversion tables, and functions,
for the C Standard Library as required to implement ctype.h.
These are the default, C locale, tables.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <LibConfig.h>
#include <ctype.h>
/// ASCII-8 Character Classification Table
const UINT16 _C_CharClassTable[128] = {
/* 00 NUL */ ( _CC ),
/* 01 SOH */ ( _CC ),
/* 02 STX */ ( _CC ),
/* 03 ETX */ ( _CC ),
/* 04 EOT */ ( _CC ),
/* 05 ENQ */ ( _CC ),
/* 06 ACK */ ( _CC ),
/* 07 BEL */ ( _CC ),
/* 08 BS */ ( _CC ),
/* 09 TAB */ ( _CC | _CW | _CB ),
/* 0A LF */ ( _CC | _CW ),
/* 0B VT */ ( _CC | _CW ),
/* 0C FF */ ( _CC | _CW ),
/* 0D CR */ ( _CC | _CW ),
/* 0E SO */ ( _CC ),
/* 0F SI */ ( _CC ),
/* 10 DLE */ ( _CC ),
/* 11 DC1 */ ( _CC ),
/* 12 DC2 */ ( _CC ),
/* 13 DC3 */ ( _CC ),
/* 14 DC4 */ ( _CC ),
/* 15 NAK */ ( _CC ),
/* 16 SYN */ ( _CC ),
/* 17 ETB */ ( _CC ),
/* 18 CAN */ ( _CC ),
/* 19 EM */ ( _CC ),
/* 1A SUB */ ( _CC ),
/* 1B ESC */ ( _CC ),
/* 1C FS */ ( _CC ),
/* 1D GS */ ( _CC ),
/* 1E RS */ ( _CC ),
/* 1F US */ ( _CC ),
/* 20 ' ' */ ( _CW | _CS | _CB ),
/* 21 '!' */ ( _CP | _CG ),
/* 22 '"' */ ( _CP | _CG ),
/* 23 '#' */ ( _CP | _CG ),
/* 24 '$' */ ( _CP | _CG ),
/* 25 '%' */ ( _CP | _CG ),
/* 26 '&' */ ( _CP | _CG ),
/* 27 '\''*/ ( _CP | _CG ),
/* 28 '(' */ ( _CP | _CG ),
/* 29 ')' */ ( _CP | _CG ),
/* 2A '*' */ ( _CP | _CG ),
/* 2B '+' */ ( _CP | _CG ),
/* 2C ',' */ ( _CP | _CG ),
/* 2D '-' */ ( _CP | _CG ),
/* 2E '.' */ ( _CP | _CG ),
/* 2F '/' */ ( _CP | _CG ),
/* 30 '0' */ ( _CD | _CG ),
/* 31 '1' */ ( _CD | _CG ),
/* 32 '2' */ ( _CD | _CG ),
/* 33 '3' */ ( _CD | _CG ),
/* 34 '4' */ ( _CD | _CG ),
/* 35 '5' */ ( _CD | _CG ),
/* 36 '6' */ ( _CD | _CG ),
/* 37 '7' */ ( _CD | _CG ),
/* 38 '8' */ ( _CD | _CG ),
/* 39 '9' */ ( _CD | _CG ),
/* 3A ':' */ ( _CP | _CG ),
/* 3B ';' */ ( _CP | _CG ),
/* 3C '<' */ ( _CP | _CG ),
/* 3D '=' */ ( _CP | _CG ),
/* 3E '>' */ ( _CP | _CG ),
/* 3F '?' */ ( _CP | _CG ),
/* 40 '@' */ ( _CP | _CG ),
/* 41 'A' */ ( _CU | _CX | _CG ),
/* 42 'B' */ ( _CU | _CX | _CG ),
/* 43 'C' */ ( _CU | _CX | _CG ),
/* 44 'D' */ ( _CU | _CX | _CG ),
/* 45 'E' */ ( _CU | _CX | _CG ),
/* 46 'F' */ ( _CU | _CX | _CG ),
/* 47 'G' */ ( _CU | _CG ),
/* 48 'H' */ ( _CU | _CG ),
/* 49 'I' */ ( _CU | _CG ),
/* 4A 'J' */ ( _CU | _CG ),
/* 4B 'K' */ ( _CU | _CG ),
/* 4C 'L' */ ( _CU | _CG ),
/* 4D 'M' */ ( _CU | _CG ),
/* 4E 'N' */ ( _CU | _CG ),
/* 4F 'O' */ ( _CU | _CG ),
/* 50 'P' */ ( _CU | _CG ),
/* 51 'Q' */ ( _CU | _CG ),
/* 52 'R' */ ( _CU | _CG ),
/* 53 'S' */ ( _CU | _CG ),
/* 54 'T' */ ( _CU | _CG ),
/* 55 'U' */ ( _CU | _CG ),
/* 56 'V' */ ( _CU | _CG ),
/* 57 'W' */ ( _CU | _CG ),
/* 58 'X' */ ( _CU | _CG ),
/* 59 'Y' */ ( _CU | _CG ),
/* 5A 'Z' */ ( _CU | _CG ),
/* 5B '[' */ ( _CP | _CG ),
/* 5C '\' */ ( _CP | _CG ),
/* 5D ']' */ ( _CP | _CG ),
/* 5E '^' */ ( _CP | _CG ),
/* 5F '_' */ ( _CP | _CG ),
/* 60 '`' */ ( _CP | _CG ),
/* 61 'a' */ ( _CL | _CX | _CG ),
/* 62 'b' */ ( _CL | _CX | _CG ),
/* 63 'c' */ ( _CL | _CX | _CG ),
/* 64 'd' */ ( _CL | _CX | _CG ),
/* 65 'e' */ ( _CL | _CX | _CG ),
/* 66 'f' */ ( _CL | _CX | _CG ),
/* 67 'g' */ ( _CL | _CG ),
/* 68 'h' */ ( _CL | _CG ),
/* 69 'i' */ ( _CL | _CG ),
/* 6A 'j' */ ( _CL | _CG ),
/* 6B 'k' */ ( _CL | _CG ),
/* 6C 'l' */ ( _CL | _CG ),
/* 6D 'm' */ ( _CL | _CG ),
/* 6E 'n' */ ( _CL | _CG ),
/* 6F 'o' */ ( _CL | _CG ),
/* 70 'p' */ ( _CL | _CG ),
/* 71 'q' */ ( _CL | _CG ),
/* 72 'r' */ ( _CL | _CG ),
/* 73 's' */ ( _CL | _CG ),
/* 74 't' */ ( _CL | _CG ),
/* 75 'u' */ ( _CL | _CG ),
/* 76 'v' */ ( _CL | _CG ),
/* 77 'w' */ ( _CL | _CG ),
/* 78 'x' */ ( _CL | _CG ),
/* 79 'y' */ ( _CL | _CG ),
/* 7A 'z' */ ( _CL | _CG ),
/* 7B '{' */ ( _CP | _CG ),
/* 7C '|' */ ( _CP | _CG ),
/* 7D '}' */ ( _CP | _CG ),
/* 7E '~' */ ( _CP | _CG ),
/* 7F DEL */ ( _CC )
};
/// ASCII-8 Upper case to Lower case character conversion table
const UINT8 _C_ToLowerTable[128] = {
/* 00 NUL */ 0x00, /* 01 SOH */ 0x01,
/* 02 STX */ 0x02, /* 03 ETX */ 0x03,
/* 04 EOT */ 0x04, /* 05 ENQ */ 0x05,
/* 06 ACK */ 0x06, /* 07 BEL */ 0x07,
/* 08 BS */ 0x08, /* 09 TAB */ 0x09,
/* 0A LF */ 0x0A, /* 0B VT */ 0x0B,
/* 0C FF */ 0x0C, /* 0D CR */ 0x0D,
/* 0E SO */ 0x0E, /* 0F SI */ 0x0F,
/* 10 DLE */ 0x10, /* 11 DC1 */ 0x11,
/* 12 DC2 */ 0x12, /* 13 DC3 */ 0x13,
/* 14 DC4 */ 0x14, /* 15 NAK */ 0x15,
/* 16 SYN */ 0x16, /* 17 ETB */ 0x17,
/* 18 CAN */ 0x18, /* 19 EM */ 0x19,
/* 1A SUB */ 0x1A, /* 1B ESC */ 0x1B,
/* 1C FS */ 0x1C, /* 1D GS */ 0x1D,
/* 1E RS */ 0x1E, /* 1F US */ 0x1F,
/* 20 ' ' */ 0x20, /* 21 '!' */ 0x21,
/* 22 '"' */ 0x22, /* 23 '#' */ 0x23,
/* 24 '$' */ 0x24, /* 25 '%' */ 0x25,
/* 26 '&' */ 0x26, /* 27 '\''*/ 0x27,
/* 28 '(' */ 0x28, /* 29 ')' */ 0x29,
/* 2A '*' */ 0x2A, /* 2B '+' */ 0x2B,
/* 2C ',' */ 0x2C, /* 2D '-' */ 0x2D,
/* 2E '.' */ 0x2E, /* 2F '/' */ 0x2F,
/* 30 '0' */ 0x30, /* 31 '1' */ 0x31,
/* 32 '2' */ 0x32, /* 33 '3' */ 0x33,
/* 34 '4' */ 0x34, /* 35 '5' */ 0x35,
/* 36 '6' */ 0x36, /* 37 '7' */ 0x37,
/* 38 '8' */ 0x38, /* 39 '9' */ 0x39,
/* 3A ':' */ 0x3A, /* 3B ';' */ 0x3B,
/* 3C '<' */ 0x3C, /* 3D '=' */ 0x3D,
/* 3E '>' */ 0x3E, /* 3F '?' */ 0x3F,
/* 40 '@' */ 0x40, /* 41 'A' */ 0x61,
/* 42 'B' */ 0x62, /* 43 'C' */ 0x63,
/* 44 'D' */ 0x64, /* 45 'E' */ 0x65,
/* 46 'F' */ 0x66, /* 47 'G' */ 0x67,
/* 48 'H' */ 0x68, /* 49 'I' */ 0x69,
/* 4A 'J' */ 0x6A, /* 4B 'K' */ 0x6B,
/* 4C 'L' */ 0x6C, /* 4D 'M' */ 0x6D,
/* 4E 'N' */ 0x6E, /* 4F 'O' */ 0x6F,
/* 50 'P' */ 0x70, /* 51 'Q' */ 0x71,
/* 52 'R' */ 0x72, /* 53 'S' */ 0x73,
/* 54 'T' */ 0x74, /* 55 'U' */ 0x75,
/* 56 'V' */ 0x76, /* 57 'W' */ 0x77,
/* 58 'X' */ 0x78, /* 59 'Y' */ 0x79,
/* 5A 'Z' */ 0x7A, /* 5B '[' */ 0x5B,
/* 5C '\' */ 0x5C, /* 5D ']' */ 0x5D,
/* 5E '^' */ 0x5E, /* 5F '_' */ 0x5F,
/* 60 '`' */ 0x60, /* 61 'a' */ 0x61,
/* 62 'b' */ 0x62, /* 63 'c' */ 0x63,
/* 64 'd' */ 0x64, /* 65 'e' */ 0x65,
/* 66 'f' */ 0x66, /* 67 'g' */ 0x67,
/* 68 'h' */ 0x68, /* 69 'i' */ 0x69,
/* 6A 'j' */ 0x6A, /* 6B 'k' */ 0x6B,
/* 6C 'l' */ 0x6C, /* 6D 'm' */ 0x6D,
/* 6E 'n' */ 0x6E, /* 6F 'o' */ 0x6F,
/* 70 'p' */ 0x70, /* 71 'q' */ 0x71,
/* 72 'r' */ 0x72, /* 73 's' */ 0x73,
/* 74 't' */ 0x74, /* 75 'u' */ 0x75,
/* 76 'v' */ 0x76, /* 77 'w' */ 0x77,
/* 78 'x' */ 0x78, /* 79 'y' */ 0x79,
/* 7A 'z' */ 0x7A, /* 7B '{' */ 0x7B,
/* 7C '|' */ 0x7C, /* 7D '}' */ 0x7D,
/* 7E '~' */ 0x7E, /* 7F DEL */ 0x7F
};
/// ASCII-8 Lower case to Upper case character conversion table
const UINT8 _C_ToUpperTable[128] = {
/* 00 NUL */ 0x00, /* 01 SOH */ 0x01,
/* 02 STX */ 0x02, /* 03 ETX */ 0x03,
/* 04 EOT */ 0x04, /* 05 ENQ */ 0x05,
/* 06 ACK */ 0x06, /* 07 BEL */ 0x07,
/* 08 BS */ 0x08, /* 09 TAB */ 0x09,
/* 0A LF */ 0x0A, /* 0B VT */ 0x0B,
/* 0C FF */ 0x0C, /* 0D CR */ 0x0D,
/* 0E SO */ 0x0E, /* 0F SI */ 0x0F,
/* 10 DLE */ 0x10, /* 11 DC1 */ 0x11,
/* 12 DC2 */ 0x12, /* 13 DC3 */ 0x13,
/* 14 DC4 */ 0x14, /* 15 NAK */ 0x15,
/* 16 SYN */ 0x16, /* 17 ETB */ 0x17,
/* 18 CAN */ 0x18, /* 19 EM */ 0x19,
/* 1A SUB */ 0x1A, /* 1B ESC */ 0x1B,
/* 1C FS */ 0x1C, /* 1D GS */ 0x1D,
/* 1E RS */ 0x1E, /* 1F US */ 0x1F,
/* 20 ' ' */ 0x20, /* 21 '!' */ 0x21,
/* 22 '"' */ 0x22, /* 23 '#' */ 0x23,
/* 24 '$' */ 0x24, /* 25 '%' */ 0x25,
/* 26 '&' */ 0x26, /* 27 '\''*/ 0x27,
/* 28 '(' */ 0x28, /* 29 ')' */ 0x29,
/* 2A '*' */ 0x2A, /* 2B '+' */ 0x2B,
/* 2C ',' */ 0x2C, /* 2D '-' */ 0x2D,
/* 2E '.' */ 0x2E, /* 2F '/' */ 0x2F,
/* 30 '0' */ 0x30, /* 31 '1' */ 0x31,
/* 32 '2' */ 0x32, /* 33 '3' */ 0x33,
/* 34 '4' */ 0x34, /* 35 '5' */ 0x35,
/* 36 '6' */ 0x36, /* 37 '7' */ 0x37,
/* 38 '8' */ 0x38, /* 39 '9' */ 0x39,
/* 3A ':' */ 0x3A, /* 3B ';' */ 0x3B,
/* 3C '<' */ 0x3C, /* 3D '=' */ 0x3D,
/* 3E '>' */ 0x3E, /* 3F '?' */ 0x3F,
/* 40 '@' */ 0x40, /* 41 'A' */ 0x41,
/* 42 'B' */ 0x42, /* 43 'C' */ 0x43,
/* 44 'D' */ 0x44, /* 45 'E' */ 0x45,
/* 46 'F' */ 0x46, /* 47 'G' */ 0x47,
/* 48 'H' */ 0x48, /* 49 'I' */ 0x49,
/* 4A 'J' */ 0x4A, /* 4B 'K' */ 0x4B,
/* 4C 'L' */ 0x4C, /* 4D 'M' */ 0x4D,
/* 4E 'N' */ 0x4E, /* 4F 'O' */ 0x4F,
/* 50 'P' */ 0x50, /* 51 'Q' */ 0x51,
/* 52 'R' */ 0x52, /* 53 'S' */ 0x53,
/* 54 'T' */ 0x54, /* 55 'U' */ 0x55,
/* 56 'V' */ 0x56, /* 57 'W' */ 0x57,
/* 58 'X' */ 0x58, /* 59 'Y' */ 0x59,
/* 5A 'Z' */ 0x5A, /* 5B '[' */ 0x5B,
/* 5C '\' */ 0x5C, /* 5D ']' */ 0x5D,
/* 5E '^' */ 0x5E, /* 5F '_' */ 0x5F,
/* 60 '`' */ 0x60, /* 61 'a' */ 0x41,
/* 62 'b' */ 0x42, /* 63 'c' */ 0x43,
/* 64 'd' */ 0x44, /* 65 'e' */ 0x45,
/* 66 'f' */ 0x46, /* 67 'g' */ 0x47,
/* 68 'h' */ 0x48, /* 69 'i' */ 0x49,
/* 6A 'j' */ 0x4A, /* 6B 'k' */ 0x4B,
/* 6C 'l' */ 0x4C, /* 6D 'm' */ 0x4D,
/* 6E 'n' */ 0x4E, /* 6F 'o' */ 0x4F,
/* 70 'p' */ 0x50, /* 71 'q' */ 0x51,
/* 72 'r' */ 0x52, /* 73 's' */ 0x53,
/* 74 't' */ 0x54, /* 75 'u' */ 0x55,
/* 76 'v' */ 0x56, /* 77 'w' */ 0x57,
/* 78 'x' */ 0x58, /* 79 'y' */ 0x59,
/* 7A 'z' */ 0x5A, /* 7B '{' */ 0x7B,
/* 7C '|' */ 0x7C, /* 7D '}' */ 0x7D,
/* 7E '~' */ 0x7E, /* 7F DEL */ 0x7F
};
/// Default character classification table is 8-bit ASCII
const UINT16 *_cClass = _C_CharClassTable;
/// Default upper to lower conversion table is 8-bit ASCII
const UINT8 *_lConvT = _C_ToLowerTable;
/// Default lower to upper conversion table is 8-bit ASCII
const UINT8 *_uConvT = _C_ToUpperTable;
void
__set_C_locale( void )
{
_cClass = _C_CharClassTable;
_lConvT = _C_ToLowerTable;
_uConvT = _C_ToUpperTable;
}

115
StdLib/LibC/LibC.inf Normal file
View File

@@ -0,0 +1,115 @@
## @file
# Standard C library: Miscelaneous implementations.
#
# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = LibC
FILE_GUID = 695bec93-82ae-4c17-bdad-7f184f4e651d
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = LibC
#
# VALID_ARCHITECTURES = IA32 X64 IPF
#
[Sources]
Main/errno.c
Main/assert.c
Main/isinfd_ieee754.c
Main/isinff_ieee754.c
Main/isnand_ieee754.c
Main/isnanf_ieee754.c
Main/infinityf_ieee754.c
Main/Main.c
Main/HtoNtoH.c
Main/ByteSwap.c
Main/longjmp.c
[Sources.IA32]
Main/x86flt_rounds.c
Main/Ia32/fpu_rmode.asm | MSFT
Main/Ia32/fpu_rmode.asm | INTEL
Main/Ia32/fpu_rmode.S | GCC
Main/Ia32/isinfl.c
Main/Ia32/isnanl.c
# Compiler helper (C RunTime) functions
CRT/Ia32/llmul.c | MSFT # __allmul
CRT/Ia32/llshl.c | MSFT # __allshl
CRT/Ia32/ulldiv.c | MSFT # __aulldiv
CRT/Ia32/ullrem.c | MSFT # __aullrem
CRT/Ia32/ullshr.c | MSFT # __aullshr
CRT/Ia32/lldiv.c | MSFT # __alldiv
CRT/Ia32/llrem.c | MSFT # __allrem
CRT/Ia32/lldvrm.c | MSFT # __alldvrm
CRT/Ia32/ulldvrm.c | MSFT # __aulldvrm
CRT/Ia32/llmul.c | INTEL
CRT/Ia32/llshl.c | INTEL
CRT/Ia32/ulldiv.c | INTEL
CRT/Ia32/ullrem.c | INTEL
CRT/Ia32/ullshr.c | INTEL
CRT/Ia32/lldiv.c | INTEL
CRT/Ia32/llrem.c | INTEL
CRT/Ia32/lldvrm.c | INTEL
CRT/Ia32/ulldvrm.c | INTEL
CRT/Gcc.c | GCC
[Sources.X64]
Main/x86flt_rounds.c
Main/X64/fpu_rmode.asm | MSFT
Main/X64/fpu_rmode.asm | INTEL
Main/X64/fpu_rmode.S | GCC
Main/X64/isinfl.c
Main/X64/isnanl.c
[Sources.IPF]
Main/x86flt_rounds.c
Main/Ipf/FpuRmode.s
[Sources.ARM]
Main/Arm/flt_rounds.c
[Binaries.IA32]
LIB|Main/Ia32/ftol2.obj|*|MSFT
[Packages]
StdLib/StdLib.dec
StdLibPrivateInternalFiles/DoNotUse.dec
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
[LibraryClasses]
ShellCEntryLib
UefiLib
BaseLib
BaseMemoryLib
MemoryAllocationLib
TimerLib
LibStdLib
LibStdio
LibString
################################################################
#
# The Build Options, below, are only used when building the C library.
# DO NOT use them when building your application!
# Nasty things could happen if you do.
#
[BuildOptions]
MSFT:*_*_IA32_CC_FLAGS = /GL-

View File

@@ -0,0 +1,74 @@
## @file
# Standard C library: Locale implementation.
#
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = LibLocale
FILE_GUID = 9205cde5-5ae5-4a4b-bfbf-f6211967eef9
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = LibLocale
#
# VALID_ARCHITECTURES = IA32 X64 IPF
#
[Sources]
__mb_cur_max.c #
_def_messages.c #
_def_monetary.c #
_def_numeric.c #
_def_time.c #
aliasname.c #
ctypeio.c #
localeconv.c #
nl_langinfo.c #
setlocale1.c #
setlocale32.c #
setlocale.c #
wcscoll.c #
wcsftime.c #
wcstoimax.c #
wcstol.c #
wcstoll.c #
wcstoul.c #
wcstoull.c #
wcstoumax.c #
wcstod.c #
wcstof.c #
wcstold.c #
wcsxfrm.c #
# Single-byte locale to avoid bringing in citrus
iswctype_sb.c #
multibyte_sb.c #
[Packages]
StdLib/StdLib.dec
StdLibPrivateInternalFiles/DoNotUse.dec
MdePkg/MdePkg.dec
[LibraryClasses]
LibC
LibCType
################################################################
#
# The Build Options, below, are only used when building the C library.
# DO NOT use them when building your application!
# Nasty things could happen if you do.
#
[BuildOptions]
GCC:*_*_*_CC_FLAGS = -fno-builtin

View File

@@ -0,0 +1,39 @@
/* $NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <limits.h>
size_t __mb_cur_max = 1;
size_t __mb_len_max_runtime = MB_LEN_MAX;

View File

@@ -0,0 +1,79 @@
/* $NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp $ */
/*-
* Copyright (c)2001 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp $
*/
__inline static int
__wctoint(wchar_t wc)
{
int n;
/* XXX I expect compiler to optimize this. :D */
switch (wc) {
case L'0': n = 0; break;
case L'1': n = 1; break;
case L'2': n = 2; break;
case L'3': n = 3; break;
case L'4': n = 4; break;
case L'5': n = 5; break;
case L'6': n = 6; break;
case L'7': n = 7; break;
case L'8': n = 8; break;
case L'9': n = 9; break;
case L'A': case L'a': n = 10; break;
case L'B': case L'b': n = 11; break;
case L'C': case L'c': n = 12; break;
case L'D': case L'd': n = 13; break;
case L'E': case L'e': n = 14; break;
case L'F': case L'f': n = 15; break;
case L'G': case L'g': n = 16; break;
case L'H': case L'h': n = 17; break;
case L'I': case L'i': n = 18; break;
case L'J': case L'j': n = 19; break;
case L'K': case L'k': n = 20; break;
case L'L': case L'l': n = 21; break;
case L'M': case L'm': n = 22; break;
case L'N': case L'n': n = 23; break;
case L'O': case L'o': n = 24; break;
case L'P': case L'p': n = 25; break;
case L'Q': case L'q': n = 26; break;
case L'R': case L'r': n = 27; break;
case L'S': case L's': n = 28; break;
case L'T': case L't': n = 29; break;
case L'U': case L'u': n = 30; break;
case L'V': case L'v': n = 31; break;
case L'W': case L'w': n = 32; break;
case L'X': case L'x': n = 33; break;
case L'Y': case L'y': n = 34; break;
case L'Z': case L'z': n = 35; break;
default: n = -1; break; /* error */
}
return n;
}

View File

@@ -0,0 +1,24 @@
/* $NetBSD: _def_messages.c,v 1.6 2005/06/12 05:21:27 lukem Exp $ */
/*
* Written by J.T. Conklin <jtc@NetBSD.org>.
* Public domain.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _def_messages.c,v 1.6 2005/06/12 05:21:27 lukem Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
#include <locale.h>
const _MessagesLocale _DefaultMessagesLocale =
{
"^[Yy]",
"^[Nn]",
"yes",
"no"
} ;
const _MessagesLocale *_CurrentMessagesLocale = &_DefaultMessagesLocale;

View File

@@ -0,0 +1,42 @@
/* $NetBSD: _def_monetary.c,v 1.8 2005/06/12 05:21:27 lukem Exp $ */
/*
* Written by J.T. Conklin <jtc@NetBSD.org>.
* Public domain.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _def_monetary.c,v 1.8 2005/06/12 05:21:27 lukem Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
#include <limits.h>
#include <locale.h>
const _MonetaryLocale _DefaultMonetaryLocale =
{
"",
"",
"",
"",
"",
"",
"",
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX,
(char)CHAR_MAX
};
const _MonetaryLocale *_CurrentMonetaryLocale = &_DefaultMonetaryLocale;

View File

@@ -0,0 +1,23 @@
/* $NetBSD: _def_numeric.c,v 1.6 2005/06/12 05:21:27 lukem Exp $ */
/*
* Written by J.T. Conklin <jtc@NetBSD.org>.
* Public domain.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _def_numeric.c,v 1.6 2005/06/12 05:21:27 lukem Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
#include <locale.h>
const _NumericLocale _DefaultNumericLocale =
{
".",
"",
""
};
const _NumericLocale *_CurrentNumericLocale = &_DefaultNumericLocale;

View File

@@ -0,0 +1,42 @@
/* $NetBSD: _def_time.c,v 1.8 2005/06/12 05:21:27 lukem Exp $ */
/*
* Written by J.T. Conklin <jtc@NetBSD.org>.
* Public domain.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _def_time.c,v 1.8 2005/06/12 05:21:27 lukem Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
#include <locale.h>
const _TimeLocale _DefaultTimeLocale =
{
{
"Sun","Mon","Tue","Wed","Thu","Fri","Sat",
},
{
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"
},
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
},
{
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
},
{
"AM", "PM"
},
"%a %b %e %H:%M:%S %Y",
"%m/%d/%y",
"%H:%M:%S",
"%I:%M:%S %p"
};
const _TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale;

View File

@@ -0,0 +1,126 @@
/* $NetBSD: _wcstod.h,v 1.1 2006/04/15 12:17:23 tnozaki Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Original version ID:
* FreeBSD: /repoman/r/ncvs/src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp
* NetBSD: wcstod.c,v 1.8 2006/04/13 01:25:13 tnozaki Exp
*/
/*
* function template for wcstof, wcstod, wcstold.
*
* parameters:
* _FUNCNAME : function name
* _RETURN_TYPE : return type
* _STRTOD_FUNC : real conversion function
*/
#ifndef __WCSTOD_H_
#define __WCSTOD_H_
/*
* Convert a string to a double-precision number.
*
* This is the wide-character counterpart of strto{f,d,ld}(). So that
* we do not have to duplicate the code of strto{f,d,ld}() here,
* we convert the supplied wide character string to multibyte and
* call strto{f,d,ld}() on the result.
* This assumes that the multibyte encoding is compatible with ASCII
* for at least the digits, radix character and letters.
*/
_RETURN_TYPE
_FUNCNAME(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
const wchar_t *src, *start;
_RETURN_TYPE val;
char *buf, *end;
size_t bufsiz, len;
_DIAGASSERT(nptr != NULL);
/* endptr may be null */
src = nptr;
while (iswspace((wint_t)*src) != 0)
++src;
if (*src == L'\0')
goto no_convert;
/*
* Convert the supplied numeric wide char. string to multibyte.
*
* We could attempt to find the end of the numeric portion of the
* wide char. string to avoid converting unneeded characters but
* choose not to bother; optimising the uncommon case where
* the input string contains a lot of text after the number
* duplicates a lot of strto{f,d,ld}()'s functionality and
* slows down the most common cases.
*/
start = src;
len = wcstombs(NULL, src, 0);
if (len == (size_t)-1)
/* errno = EILSEQ */
goto no_convert;
_DIAGASSERT(len > 0);
bufsiz = len;
buf = (void *)malloc(bufsiz + 1);
if (buf == NULL)
/* errno = ENOMEM */
goto no_convert;
len = wcstombs(buf, src, bufsiz + 1);
_DIAGASSERT(len == bufsiz);
_DIAGASSERT(buf[len] == '\0');
/* Let strto{f,d,ld}() do most of the work for us. */
val = _STRTOD_FUNC(buf, &end);
if (buf == end) {
free(buf);
goto no_convert;
}
/*
* We only know where the number ended in the _multibyte_
* representation of the string. If the caller wants to know
* where it ended, count multibyte characters to find the
* corresponding position in the wide char string.
*/
if (endptr != NULL)
/* XXX Assume each wide char is one byte. */
*endptr = __UNCONST(start + (size_t)(end - buf));
free(buf);
return val;
no_convert:
if (endptr != NULL)
*endptr = __UNCONST(nptr);
return 0;
}
#endif /*__WCSTOD_H_*/

View File

@@ -0,0 +1,153 @@
/** @file
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 1990, 1993
The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Original version ID:
@(#)strtol.c 8.1 (Berkeley) 6/4/93
NetBSD: wcstol.c,v 1.1 2001/09/27 16:30:36 yamt Exp
Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstol.c,v 1.2 2001/09/21 16:11:41 yamt Exp
NetBSD: _wcstol.h,v 1.3 2005/11/29 03:11:59 christos Exp
*/
/*
* function template for wcstol, wcstoll and wcstoimax.
*
* parameters:
* _FUNCNAME : function name
* __wINT : return type
* __wINT_MIN : lower limit of the return type
* __wINT_MAX : upper limit of the return type
*/
__wINT
_FUNCNAME(
const wchar_t *nptr,
wchar_t **endptr,
int base
)
{
const wchar_t *s;
__wINT acc, cutoff;
wint_t wc;
int i;
int neg, any, cutlim;
_DIAGASSERT(nptr != NULL);
/* endptr may be NULL */
#ifdef __GNUC__
(void)&acc; (void)&cutoff;
#endif
/* check base value */
if (base && (base < 2 || base > 36)) {
errno = EINVAL;
return 0;
}
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
s = nptr;
do {
wc = (wchar_t) *s++;
} while (iswspace(wc));
if (wc == L'-') {
neg = 1;
wc = *s++;
} else {
neg = 0;
if (wc == L'+')
wc = *s++;
}
if ((base == 0 || base == 16) &&
wc == L'0' && (*s == L'x' || *s == L'X')) {
wc = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = ((wc == L'0') ? 8 : 10);
/*
* See strtol for comments as to the logic used.
*/
cutoff = neg ? __wINT_MIN : __wINT_MAX;
cutlim = (int)(cutoff % base);
cutoff /= base;
if (neg) {
if (cutlim > 0) {
cutlim -= base;
cutoff += 1;
}
cutlim = -cutlim;
}
for (acc = 0, any = 0;; wc = (wchar_t) *s++) {
i = __wctoint((wchar_t)wc);
if (i == -1)
break;
if (i >= base)
break;
if (any < 0)
continue;
if (neg) {
if (acc < cutoff || (acc == cutoff && i > cutlim)) {
any = -1;
acc = __wINT_MIN;
errno = ERANGE;
} else {
any = 1;
acc *= base;
acc -= i;
}
} else {
if (acc > cutoff || (acc == cutoff && i > cutlim)) {
any = -1;
acc = __wINT_MAX;
errno = ERANGE;
} else {
any = 1;
acc *= base;
acc += i;
}
}
}
if (endptr != 0)
*endptr = __UNCONST(any ? s - 1 : nptr);
return (acc);
}

View File

@@ -0,0 +1,131 @@
/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 1990, 1993
The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Original version ID:
@(#)strtoul.c 8.1 (Berkeley) 6/4/93
Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstoul.c,v 1.2 2001/09/21 16:11:41 yamt Exp
NetBSD: wcstoul.c,v 1.1 2001/09/27 16:30:37 yamt Exp
NetBSD: _wcstoul.h,v 1.3 2005/11/29 03:11:59 christos Exp
*/
/*
* function template for wcstoul, wcstoull and wcstoumax.
*
* parameters:
* _FUNCNAME : function name
* __wUINT : return type
* __wINT : signed version of __wUINT
* __wUINT_MAX : upper limit of the return type
*/
__wUINT
_FUNCNAME(
const wchar_t *nptr,
wchar_t **endptr,
int base
)
{
const wchar_t *s;
__wUINT acc, cutoff;
wint_t wc;
int i;
int neg, any, cutlim;
_DIAGASSERT(nptr != NULL);
/* endptr may be NULL */
if (base && (base < 2 || base > 36)) {
errno = EINVAL;
return 0;
}
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
s = nptr;
do {
wc = (wchar_t) *s++;
} while (iswspace(wc));
if (wc == L'-') {
neg = 1;
wc = *s++;
} else {
neg = 0;
if (wc == L'+')
wc = *s++;
}
if ((base == 0 || base == 16) &&
wc == L'0' && (*s == L'x' || *s == L'X')) {
wc = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = wc == L'0' ? 8 : 10;
/*
* See strtoul for comments as to the logic used.
*/
cutoff = __wUINT_MAX / (__wUINT)base;
cutlim = (int)(__wUINT_MAX % (__wUINT)base);
for (acc = 0, any = 0;; wc = (wint_t) *s++) {
i = __wctoint((wchar_t)wc);
if (i == -1) {
break;
}
if (i >= base)
break;
if (any < 0)
continue;
if (acc > cutoff || (acc == cutoff && i > cutlim)) {
any = -1;
acc = __wUINT_MAX;
errno = ERANGE;
} else {
any = 1;
acc *= (__wUINT)base;
acc += i;
}
}
if (neg && any > 0)
acc = (__wUINT)(-((__wINT)acc));
if (endptr != 0)
*endptr = __UNCONST(any ? s - 1 : nptr);
return (acc);
}

View File

@@ -0,0 +1,129 @@
/* $NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $ */
/*-
* Copyright (c)2002 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "aliasname_local.h"
__inline int __is_ws(char);
__inline int __is_ws(char ch)
{
return (ch == ' ' || ch == '\t');
}
const char *
__unaliasname(const char *dbname, const char *alias, void *buf, size_t bufsize)
{
FILE *fp = NULL;
const char *result = alias;
size_t resultlen;
size_t aliaslen;
const char *p;
size_t len;
_DIAGASSERT(dbname != NULL);
_DIAGASSERT(alias != NULL);
_DIAGASSERT(buf != NULL);
fp = fopen(dbname, "r");
if (fp == NULL)
goto quit;
aliaslen = strlen(alias);
while (/*CONSTCOND*/ 1) {
p = fgetln(fp, &len);
if (p == NULL)
goto quit; /* eof or error */
_DIAGASSERT(len != 0);
/* ignore terminating NL */
if (p[len - 1] == '\n')
len--;
/* ignore null line and comment */
if (len == 0 || p[0] == '#')
continue;
if (aliaslen > len)
continue;
if (memcmp(alias, p, aliaslen))
continue;
p += aliaslen;
len -= aliaslen;
if (len == 0 || !__is_ws(*p))
continue;
/* entry was found here */
break;
/* NOTREACHED */
}
/* skip white spaces */
do {
p++;
len--;
} while (len != 0 && __is_ws(*p));
if (len == 0)
goto quit;
/* count length of result */
resultlen = 0;
while (resultlen < len && !__is_ws(*p))
resultlen++;
/* check if space is enough */
if (bufsize < resultlen + 1)
goto quit;
memcpy(buf, p, resultlen);
((char *)buf)[resultlen] = 0;
result = buf;
quit:
if (fp)
fclose(fp);
return result;
}

View File

@@ -0,0 +1,29 @@
/* $NetBSD: aliasname_local.h,v 1.1 2002/02/13 07:45:52 yamt Exp $ */
/*-
* Copyright (c)2002 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
const char *__unaliasname(const char *, const char *, void *, size_t);

View File

@@ -0,0 +1,186 @@
/** @file
Internal C-type locale functions.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 1997 Christos Zoulas. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by Christos Zoulas.
4. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _CTYPE_PRIVATE
#include <ctype.h>
#include "ctypeio.h"
int
__loadctype(const char *name)
{
FILE *fp;
char id[sizeof(_CTYPE_ID) - 1];
u_int32_t i, len;
unsigned short *new_ctype = NULL;
unsigned char *new_toupper = NULL, *new_tolower = NULL;
_DIAGASSERT(name != NULL);
if ((fp = fopen(name, "r")) == NULL)
return 0;
if (fread(id, sizeof(id), 1, fp) != 1)
goto bad;
if (memcmp(id, _CTYPE_ID, sizeof(id)) != 0)
goto bad;
if (fread(&i, sizeof(u_int32_t), 1, fp) != 1)
goto bad;
if ((i = ntohl(i)) != _CTYPE_REV)
goto bad;
if (fread(&len, sizeof(u_int32_t), 1, fp) != 1)
goto bad;
if ((len = ntohl(len)) != _CTYPE_NUM_CHARS)
goto bad;
if ((new_ctype = malloc(sizeof(UINT16) * (1 + len))) == NULL)
goto bad;
new_ctype[0] = 0;
if (fread(&new_ctype[1], sizeof(UINT16), len, fp) != len)
goto bad;
if ((new_toupper = malloc(sizeof(UINT8) * (1 + len))) == NULL)
goto bad;
new_toupper[0] = (UINT8)EOF;
if (fread(&new_toupper[1], sizeof(UINT8), len, fp) != len)
goto bad;
if ((new_tolower = malloc(sizeof(UINT8) * (1 + len))) == NULL)
goto bad;
new_tolower[0] = (UINT8)EOF;
if (fread(&new_tolower[1], sizeof(UINT8), len, fp) != len)
goto bad;
#if BYTE_ORDER == LITTLE_ENDIAN
for (i = 1; i <= len; i++) {
new_ctype[i] = ntohs(new_ctype[i]);
}
#endif
(void) fclose(fp);
if (_cClass != _C_CharClassTable)
free(__UNCONST(_cClass));
_cClass = new_ctype;
if (_uConvT != _C_ToUpperTable)
free(__UNCONST(_uConvT));
_uConvT = new_toupper;
if (_lConvT != _C_ToLowerTable)
free(__UNCONST(_lConvT));
_lConvT = new_tolower;
return 1;
bad:
free(new_tolower);
free(new_toupper);
free(new_ctype);
(void) fclose(fp);
return 0;
}
int
__savectype(
const char *name,
unsigned short *new_ctype,
unsigned char *new_toupper,
unsigned char *new_tolower
)
{
FILE *fp;
u_int32_t i, len = _CTYPE_NUM_CHARS;
_DIAGASSERT(name != NULL);
_DIAGASSERT(new_ctype != NULL);
_DIAGASSERT(new_toupper != NULL);
_DIAGASSERT(new_tolower != NULL);
if ((fp = fopen(name, "w")) == NULL)
return 0;
if (fwrite(_CTYPE_ID, sizeof(_CTYPE_ID) - 1, 1, fp) != 1)
goto bad;
i = htonl(_CTYPE_REV);
if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1)
goto bad;
i = htonl(len);
if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1)
goto bad;
#if BYTE_ORDER == LITTLE_ENDIAN
for (i = 1; i <= len; i++) {
new_ctype[i] = htons(new_ctype[i]);
}
#endif
if (fwrite(&new_ctype[1], sizeof(UINT16), len, fp) != len)
goto bad;
if (fwrite(&new_toupper[1], sizeof(UINT8), len, fp) != len)
goto bad;
if (fwrite(&new_tolower[1], sizeof(UINT8), len, fp) != len)
goto bad;
(void) fclose(fp);
return 1;
bad:
(void) fclose(fp);
return 0;
}

View File

@@ -0,0 +1,35 @@
/* $NetBSD: ctypeio.h,v 1.1 1997/06/02 09:52:48 kleink Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Christos Zoulas.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
__BEGIN_DECLS
int __loadctype (const char *);
int __savectype (const char *, unsigned short *, unsigned char *, unsigned char *);
__END_DECLS

View File

@@ -0,0 +1,234 @@
/** @file
Wide character classification and conversion functions.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 1989 The Regents of the University of California.
All rights reserved.
(c) UNIX System Laboratories, Inc.
All or some portions of this file are derived from material licensed
to the University of California by American Telephone and Telegraph
Co. or Unix System Laboratories, Inc. and are reproduced herein with
the permission of UNIX System Laboratories, Inc.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include <ctype.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#undef iswalnum
int
iswalnum(wint_t c)
{
return isalnum((int)c);
}
#undef iswalpha
int
iswalpha(wint_t c)
{
return isalpha((int)c);
}
#undef iswblank
int
iswblank(wint_t c)
{
return isblank((int)c);
}
#undef iswcntrl
int
iswcntrl(wint_t c)
{
return iscntrl((int)c);
}
#undef iswdigit
int
iswdigit(wint_t c)
{
return isdigit((int)c);
}
#undef iswgraph
int
iswgraph(wint_t c)
{
return isgraph((int)c);
}
#undef iswlower
int
iswlower(wint_t c)
{
return islower((int)c);
}
#undef iswprint
int
iswprint(wint_t c)
{
return isprint((int)c);
}
#undef iswpunct
int
iswpunct(wint_t c)
{
return ispunct((int)c);
}
#undef iswspace
int
iswspace(wint_t c)
{
return isspace((int)c);
}
#undef iswupper
int
iswupper(wint_t c)
{
return isupper((int)c);
}
#undef iswxdigit
int
iswxdigit(wint_t c)
{
return isxdigit((int)c);
}
#undef towupper
wint_t
towupper(wint_t c)
{
return toupper((int)c);
}
#undef towlower
wint_t
towlower(wint_t c)
{
return tolower((int)c);
}
#undef wcwidth
int
/*ARGSUSED*/
wcwidth(wchar_t c)
{
return 1;
}
#undef iswctype
int
iswctype(wint_t c, wctype_t charclass)
{
/*
* SUSv3: If charclass is 0, iswctype() shall return 0.
*/
return (__isCClass((int)c, (unsigned int)charclass));
}
// Additional functions in <wctype.h> but not in NetBSD _sb code.
static
struct _typestrval {
char *name;
wctype_t value;
} typestrval[] = {
{ "alnum", (_CD | _CU | _CL | _XA) },
{ "alpha", (_CU | _CL | _XA) },
{ "blank", (_CB) },
{ "cntrl", (_CC) },
{ "digit", (_CD) },
{ "graph", (_CG) },
{ "lower", (_CL) },
{ "print", (_CS | _CG) },
{ "punct", (_CP) },
{ "space", (_CW) },
{ "upper", (_CU) },
{ "xdigit", (_CD | _CX) }
};
#define NUM_PROPVAL (sizeof(typestrval) / sizeof(struct _typestrval))
static
struct _transtrval {
char *name;
wctrans_t function;
} transtrval[] = {
{ "tolower", towlower },
{ "toupper", towupper }
};
#define NUM_TRANSVAL (sizeof(transtrval) / sizeof(struct _transtrval))
wctype_t wctype(const char *property)
{
int i;
for(i = 0; i < NUM_PROPVAL; ++i) {
if( strcmp(typestrval[i].name, property) == 0) {
return typestrval[i].value;
}
}
return 0;
}
wint_t towctrans(wint_t p1, wctrans_t tranfunc)
{
return tranfunc(p1);
}
wctrans_t wctrans(const char *property)
{
int i;
for(i = 0; i < NUM_TRANSVAL; ++i) {
if( strcmp(transtrval[i].name, property) == 0) {
return transtrval[i].function;
}
}
return NULL;
}

View File

@@ -0,0 +1,85 @@
/* $NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos Exp $ */
/*
* Written by J.T. Conklin <jtc@NetBSD.org>.
* Public domain.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
#include <locale.h>
/*
* The localeconv() function constructs a struct lconv from the current
* monetary and numeric locales.
*
* Because localeconv() may be called many times (especially by library
* routines like printf() & strtod()), the approprate members of the
* lconv structure are computed only when the monetary or numeric
* locale has been changed.
*/
int __mlocale_changed = 1;
int __nlocale_changed = 1;
/*
* Return the current locale conversion.
*/
struct lconv *
localeconv()
{
static struct lconv ret;
if (__mlocale_changed) {
/* LC_MONETARY */
ret.int_curr_symbol =
__UNCONST(_CurrentMonetaryLocale->int_curr_symbol);
ret.currency_symbol =
__UNCONST(_CurrentMonetaryLocale->currency_symbol);
ret.mon_decimal_point =
__UNCONST(_CurrentMonetaryLocale->mon_decimal_point);
ret.mon_thousands_sep =
__UNCONST(_CurrentMonetaryLocale->mon_thousands_sep);
ret.mon_grouping =
__UNCONST(_CurrentMonetaryLocale->mon_grouping);
ret.positive_sign =
__UNCONST(_CurrentMonetaryLocale->positive_sign);
ret.negative_sign =
__UNCONST(_CurrentMonetaryLocale->negative_sign);
ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits;
ret.frac_digits = _CurrentMonetaryLocale->frac_digits;
ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes;
ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space;
ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes;
ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space;
ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn;
ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn;
ret.int_p_cs_precedes =
_CurrentMonetaryLocale->int_p_cs_precedes;
ret.int_n_cs_precedes =
_CurrentMonetaryLocale->int_n_cs_precedes;
ret.int_p_sep_by_space =
_CurrentMonetaryLocale->int_p_sep_by_space;
ret.int_n_sep_by_space =
_CurrentMonetaryLocale->int_n_sep_by_space;
ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn;
ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn;
__mlocale_changed = 0;
}
if (__nlocale_changed) {
/* LC_NUMERIC */
ret.decimal_point =
__UNCONST(_CurrentNumericLocale->decimal_point);
ret.thousands_sep =
__UNCONST(_CurrentNumericLocale->thousands_sep);
ret.grouping =
__UNCONST(_CurrentNumericLocale->grouping);
__nlocale_changed = 0;
}
return (&ret);
}

View File

@@ -0,0 +1,272 @@
/* $NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $ */
/*
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char *sccsid = "from: @(#)multibyte.c 5.1 (Berkeley) 2/18/91";
#else
__RCSID("$NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <wchar.h>
/*
* Stub multibyte character functions.
* This cheezy implementation is fixed to the native single-byte
* character set.
*/
/*ARGSUSED*/
int
mbsinit(const mbstate_t *ps)
{
return 1;
}
/*ARGSUSED*/
size_t
mbrlen(
const char *s,
size_t n,
mbstate_t *ps
)
{
/* ps appears to be unused */
if (s == NULL || *s == '\0')
return 0;
if (n == 0)
return (size_t)-1;
return 1;
}
int
mblen(
const char *s,
size_t n
)
{
/* s may be NULL */
return (int)mbrlen(s, n, NULL);
}
/*ARGSUSED*/
size_t
mbrtowc(
wchar_t *pwc,
const char *s,
size_t n,
mbstate_t *ps
)
{
/* pwc may be NULL */
/* s may be NULL */
/* ps appears to be unused */
if (s == NULL)
return 0;
if (n == 0)
return (size_t)-1;
if (pwc)
*pwc = (wchar_t) *s;
return (*s != '\0');
}
int
mbtowc(
wchar_t *pwc,
const char *s,
size_t n
)
{
/* pwc may be NULL */
/* s may be NULL */
return (int)mbrtowc(pwc, s, n, NULL);
}
/*ARGSUSED*/
size_t
wcrtomb(
char *s,
wchar_t wchar,
mbstate_t *ps
)
{
/* s may be NULL */
/* ps appears to be unused */
if (s == NULL)
return 0;
*s = (char) wchar;
return 1;
}
int
wctomb(
char *s,
wchar_t wchar
)
{
/* s may be NULL */
return (int)wcrtomb(s, wchar, NULL);
}
/*ARGSUSED*/
size_t
mbsrtowcs(
wchar_t *pwcs,
const char **s,
size_t n,
mbstate_t *ps
)
{
int count = 0;
/* pwcs may be NULL */
/* s may be NULL */
/* ps appears to be unused */
if (!s || !*s)
return 0;
if (n != 0) {
if (pwcs != NULL) {
do {
if ((*pwcs++ = (wchar_t) *(*s)++) == 0)
break;
count++;
} while (--n != 0);
} else {
do {
if (((wchar_t)*(*s)++) == 0)
break;
count++;
} while (--n != 0);
}
}
return count;
}
size_t
mbstowcs(
wchar_t *pwcs,
const char *s,
size_t n
)
{
/* pwcs may be NULL */
/* s may be NULL */
return mbsrtowcs(pwcs, &s, n, NULL);
}
/*ARGSUSED*/
size_t
wcsrtombs(
char *s,
const wchar_t **pwcs,
size_t n,
mbstate_t *ps
)
{
int count = 0;
/* s may be NULL */
/* pwcs may be NULL */
/* ps appears to be unused */
if (pwcs == NULL || *pwcs == NULL)
return (0);
if (s == NULL) {
while (*(*pwcs)++ != 0)
count++;
return(count);
}
if (n != 0) {
do {
if ((*s++ = (char) *(*pwcs)++) == 0)
break;
count++;
} while (--n != 0);
}
return count;
}
size_t
wcstombs(
char *s,
const wchar_t *pwcs,
size_t n
)
{
/* s may be NULL */
/* pwcs may be NULL */
return wcsrtombs(s, &pwcs, n, NULL);
}
wint_t
btowc(int c)
{
if (c == EOF || c & ~0xFF)
return WEOF;
return (wint_t)c;
}
int
wctob(wint_t c)
{
if (c == WEOF || c & ~0xFF)
return EOF;
return (int)c;
}

View File

@@ -0,0 +1,125 @@
/* $NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $ */
/*
* Written by J.T. Conklin <jtc@NetBSD.org>.
* Public domain.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
#include <locale.h>
#include <nl_types.h>
#include <langinfo.h>
#include "rune.h"
#include "runetype.h"
char *
nl_langinfo(nl_item item)
{
const char *s;
switch (item) {
case D_T_FMT:
s = _CurrentTimeLocale->d_t_fmt;
break;
case D_FMT:
s = _CurrentTimeLocale->d_fmt;
break;
case T_FMT:
s = _CurrentTimeLocale->t_fmt;
break;
case T_FMT_AMPM:
s = _CurrentTimeLocale->t_fmt_ampm;
break;
case AM_STR:
case PM_STR:
s = _CurrentTimeLocale->am_pm[(size_t)(item - AM_STR)];
break;
case DAY_1:
case DAY_2:
case DAY_3:
case DAY_4:
case DAY_5:
case DAY_6:
case DAY_7:
s = _CurrentTimeLocale->day[(size_t)(item - DAY_1)];
break;
case ABDAY_1:
case ABDAY_2:
case ABDAY_3:
case ABDAY_4:
case ABDAY_5:
case ABDAY_6:
case ABDAY_7:
s = _CurrentTimeLocale->abday[(size_t)(item - ABDAY_1)];
break;
case MON_1:
case MON_2:
case MON_3:
case MON_4:
case MON_5:
case MON_6:
case MON_7:
case MON_8:
case MON_9:
case MON_10:
case MON_11:
case MON_12:
s = _CurrentTimeLocale->mon[(size_t)(item - MON_1)];
break;
case ABMON_1:
case ABMON_2:
case ABMON_3:
case ABMON_4:
case ABMON_5:
case ABMON_6:
case ABMON_7:
case ABMON_8:
case ABMON_9:
case ABMON_10:
case ABMON_11:
case ABMON_12:
s = _CurrentTimeLocale->abmon[(size_t)(item - ABMON_1)];
break;
case RADIXCHAR:
s = _CurrentNumericLocale->decimal_point;
break;
case THOUSEP:
s = _CurrentNumericLocale->thousands_sep;
break;
case YESSTR:
s = _CurrentMessagesLocale->yesstr;
break;
case YESEXPR:
s = _CurrentMessagesLocale->yesexpr;
break;
case NOSTR:
s = _CurrentMessagesLocale->nostr;
break;
case NOEXPR:
s = _CurrentMessagesLocale->noexpr;
break;
case CRNCYSTR: /* XXX */
s = "";
break;
case CODESET:
#ifdef WITH_RUNE
s = _CurrentRuneLocale->rl_codeset;
#else
s = NULL;
#endif
if (!s)
s = "";
break;
default:
s = "";
break;
}
/* The return value should be really const, but the interface says OW */
return __UNCONST(s);
}

100
StdLib/LibC/Locale/rune.h Normal file
View File

@@ -0,0 +1,100 @@
/* $NetBSD: rune.h,v 1.11 2006/02/16 19:19:49 tnozaki Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)rune.h 8.1 (Berkeley) 6/27/93
*/
#ifndef _RUNE_H_
#define _RUNE_H_
#include <LibConfig.h>
#include <stdio.h>
#include <wchar.h>
#include "runetype.h"
/*
* map _RTYPE_x to _CTYPE_x
*
* XXX: these should be defined in ctype.h and used in isxxx macros.
* (note: current isxxx macros use "old" NetBSD masks and
* _CTYPE_x are not public.)
*/
#define _CTYPE_A _RUNETYPE_A
#define _CTYPE_C _RUNETYPE_C
#define _CTYPE_D _RUNETYPE_D
#define _CTYPE_G _RUNETYPE_G
#define _CTYPE_L _RUNETYPE_L
#define _CTYPE_P _RUNETYPE_P
#define _CTYPE_S _RUNETYPE_S
#define _CTYPE_U _RUNETYPE_U
#define _CTYPE_X _RUNETYPE_X
#define _CTYPE_B _RUNETYPE_B
#define _CTYPE_R _RUNETYPE_R
#define _CTYPE_I _RUNETYPE_I
#define _CTYPE_T _RUNETYPE_T
#define _CTYPE_Q _RUNETYPE_Q
#define _CTYPE_SWM _RUNETYPE_SWM
#define _CTYPE_SWS _RUNETYPE_SWS
#define _CTYPE_SW0 _RUNETYPE_SW0
#define _CTYPE_SW1 _RUNETYPE_SW1
#define _CTYPE_SW2 _RUNETYPE_SW2
#define _CTYPE_SW3 _RUNETYPE_SW3
/*
* Other namespace conversion.
*/
#define rune_t __nbrune_t
#define _RUNE_ISCACHED _NB_RUNE_ISCACHED
#define _CACHED_RUNES _NB_CACHED_RUNES
#define _DEFAULT_INVALID_RUNE _NB_DEFAULT_INVALID_RUNE
#define _RuneEntry _NBRuneEntry
#define _RuneRange _NBRuneRange
#define _RuneLocale _NBRuneLocale
#define _RUNE_MAGIC_1 _NB_RUNE_MAGIC_1
#define _RUNE_MODULE_1 _NB_RUNE_MODULE_1
#define _RUNE_CODESET _NB_RUNE_CODESET
/*
* global variables
*/
extern size_t __mb_len_max_runtime;
#define __MB_LEN_MAX_RUNTIME __mb_len_max_runtime
extern _RuneLocale _DefaultRuneLocale;
extern _RuneLocale *_CurrentRuneLocale;
extern const char *_PathLocale;
#define _LOCALE_ALIAS_NAME "locale.alias"
#endif /*! _RUNE_H_ */

View File

@@ -0,0 +1,221 @@
/* $NetBSD: runetype.h,v 1.19 2005/11/29 03:11:59 christos Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)runetype.h 8.1 (Berkeley) 6/2/93
*/
#ifndef _NB_RUNETYPE_H_
#define _NB_RUNETYPE_H_
#include <sys/EfiCdefs.h>
#include <sys/types.h>
/* for cross host tools on older systems */
#ifndef UINT32_C
/* assumes sizeof(unsigned int)>=4 */
#define UINT32_C(c) ((uint32_t)(c##U))
#endif
typedef uint32_t __nbrune_t;
typedef uint64_t __runepad_t;
#define _NB_CACHED_RUNES (1 << 8) /* Must be a power of 2 */
#define _NB_RUNE_ISCACHED(c) ((c)>=0 && (c)<_CACHED_RUNES)
#define _NB_DEFAULT_INVALID_RUNE ((__nbrune_t)-3)
/*
* The lower 8 bits of runetype[] contain the digit value of the rune.
*/
typedef uint32_t _RuneType;
#define _RUNETYPE_A UINT32_C(0x00000100) /* Alpha */
#define _RUNETYPE_C UINT32_C(0x00000200) /* Control */
#define _RUNETYPE_D UINT32_C(0x00000400) /* Digit */
#define _RUNETYPE_G UINT32_C(0x00000800) /* Graph */
#define _RUNETYPE_L UINT32_C(0x00001000) /* Lower */
#define _RUNETYPE_P UINT32_C(0x00002000) /* Punct */
#define _RUNETYPE_S UINT32_C(0x00004000) /* Space */
#define _RUNETYPE_U UINT32_C(0x00008000) /* Upper */
#define _RUNETYPE_X UINT32_C(0x00010000) /* X digit */
#define _RUNETYPE_B UINT32_C(0x00020000) /* Blank */
#define _RUNETYPE_R UINT32_C(0x00040000) /* Print */
#define _RUNETYPE_I UINT32_C(0x00080000) /* Ideogram */
#define _RUNETYPE_T UINT32_C(0x00100000) /* Special */
#define _RUNETYPE_Q UINT32_C(0x00200000) /* Phonogram */
#define _RUNETYPE_SWM UINT32_C(0xc0000000)/* Mask to get screen width data */
#define _RUNETYPE_SWS 30 /* Bits to shift to get width */
#define _RUNETYPE_SW0 UINT32_C(0x00000000) /* 0 width character */
#define _RUNETYPE_SW1 UINT32_C(0x40000000) /* 1 width character */
#define _RUNETYPE_SW2 UINT32_C(0x80000000) /* 2 width character */
#define _RUNETYPE_SW3 UINT32_C(0xc0000000) /* 3 width character */
/*
* rune file format. network endian.
*/
typedef struct {
int32_t fre_min; /* First rune of the range */
int32_t fre_max; /* Last rune (inclusive) of the range */
int32_t fre_map; /* What first maps to in maps */
uint32_t fre_pad1; /* backward compatibility */
__runepad_t fre_pad2; /* backward compatibility */
} __attribute__((__packed__)) _FileRuneEntry;
typedef struct {
uint32_t frr_nranges; /* Number of ranges stored */
uint32_t frr_pad1; /* backward compatibility */
__runepad_t frr_pad2; /* backward compatibility */
} __attribute__((__packed__)) _FileRuneRange;
typedef struct {
char frl_magic[8]; /* Magic saying what version we are */
char frl_encoding[32];/* ASCII name of this encoding */
__runepad_t frl_pad1; /* backward compatibility */
__runepad_t frl_pad2; /* backward compatibility */
int32_t frl_invalid_rune;
uint32_t frl_pad3; /* backward compatibility */
_RuneType frl_runetype[_NB_CACHED_RUNES];
int32_t frl_maplower[_NB_CACHED_RUNES];
int32_t frl_mapupper[_NB_CACHED_RUNES];
/*
* The following are to deal with Runes larger than _CACHED_RUNES - 1.
* Their data is actually contiguous with this structure so as to make
* it easier to read/write from/to disk.
*/
_FileRuneRange frl_runetype_ext;
_FileRuneRange frl_maplower_ext;
_FileRuneRange frl_mapupper_ext;
__runepad_t frl_pad4; /* backward compatibility */
int32_t frl_variable_len;/* how long that data is */
uint32_t frl_pad5; /* backward compatibility */
/* variable size data follows */
} __attribute__((__packed__)) _FileRuneLocale;
/*
* expanded rune locale declaration. local to the host. host endian.
*/
typedef struct {
__nbrune_t re_min; /* First rune of the range */
__nbrune_t re_max; /* Last rune (inclusive) of the range */
__nbrune_t re_map; /* What first maps to in maps */
_RuneType *re_rune_types; /* Array of types in range */
} _NBRuneEntry;
typedef struct {
uint32_t rr_nranges; /* Number of ranges stored */
_NBRuneEntry *rr_rune_ranges;
} _NBRuneRange;
/*
* wctrans stuffs.
*/
typedef struct _WCTransEntry {
const char *te_name;
__nbrune_t *te_cached;
_NBRuneRange *te_extmap;
} _WCTransEntry;
#define _WCTRANS_INDEX_LOWER 0
#define _WCTRANS_INDEX_UPPER 1
#define _WCTRANS_NINDEXES 2
/*
* wctype stuffs.
*/
typedef struct _WCTypeEntry {
const char *te_name;
_RuneType te_mask;
} _WCTypeEntry;
#define _WCTYPE_INDEX_ALNUM 0
#define _WCTYPE_INDEX_ALPHA 1
#define _WCTYPE_INDEX_BLANK 2
#define _WCTYPE_INDEX_CNTRL 3
#define _WCTYPE_INDEX_DIGIT 4
#define _WCTYPE_INDEX_GRAPH 5
#define _WCTYPE_INDEX_LOWER 6
#define _WCTYPE_INDEX_PRINT 7
#define _WCTYPE_INDEX_PUNCT 8
#define _WCTYPE_INDEX_SPACE 9
#define _WCTYPE_INDEX_UPPER 10
#define _WCTYPE_INDEX_XDIGIT 11
#define _WCTYPE_NINDEXES 12
/*
* ctype stuffs
*/
typedef struct _NBRuneLocale {
/*
* copied from _FileRuneLocale
*/
char rl_magic[8]; /* Magic saying what version we are */
char rl_encoding[32];/* ASCII name of this encoding */
__nbrune_t rl_invalid_rune;
_RuneType rl_runetype[_NB_CACHED_RUNES];
__nbrune_t rl_maplower[_NB_CACHED_RUNES];
__nbrune_t rl_mapupper[_NB_CACHED_RUNES];
_NBRuneRange rl_runetype_ext;
_NBRuneRange rl_maplower_ext;
_NBRuneRange rl_mapupper_ext;
void *rl_variable;
size_t rl_variable_len;
/*
* the following portion is generated on the fly
*/
const char *rl_codeset;
struct _citrus_ctype_rec *rl_citrus_ctype;
_WCTransEntry rl_wctrans[_WCTRANS_NINDEXES];
_WCTypeEntry rl_wctype[_WCTYPE_NINDEXES];
} _NBRuneLocale;
/* magic number for LC_CTYPE (rune)locale declaration */
#define _NB_RUNE_MAGIC_1 "RuneCT10" /* Indicates version 0 of RuneLocale */
/* magic string for dynamic link module - type should be like "LC_CTYPE" */
#define _NB_RUNE_MODULE_1(type) "RuneModule10." type
/* codeset tag */
#define _NB_RUNE_CODESET "CODESET="
#endif /* !_NB_RUNETYPE_H_ */

View File

@@ -0,0 +1,423 @@
/* $NetBSD: setlocale.c,v 1.50 2006/02/16 19:19:49 tnozaki Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
#else
__RCSID("$NetBSD: setlocale.c,v 1.50 2006/02/16 19:19:49 tnozaki Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#if defined(_MSC_VER)
// Disable warnings about assignment within conditional expressions.
#pragma warning ( disable : 4706 )
#endif
#define _CTYPE_PRIVATE
#include "namespace.h"
#include <sys/localedef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/EfiSysCall.h>
#include "rune.h"
#ifdef WITH_RUNE
#include "rune_local.h"
#else
#include "ctypeio.h"
#endif
#ifdef CITRUS
#include <citrus/citrus_namespace.h>
#include <citrus/citrus_region.h>
#include <citrus/citrus_lookup.h>
#include <citrus/citrus_bcs.h>
#else
#include "aliasname_local.h"
#define _lookup_alias(p, a, b, s, c) __unaliasname((p), (a), (b), (s))
#define _bcs_strcasecmp(a, b) strcasecmp((a), (b))
#endif
#define _LOCALE_SYM_FORCE "/force"
#ifndef WITH_RUNE
const char *_PathLocale = NULL;
#endif
/*
* Category names for getenv()
*/
static const char *const categories[_LC_LAST] = {
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
"LC_MESSAGES"
};
/*
* Current locales for each category
*/
static char current_categories[_LC_LAST][32] = {
"C",
"C",
"C",
"C",
"C",
"C",
"C"
};
/*
* The locales we are going to try and load
*/
static char new_categories[_LC_LAST][32];
static char current_locale_string[_LC_LAST * 33];
static char *currentlocale(void);
static void revert_to_default(int);
static int force_locale_enable(int);
static int load_locale_sub(int, const char *, int);
static char *loadlocale(int);
static const char *__get_locale_env(int);
char *
__setlocale(int category, const char *locale)
{
int i, loadlocale_success;
size_t len;
const char *env, *r;
//if (issetugid() ||
// (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))))
// _PathLocale = _PATH_LOCALE;
if (category < 0 || category >= _LC_LAST)
return (NULL);
if (!locale)
return (category ?
current_categories[category] : currentlocale());
/*
* Default to the current locale for everything.
*/
for (i = 1; i < _LC_LAST; ++i)
(void)strncpyX(new_categories[i], current_categories[i],
sizeof(new_categories[i]));
/*
* Now go fill up new_categories from the locale argument
*/
if (!*locale) {
if (category == LC_ALL) {
for (i = 1; i < _LC_LAST; ++i) {
env = __get_locale_env(i);
(void)strncpyX(new_categories[i], env,
sizeof(new_categories[i]));
}
}
else {
env = __get_locale_env(category);
(void)strncpyX(new_categories[category], env,
sizeof(new_categories[category]));
}
} else if (category) {
(void)strncpyX(new_categories[category], locale,
sizeof(new_categories[category]));
} else {
if ((r = strchr(locale, '/')) == 0) {
for (i = 1; i < _LC_LAST; ++i) {
(void)strncpyX(new_categories[i], locale,
sizeof(new_categories[i]));
}
} else {
for (i = 1;;) {
_DIAGASSERT(*r == '/' || *r == 0);
_DIAGASSERT(*locale != 0);
if (*locale == '/')
return (NULL); /* invalid format. */
len = r - locale;
if (len + 1 > sizeof(new_categories[i]))
return (NULL); /* too long */
(void)memcpy(new_categories[i], locale, len);
new_categories[i][len] = '\0';
if (*r == 0)
break;
_DIAGASSERT(*r == '/');
if (*(locale = ++r) == 0)
/* slash followed by NUL */
return (NULL);
/* skip until NUL or '/' */
while (*r && *r != '/')
r++;
if (++i == _LC_LAST)
return (NULL); /* too many slashes. */
}
if (i + 1 != _LC_LAST)
return (NULL); /* too few slashes. */
}
}
if (category)
return (loadlocale(category));
loadlocale_success = 0;
for (i = 1; i < _LC_LAST; ++i) {
if (loadlocale(i) != NULL)
loadlocale_success = 1;
}
/*
* If all categories failed, return NULL; we don't need to back
* changes off, since none happened.
*/
if (!loadlocale_success)
return NULL;
return (currentlocale());
}
static char *
currentlocale()
{
int i;
(void)strncpyX(current_locale_string, current_categories[1],
sizeof(current_locale_string));
for (i = 2; i < _LC_LAST; ++i)
if (strcmp(current_categories[1], current_categories[i])) {
(void)snprintf(current_locale_string,
sizeof(current_locale_string), "%s/%s/%s/%s/%s/%s",
current_categories[1], current_categories[2],
current_categories[3], current_categories[4],
current_categories[5], current_categories[6]);
break;
}
return (current_locale_string);
}
static void
revert_to_default(int category)
{
switch (category) {
case LC_CTYPE:
#ifdef WITH_RUNE
(void)_xpg4_setrunelocale("C");
(void)__runetable_to_netbsd_ctype("C");
#else
if (_cClass != _C_CharClassTable) {
/* LINTED const castaway */
free((void *)_cClass);
_cClass = _C_CharClassTable;
}
if (_uConvT != _C_ToUpperTable) {
/* LINTED const castaway */
free((void *)_uConvT);
_uConvT = _C_ToUpperTable;
}
if (_lConvT != _C_ToLowerTable) {
/* LINTED const castaway */
free((void *)_lConvT);
_lConvT = _C_ToLowerTable;
}
#endif
break;
case LC_MESSAGES:
case LC_COLLATE:
case LC_MONETARY:
case LC_NUMERIC:
case LC_TIME:
break;
}
}
static int
force_locale_enable(int category)
{
revert_to_default(category);
return 0;
}
static int
load_locale_sub(
int category,
const char *locname,
int isspecial
)
{
char name[PATH_MAX];
/* check for the default locales */
if (!strcmp(new_categories[category], "C") ||
!strcmp(new_categories[category], "POSIX")) {
revert_to_default(category);
return 0;
}
/* check whether special symbol */
if (isspecial && _bcs_strcasecmp(locname, _LOCALE_SYM_FORCE) == 0)
return force_locale_enable(category);
/* sanity check */
if (strchr(locname, '/') != NULL)
return -1;
(void)snprintf(name, sizeof(name), "%s/%s/%s",
_PathLocale, locname, categories[category]);
switch (category) {
case LC_CTYPE:
#ifdef WITH_RUNE
if (_xpg4_setrunelocale(__UNCONST(locname)))
return -1;
if (__runetable_to_netbsd_ctype(locname)) {
/* very unfortunate, but need to go to "C" locale */
revert_to_default(category);
return -1;
}
#else
if (!__loadctype(name))
return -1;
#endif
break;
case LC_MESSAGES:
/*
* XXX we don't have LC_MESSAGES support yet,
* but catopen may use the value of LC_MESSAGES category.
* so return successfully if locale directory is present.
*/
(void)snprintf(name, sizeof(name), "%s/%s",
_PathLocale, locname);
/* local */
{
struct stat st;
if (stat(name, &st) < 0)
return -1;
if (!S_ISDIR(st.st_mode))
return -1;
}
break;
case LC_COLLATE:
case LC_MONETARY:
case LC_NUMERIC:
case LC_TIME:
return -1;
}
return 0;
}
static char *
loadlocale(int category)
{
//char aliaspath[PATH_MAX], loccat[PATH_MAX], buf[PATH_MAX];
//const char *alias;
_DIAGASSERT(0 < category && category < _LC_LAST);
if (strcmp(new_categories[category], current_categories[category]) == 0)
return (current_categories[category]);
/* (1) non-aliased file */
if (!load_locale_sub(category, new_categories[category], 0))
goto success;
///* (2) lookup locname/catname type alias */
//(void)snprintf(aliaspath, sizeof(aliaspath),
// "%s/" _LOCALE_ALIAS_NAME, _PathLocale);
//(void)snprintf(loccat, sizeof(loccat), "%s/%s",
// new_categories[category], categories[category]);
//alias = _lookup_alias(aliaspath, loccat, buf, sizeof(buf),
// _LOOKUP_CASE_SENSITIVE);
//if (!load_locale_sub(category, alias, 1))
// goto success;
///* (3) lookup locname type alias */
//alias = _lookup_alias(aliaspath, new_categories[category],
// buf, sizeof(buf), _LOOKUP_CASE_SENSITIVE);
//if (!load_locale_sub(category, alias, 1))
// goto success;
return NULL;
success:
(void)strncpyX(current_categories[category],
new_categories[category],
sizeof(current_categories[category]));
return current_categories[category];
}
static const char *
__get_locale_env(int category)
{
const char *env;
//_DIAGASSERT(category != LC_ALL);
///* 1. check LC_ALL. */
//env = getenv(categories[0]);
///* 2. check LC_* */
//if (!env || !*env)
// env = getenv(categories[category]);
///* 3. check LANG */
//if (!env || !*env)
// env = getenv("LANG");
///* 4. if none is set, fall to "C" */
//if (!env || !*env || strchr(env, '/'))
env = "C";
return env;
}

View File

@@ -0,0 +1,53 @@
/* $NetBSD: setlocale1.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: setlocale1.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include "rune.h"
__warn_references(setlocale,
"warning: reference to compatibility setlocale(); include <locale.h> for correct reference")
/*
* Preparation for the future import of multibyte locale.
* This function will ensure binary compatibility for old executables.
*/
char *
setlocale(int category, const char *locale)
{
/* locale may be NULL */
__mb_len_max_runtime = 1;
return __setlocale(category, locale);
}

View File

@@ -0,0 +1,46 @@
/* $NetBSD: setlocale32.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: setlocale32.c,v 1.2 2003/03/11 17:23:07 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include "rune.h"
char *
__setlocale_mb_len_max_32(int category, const char *locale)
{
/* locale may be NULL */
__mb_len_max_runtime = 32;
return __setlocale(category, locale);
}

View File

@@ -0,0 +1,47 @@
/* $NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <wchar.h>
/*
* Compare strings with using collating information.
*/
int
wcscoll(const wchar_t *s1, const wchar_t *s2)
{
/* XXX: LC_COLLATE should be implemented. */
return (wcscmp(s1, s2));
}

View File

@@ -0,0 +1,109 @@
/* $NetBSD: wcsftime.c,v 1.2 2006/10/04 14:19:16 tnozaki Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
__FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
#else
__RCSID("$NetBSD: wcsftime.c,v 1.2 2006/10/04 14:19:16 tnozaki Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include <wchar.h>
#include <machine/int_limits.h>
/*
* Convert date and time to a wide-character string.
*
* This is the wide-character counterpart of strftime(). So that we do not
* have to duplicate the code of strftime(), we convert the format string to
* multibyte, call strftime(), then convert the result back into wide
* characters.
*
* This technique loses in the presence of stateful multibyte encoding if any
* of the conversions in the format string change conversion state. When
* stateful encoding is implemented, we will need to reset the state between
* format specifications in the format string.
*/
size_t
wcsftime(wchar_t *wcs, size_t maxsize,
const wchar_t *format, const struct tm *timeptr)
{
char *dst, *dstp, *sformat;
size_t n, sflen;
int sverrno;
sformat = dst = NULL;
/*
* Convert the supplied format string to a multibyte representation
* for strftime(), which only handles single-byte characters.
*/
sflen = wcstombs(NULL, format, 0);
if (sflen == (size_t)-1)
goto error;
if ((sformat = malloc(sflen + 1)) == NULL)
goto error;
wcstombs(sformat, format, sflen + 1);
/*
* Allocate memory for longest multibyte sequence that will fit
* into the caller's buffer and call strftime() to fill it.
* Then, copy and convert the result back into wide characters in
* the caller's buffer.
*/
if (SIZE_T_MAX / MB_CUR_MAX <= maxsize) {
/* maxsize is preposturously large - avoid int. overflow. */
errno = EINVAL;
goto error;
}
dst = malloc(maxsize * MB_CUR_MAX);
if (dst == NULL)
goto error;
if (strftime(dst, maxsize, sformat, timeptr) == 0)
goto error;
dstp = dst;
n = mbstowcs(wcs, dstp, maxsize);
if (n == (size_t)-2 || n == (size_t)-1)
goto error;
free(sformat);
free(dst);
return n;
error:
sverrno = errno;
free(sformat);
free(dst);
errno = sverrno;
return 0;
}

View File

@@ -0,0 +1,51 @@
/* $NetBSD: wcstod.c,v 1.12 2006/04/16 17:03:32 christos Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstod.c,v 1.12 2006/04/16 17:03:32 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
//#ifdef __weak_alias
//__strong_alias(_wcstod,wcstod)
//__weak_alias(wcstod,_wcstod)
//#endif
#define _FUNCNAME wcstod
#define _RETURN_TYPE double
#define _STRTOD_FUNC strtod
#include "_wcstod.h"

View File

@@ -0,0 +1,53 @@
/* $NetBSD: wcstof.c,v 1.2 2006/04/16 17:03:32 christos Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstof.c,v 1.2 2006/04/16 17:03:32 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#ifdef __weak_alias
__strong_alias(_wcstof,wcstof)
__weak_alias(wcstof,_wcstof)
#endif
#define _FUNCNAME wcstof
#define _RETURN_TYPE float
#define _STRTOD_FUNC strtof
#include "_wcstod.h"

View File

@@ -0,0 +1,59 @@
/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c)2003 Citrus Project,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstoimax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include "__wctoint.h"
#define _FUNCNAME wcstoimax
#define __wINT intmax_t
#define __wINT_MIN INTMAX_MIN
#define __wINT_MAX INTMAX_MAX
#include "_wcstol.h"

View File

@@ -0,0 +1,58 @@
/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c)2003 Citrus Project,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstol.c,v 1.3 2004/06/21 21:20:43 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include "__wctoint.h"
#define _FUNCNAME wcstol
#define __wINT long int
#define __wINT_MIN LONG_MIN
#define __wINT_MAX LONG_MAX
#include "_wcstol.h"

View File

@@ -0,0 +1,53 @@
/* $NetBSD: wcstold.c,v 1.2 2006/04/16 17:03:32 christos Exp $ */
/*-
* Copyright (c)2006 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstold.c,v 1.2 2006/04/16 17:03:32 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#ifdef __weak_alias
__strong_alias(_wcstold,wcstold)
__weak_alias(wcstold,_wcstold)
#endif
#define _FUNCNAME wcstold
#define _RETURN_TYPE long double
#define _STRTOD_FUNC strtold
#include "_wcstod.h"

View File

@@ -0,0 +1,58 @@
/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c)2003 Citrus Project,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstoll.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include "__wctoint.h"
#define _FUNCNAME wcstoll
#define __wINT /* LONGLONG */ long long int
#define __wINT_MIN LLONG_MIN
#define __wINT_MAX LLONG_MAX
#include "_wcstol.h"

View File

@@ -0,0 +1,58 @@
/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c)2003 Citrus Project,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstoul.c,v 1.3 2004/06/21 21:20:43 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include "__wctoint.h"
#define _FUNCNAME wcstoul
#define __wINT long int
#define __wUINT unsigned long int
#define __wUINT_MAX ULONG_MAX
#include "_wcstoul.h"

View File

@@ -0,0 +1,58 @@
/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c)2003 Citrus Project,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstoull.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include "__wctoint.h"
#define _FUNCNAME wcstoull
#define __wINT long long int
#define __wUINT /* LONGLONG */ unsigned long long int
#define __wUINT_MAX ULLONG_MAX
#include "_wcstoul.h"

View File

@@ -0,0 +1,59 @@
/** @file
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c)2003 Citrus Project,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcstoumax.c,v 1.2 2004/06/21 21:20:43 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include "__wctoint.h"
#define _FUNCNAME wcstoumax
#define __wINT intmax_t
#define __wUINT uintmax_t
#define __wUINT_MAX UINTMAX_MAX
#include "_wcstoul.h"

View File

@@ -0,0 +1,66 @@
/* $NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <wchar.h>
/*
* Compare strings with using collating information.
*/
size_t
wcsxfrm(
wchar_t *s1,
const wchar_t *s2,
size_t n
)
{
size_t len;
/* XXX: LC_COLLATE should be implemented. */
len = wcslen(s2);
if (len<n)
wcscpy(s1, s2);
else {
/*
* SUSv3 says:
* If the value returned is n or more, the contents
* of the array pointed to by ws1 are unspecified.
*/
/* thus, do nothing */
}
return (len);
}

View File

@@ -0,0 +1,81 @@
/* $NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $ */
/*
* Copyright (c) 1996 Mark Brinicombe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe
* for the NetBSD Project.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <ieeefp.h>
static const int map[] = {
1, /* round to nearest */
2, /* round to positive infinity */
3, /* round to negative infinity */
0 /* round to zero */
};
/*
* Return the current FP rounding mode
*
* Returns:
* 0 - round to zero
* 1 - round to nearest
* 2 - round to postive infinity
* 3 - round to negative infinity
*
* ok all we need to do is get the current FP rounding mode
* index our map table and return the appropriate value.
*
* HOWEVER:
* The ARM FPA codes the rounding mode into the actual FP instructions
* so there is no such thing as a global rounding mode.
* The default is round to nearest if rounding is not explicitly specified.
* FP instructions generated by GCC will not explicitly specify a rounding
* mode.
*
* So the best we can do it to return the rounding mode FP instructions
* use if rounding is not specified which is round to nearest.
*
* This could change in the future with new floating point emulators or
* soft float FP libraries.
*/
int __flt_rounds(void);
int
__flt_rounds()
{
return(map[fpgetround()]);
}

View File

@@ -0,0 +1,72 @@
/** @file
Byte Swap routines for endian-nes conversions.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
#include <LibConfig.h>
#include <sys/bswap.h>
// Undefine macro versions of the functions to be defined below.
#undef bswap16
#undef bswap32
#undef bswap64
/**
Switches the endianness of a 16-bit integer.
This function swaps the bytes in a 16-bit unsigned value to switch the value
from little endian to big endian or vice versa. The byte swapped value is
returned.
@param Value A 16-bit unsigned value.
@return The byte swapped Value.
**/
uint16_t bswap16(uint16_t Value)
{
return SwapBytes16(Value);
}
/**
Switches the endianness of a 32-bit integer.
This function swaps the bytes in a 32-bit unsigned value to switch the value
from little endian to big endian or vice versa. The byte swapped value is
returned.
@param Value A 32-bit unsigned value.
@return The byte swapped Value.
**/
uint32_t bswap32(uint32_t Value)
{
return SwapBytes32(Value);
}
/**
Switches the endianness of a 64-bit integer.
This function swaps the bytes in a 64-bit unsigned value to switch the value
from little endian to big endian or vice versa. The byte swapped value is
returned.
@param Value A 64-bit unsigned value.
@return The byte swapped Value.
**/
uint64_t bswap64(uint64_t Value)
{
return SwapBytes64(Value);
}

View File

@@ -0,0 +1,90 @@
/** @File
Routines for translating between host and network byte-order.
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
#include <LibConfig.h>
#include <sys/endian.h>
// Undefine macro versions of the functions to be defined below.
#undef htonl
#undef htons
#undef ntohl
#undef ntohs
/** 32-bit Host to Network byte order conversion.
@param[in] Datum The 32-bit value to be converted.
@return Datum, converted to network byte order.
**/
uint32_t
htonl(
IN uint32_t Datum
)
{
#if BYTE_ORDER == LITTLE_ENDIAN
return SwapBytes32(Datum);
#else
return Datum;
#endif
}
/** 16-bit Host to Network byte order conversion.
@param[in] Datum The 16-bit value to be converted.
@return Datum, converted to network byte order.
**/
uint16_t
htons(
IN uint16_t Datum
)
{
#if BYTE_ORDER == LITTLE_ENDIAN
return SwapBytes16(Datum);
#else
return Datum;
#endif
}
/** 32-bit Network to Host byte order conversion.
@param[in] Datum The 16-bit value to be converted.
@return Datum, converted to host byte order.
**/
uint32_t
ntohl(
IN uint32_t Datum
)
{
#if BYTE_ORDER == LITTLE_ENDIAN
return SwapBytes32(Datum);
#else
return Datum;
#endif
}
/** 16-bit Network to Host byte order conversion.
@param[in] Datum The 16-bit value to be converted.
@return Datum, converted to host byte order.
**/
uint16_t
ntohs(
IN uint16_t Datum
)
{
#if BYTE_ORDER == LITTLE_ENDIAN
return SwapBytes16(Datum);
#else
return Datum;
#endif
}

View File

@@ -0,0 +1,22 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#------------------------------------------------------------------------------
ASM_GLOBAL ASM_PFX(internal_FPU_rmode)
ASM_PFX(internal_FPU_rmode):
subl $4,%esp
fnstcw (%esp)
movl (%esp),%eax
shrl $10,%eax
andl $3,%eax
addl $4,%esp
ret

View File

@@ -0,0 +1,46 @@
;------------------------------------------------------------------------------
; Return the current FPU rounding mode.
;
; MASM implementation of the flt_rounds function by:
; J.T. Conklin, Apr 4, 1995
; Public domain.
;
; Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php.
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; NetBSD: flt_rounds.S,v 1.6 1999/08/23 08:45:09 kleink Exp
;------------------------------------------------------------------------------
.686
.model flat,C
.code
;_map BYTE 1 ; round to nearest
; BYTE 3 ; round to negative infinity
; BYTE 2 ; round to positive infinity
; BYTE 0 ; round to zero
;------------------------------------------------------------------------------
; int
; EFIAPI
; fpu_rmode( void );
;
;------------------------------------------------------------------------------
internal_FPU_rmode PROC
sub esp, 4 ; Create a local variable for fnstcw
fnstcw [esp]
mov eax, [esp]
shr eax, 10
and eax, 3
add esp, 4 ; Delete the local variable
ret
internal_FPU_rmode ENDP
END

Binary file not shown.

View File

@@ -0,0 +1,68 @@
/* $NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// C4700: uninitialized local variable used
#pragma warning ( disable : 4700 )
#endif
/*
* 7.12.3.3 isinf - test for infinity
* IEEE 754 compatible 80-bit extended-precision Intel 386 version
*/
int
__isinfl(long double x)
{
union ieee_ext_u u;
u.extu_ld = x;
return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
u.extu_ext.ext_frach == 0x80000000 && u.extu_ext.ext_fracl == 0);
}

View File

@@ -0,0 +1,69 @@
/* $NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// C4700: uninitialized local variable used
#pragma warning ( disable : 4700 )
#endif
/*
* 7.12.3.4 isnan - test for a NaN
* IEEE 754 compatible 80-bit extended-precision Intel 386 version
*/
int
__isnanl(long double x)
{
union ieee_ext_u u;
u.extu_ld = x;
return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
(u.extu_ext.ext_frach & 0x80000000) != 0 &&
(u.extu_ext.ext_frach != 0x80000000 || u.extu_ext.ext_fracl != 0));
}

View File

@@ -0,0 +1,12 @@
.globl internal_FPU_rmode
.proc internal_FPU_rmode
internal_FPU_rmode::
// get the floating point rounding control bits
// bits 10 and 11 are the rc bits from main status field fpsr.sf0
mov r8= ar.fpsr;;
shr r8 = r8, 10
mov r9 = 3;;
and r8 = r8, r9;;
br.sptk.few b0
.endp internal_FPU_rmode

View File

@@ -0,0 +1,25 @@
/*
* Written by J.T. Conklin, Apr 10, 1995
* Public domain.
*/
#include <sys/EfiCdefs.h>
/* __FBSDID("$FreeBSD: src/lib/libc/ia64/gen/flt_rounds.c,v 1.1 2004/07/19 08:17:24 das Exp $"); */
#include <float.h>
static const int map[] = {
1, /* round to nearest */
3, /* round to zero */
2, /* round to negative infinity */
0 /* round to positive infinity */
};
int
__flt_rounds(void)
{
int x;
__asm("mov %0=ar.fpsr" : "=r" (x));
return (map[(x >> 10) & 0x03]);
}

102
StdLib/LibC/Main/Main.c Normal file
View File

@@ -0,0 +1,102 @@
/** @file
Establish the program environment and the "main" entry point.
All of the global data in the gMD structure is initialized to 0, NULL, or
SIG_DFL; as appropriate.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/ShellCEntryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/TimerLib.h>
#include <LibConfig.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <MainData.h>
extern int main( int, wchar_t**);
extern int __sse2_available;
struct __MainData *gMD;
/* Worker function to keep GCC happy. */
void __main()
{
;
}
INTN
EFIAPI
ShellAppMain (
IN UINTN Argc,
IN CHAR16 **Argv
)
{
INTN ExitVal;
INTN i;
struct __filedes *mfd;
FILE *fp;
ExitVal = (INTN)RETURN_SUCCESS;
gMD = AllocateZeroPool(sizeof(struct __MainData));
if( gMD == NULL ) {
ExitVal = (INTN)RETURN_OUT_OF_RESOURCES;
}
else {
/* Initialize data */
__sse2_available = 0;
_fltused = 1;
errno = 0;
EFIerrno = 0;
#ifdef NT32dvm
gMD->ClocksPerSecond = 0; // For NT32 only
gMD->AppStartTime = 0; // For NT32 only
#else
gMD->ClocksPerSecond = (clock_t)GetPerformanceCounterProperties( NULL, NULL);
gMD->AppStartTime = (clock_t)GetPerformanceCounter();
#endif /* NT32 dvm */
// Initialize file descriptors
mfd = gMD->fdarray;
for(i = 0; i < (FOPEN_MAX); ++i) {
mfd[i].MyFD = (UINT16)i;
}
// Open stdin, stdout, stderr
fp = freopen("stdin:", "r", stdin);
if(fp != NULL) {
fp = freopen("stdout:", "w", stdout);
if(fp != NULL) {
fp = freopen("stderr:", "w", stderr);
}
}
if(fp == NULL) {
Print(L"ERROR Initializing Standard IO: %a.\n %r\n",
strerror(errno), EFIerrno);
}
ExitVal = (INTN)main( (int)Argc, (wchar_t **)Argv);
if (gMD->cleanup != NULL) {
gMD->cleanup();
}
}
if(gMD != NULL) {
FreePool( gMD );
}
return ExitVal;
}

View File

@@ -0,0 +1,20 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#------------------------------------------------------------------------------
ASM_GLOBAL ASM_PFX(internal_FPU_rmode)
ASM_PFX(internal_FPU_rmode):
fnstcw -4(%rsp)
movl -4(%rsp),%eax
shrl $10,%eax
andl $3,%eax
ret

View File

@@ -0,0 +1,41 @@
;------------------------------------------------------------------------------
; Return the current FPU rounding mode.
;
; MASM implementation of the flt_rounds function from NetBSD.
;
; Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php.
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
;------------------------------------------------------------------------------
.code
;_map BYTE 1 ; round to nearest
; BYTE 3 ; round to negative infinity
; BYTE 2 ; round to positive infinity
; BYTE 0 ; round to zero
;------------------------------------------------------------------------------
; int
; EFIAPI
; fpu_rmode( void );
;
; VC++ always creates space for 4 parameters on the stack, whether they are
; used or not. We use one for temporary storage since the only variant of
; fnstcw saves to memory, NOT a register.
;------------------------------------------------------------------------------
internal_FPU_rmode PROC
fnstcw [rsp + 8] ; save 16-bit FPU Control Word
mov eax, [rsp + 8] ; get the saved FPU Control Word
shr eax, 10
and rax, 3 ; index is only the LSB two bits in RAX
ret ; Return rounding mode in RAX
internal_FPU_rmode ENDP
END

View File

@@ -0,0 +1,63 @@
/* $NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:08 pavel Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isinfl.c,v 1.5.16.1 2007/05/07 19:49:08 pavel Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
/*
* 7.12.3.3 isinf - test for infinity
* IEEE 754 compatible 80-bit extended-precision Intel 386 version
*/
int
__isinfl(long double x)
{
union ieee_ext_u u = {0.0};
u.extu_ld = x;
return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
u.extu_ext.ext_frach == 0x80000000 && u.extu_ext.ext_fracl == 0);
}

View File

@@ -0,0 +1,64 @@
/* $NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isnanl.c,v 1.5.16.1 2007/05/07 19:49:07 pavel Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
/*
* 7.12.3.4 isnan - test for a NaN
* IEEE 754 compatible 80-bit extended-precision Intel 386 version
*/
int
__isnanl(long double x)
{
union ieee_ext_u u = { 0 };
u.extu_ld = x;
return (u.extu_ext.ext_exp == EXT_EXP_INFNAN &&
(u.extu_ext.ext_frach & 0x80000000) != 0 &&
(u.extu_ext.ext_frach != 0x80000000 || u.extu_ext.ext_fracl != 0));
}

32
StdLib/LibC/Main/assert.c Normal file
View File

@@ -0,0 +1,32 @@
/**
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
//#include <Uefi.h>
//#include <Library/UefiLib.h>
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#include <stdio.h>
#include <stdlib.h>
void
EFIAPI
__assert(const char *func, const char *file, int line, const char *failedexpr)
{
if (func == NULL)
printf("Assertion failed: (%s), file %s, line %d.\n",
failedexpr, file, line);
else
printf("Assertion failed: (%s), function %s, file %s, line %d.\n",
failedexpr, func, file, line);
abort();
/* NOTREACHED */
}

View File

@@ -0,0 +1,22 @@
/* $NetBSD: bswap16.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */
/*
* Written by Manuel Bouyer <bouyer@NetBSD.org>.
* Public domain.
*/
//#include <sys/cdefs.h>
//#if defined(LIBC_SCCS) && !defined(lint)
//__RCSID("$NetBSD: bswap16.c,v 1.1 2005/12/20 19:28:51 christos Exp $");
//#endif /* LIBC_SCCS and not lint */
//#include <sys/types.h>
//#include <machine/bswap.h>
#undef bswap16
UINT16
bswap16(UINT16 x)
{
return ((x << 8) & 0xff00) | ((x >> 8) & 0x00ff);
}

View File

@@ -0,0 +1,25 @@
/* $NetBSD: bswap32.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */
/*
* Written by Manuel Bouyer <bouyer@NetBSD.org>.
* Public domain.
*/
//#include <sys/cdefs.h>
//#if defined(LIBC_SCCS) && !defined(lint)
//__RCSID("$NetBSD: bswap32.c,v 1.1 2005/12/20 19:28:51 christos Exp $");
//#endif /* LIBC_SCCS and not lint */
//#include <sys/types.h>
//#include <machine/bswap.h>
#undef bswap32
UINT32
bswap32(UINT32 x)
{
return ((x << 24) & 0xff000000 ) |
((x << 8) & 0x00ff0000 ) |
((x >> 8) & 0x0000ff00 ) |
((x >> 24) & 0x000000ff );
}

View File

@@ -0,0 +1,44 @@
/* $NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */
/*
* Written by Manuel Bouyer <bouyer@NetBSD.org>.
* Public domain.
*/
//#include <sys/cdefs.h>
//#if defined(LIBC_SCCS) && !defined(lint)
//__RCSID("$NetBSD: bswap64.c,v 1.1 2005/12/20 19:28:51 christos Exp $");
//#endif /* LIBC_SCCS and not lint */
//#include <sys/types.h>
//#include <machine/bswap.h>
#undef bswap64
UINT64
bswap64(UINT64 x)
{
#ifndef _LP64
/*
* Assume we have wide enough registers to do it without touching
* memory.
*/
return ( (x << 56) & 0xff00000000000000UL ) |
( (x << 40) & 0x00ff000000000000UL ) |
( (x << 24) & 0x0000ff0000000000UL ) |
( (x << 8) & 0x000000ff00000000UL ) |
( (x >> 8) & 0x00000000ff000000UL ) |
( (x >> 24) & 0x0000000000ff0000UL ) |
( (x >> 40) & 0x000000000000ff00UL ) |
( (x >> 56) & 0x00000000000000ffUL );
#else
/*
* Split the operation in two 32bit steps.
*/
u_int32_t tl, th;
th = bswap32((u_int32_t)(x & 0x00000000ffffffffULL));
tl = bswap32((u_int32_t)((x >> 32) & 0x00000000ffffffffULL));
return ((u_int64_t)th << 32) | tl;
#endif
}

19
StdLib/LibC/Main/errno.c Normal file
View File

@@ -0,0 +1,19 @@
/** @file
Instantiate errno as declared in <errno.h>.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
int errno = 0;
RETURN_STATUS EFIerrno = RETURN_SUCCESS;
// This is required to keep VC++ happy if you use floating-point
int _fltused = 1;
int __sse2_available = 0; ///< Used by ftol2_sse

View File

@@ -0,0 +1,20 @@
/* $NetBSD: infinityf_ieee754.c,v 1.2 2005/06/12 05:21:27 lukem Exp $ */
/*
* IEEE-compatible infinityf.c -- public domain.
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: infinityf_ieee754.c,v 1.2 2005/06/12 05:21:27 lukem Exp $");
#endif /* LIBC_SCCS and not lint */
#include <math.h>
#include <machine/endian.h>
const union __float_u __infinityf =
#if BYTE_ORDER == BIG_ENDIAN
{ { 0x7f, 0x80, 0, 0 } };
#else
{ { 0, 0, 0x80, 0x7f } };
#endif

View File

@@ -0,0 +1,68 @@
/* $NetBSD: isinfd_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isinfd_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
/* libc.so.12 ABI compatbility */
#ifdef __weak_alias
__weak_alias(isinf,__isinfd)
#endif
/*
* 7.12.3.3 isinf - test for infinity
* IEEE 754 double-precision version
*/
int
__isinfd(double x)
{
union ieee_double_u u;
u.dblu_d = x;
return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN &&
(u.dblu_dbl.dbl_frach == 0 && u.dblu_dbl.dbl_fracl == 0));
}

View File

@@ -0,0 +1,63 @@
/* $NetBSD: isinff_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isinff_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
/*
* 7.12.3.3 isinf - test for infinity
* IEEE 754 single-precision version
*/
int
__isinff(float x)
{
union ieee_single_u u;
u.sngu_f = x;
return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN &&
u.sngu_sng.sng_frac == 0);
}

View File

@@ -0,0 +1,68 @@
/* $NetBSD: isnand_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isnand_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
/* libc.so.12 ABI compatbility */
#ifdef __weak_alias
__weak_alias(isnan,__isnand)
#endif
/*
* 7.12.3.4 isnan - test for a NaN
* IEEE 754 double-precision version
*/
int
__isnand(double x)
{
union ieee_double_u u;
u.dblu_d = x;
return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN &&
(u.dblu_dbl.dbl_frach != 0 || u.dblu_dbl.dbl_fracl != 0));
}

View File

@@ -0,0 +1,63 @@
/* $NetBSD: isnanf_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: isnanf_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <machine/ieee.h>
#include <math.h>
/*
* 7.12.3.4 isnan - test for a NaN
* IEEE 754 single-precision version
*/
int
__isnanf(float x)
{
union ieee_single_u u;
u.sngu_f = x;
return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN &&
u.sngu_sng.sng_frac != 0);
}

View File

@@ -0,0 +1,20 @@
/** @file
The longjmp function.
The C standard requires that longjmp be a function and not a macro.
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
#include <setjmp.h>
void longjmp(jmp_buf env, int val)
{
LongJump(env, (UINTN)((val == 0) ? 1 : val));
}

View File

@@ -0,0 +1,23 @@
/** @file
Return the current FPU rounding mode.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
extern int internal_FPU_rmode( void );
static INT8 rmode[] = { 1, 3, 2, 0 };
int
EFIAPI
__flt_rounds ( void )
{
return rmode[ internal_FPU_rmode() ];
}

101
StdLib/LibC/Math/Math.inf Normal file
View File

@@ -0,0 +1,101 @@
## @file
# Standard C library: Math Library.
#
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = LibMath
FILE_GUID = a9dc6f60-f861-47d1-8751-ecaae7d27291
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = LibMath
#
# VALID_ARCHITECTURES = IA32 X64 IPF
#
[Sources]
# ieee 754 specific
e_acos.c
e_asin.c
e_atan2.c
e_cosh.c
e_exp.c
e_sinh.c
e_log.c
e_log2.c
e_log10.c
e_pow.c
e_sqrt.c
e_fmod.c
e_rem_pio2.c
# kernel functions
k_cos.c
k_sin.c
k_tan.c
k_rem_pio2.c
# Simple, unadorned, functions
s_atan.c
s_cos.c
s_sin.c
s_tan.c
s_expm1.c
s_tanh.c
s_frexp.c
s_ldexp.c
s_scalbn.c
s_copysign.c
s_finite.c
s_infinity.c
s_modf.c
s_fabs.c
s_ceil.c
s_floor.c
# wrapper functions
w_acos.c
w_asin.c
w_atan2.c
w_cosh.c
w_sinh.c
w_exp.c
w_log.c
w_log2.c
w_log10.c
w_pow.c
w_sqrt.c
w_fmod.c
[Packages]
StdLib/StdLib.dec
StdLibPrivateInternalFiles/DoNotUse.dec
MdePkg/MdePkg.dec
[LibraryClasses]
LibC
################################################################
# The Build Options, below, are only used when building the C library.
# DO NOT use them when building your application!
# Nasty things could happen if you do.
#
# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be
# defined in this library.
# /GL- is required so that LTCG generated references to functions in this library,
# such as memcpy(), can be resolved.
#
[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /Oi- /GL-

122
StdLib/LibC/Math/e_acos.c Normal file
View File

@@ -0,0 +1,122 @@
/** @file
Compute acos(x) using ieee FP math.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
e_acos.c 5.1 93/09/24
NetBSD: e_acos.c,v 1.12 2002/05/26 22:01:47 wiz Exp
*/
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// Keep older compilers quiet about floating-point divide-by-zero
#pragma warning ( disable : 4723 )
#endif
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
/* __ieee754_acos(x)
* Method :
* acos(x) = pi/2 - asin(x)
* acos(-x) = pi/2 + asin(x)
* For |x|<=0.5
* acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)
* For x>0.5
* acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
* = 2asin(sqrt((1-x)/2))
* = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
* = 2f + (2c + 2s*z*R(z))
* where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
* for f so that f+c ~ sqrt(z).
* For x<-0.5
* acos(x) = pi - 2asin(sqrt((1-|x|)/2))
* = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
*
* Special cases:
* if x is NaN, return x itself;
* if |x|>1, return NaN with invalid signal.
*
* Function needed: __ieee754_sqrt
*/
#include "math.h"
#include "math_private.h"
static const double
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
double
__ieee754_acos(double x)
{
double z,p,q,r,w,s,c,df;
int32_t hx,ix;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x3ff00000) { /* |x| >= 1 */
u_int32_t lx;
GET_LOW_WORD(lx,x);
if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */
if(hx>0) return 0.0; /* acos(1) = 0 */
else return pi+2.0*pio2_lo; /* acos(-1)= pi */
}
return (x-x)/(x-x); /* acos(|x|>1) is NaN */
}
if(ix<0x3fe00000) { /* |x| < 0.5 */
if(ix<=0x3c600000) return pio2_hi+pio2_lo; /*if|x|<2**-57*/
z = x*x;
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
r = p/q;
return pio2_hi - (x - (pio2_lo-x*r));
}
else if (hx<0) { /* x < -0.5 */
z = (one+x)*0.5;
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
s = __ieee754_sqrt(z);
r = p/q;
w = r*s-pio2_lo;
return pi - 2.0*(s+w);
}
else { /* x > 0.5 */
z = (one-x)*0.5;
s = __ieee754_sqrt(z);
df = s;
SET_LOW_WORD(df,0);
c = (z-df*df)/(s+df);
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
r = p/q;
w = r*s+c;
return 2.0*(df+w);
}
}

120
StdLib/LibC/Math/e_asin.c Normal file
View File

@@ -0,0 +1,120 @@
/* @(#)e_asin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_asin.c,v 1.12 2002/05/26 22:01:48 wiz Exp $");
#endif
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// C4723: potential divide by zero.
#pragma warning ( disable : 4723 )
#endif
/* __ieee754_asin(x)
* Method :
* Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
* we approximate asin(x) on [0,0.5] by
* asin(x) = x + x*x^2*R(x^2)
* where
* R(x^2) is a rational approximation of (asin(x)-x)/x^3
* and its remez error is bounded by
* |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
*
* For x in [0.5,1]
* asin(x) = pi/2-2*asin(sqrt((1-x)/2))
* Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
* then for x>0.98
* asin(x) = pi/2 - 2*(s+s*z*R(z))
* = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
* For x<=0.98, let pio4_hi = pio2_hi/2, then
* f = hi part of s;
* c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z)
* and
* asin(x) = pi/2 - 2*(s+s*z*R(z))
* = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
* = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
*
* Special cases:
* if x is NaN, return x itself;
* if |x|>1, return NaN with invalid signal.
*
*/
#include "math.h"
#include "math_private.h"
static const double
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
huge = 1.000e+300,
pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
/* coefficient for R(x^2) */
pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
double
__ieee754_asin(double x)
{
double t,w,p,q,c,r,s;
int32_t hx,ix;
t = 0;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>= 0x3ff00000) { /* |x|>= 1 */
u_int32_t lx;
GET_LOW_WORD(lx,x);
if(((ix-0x3ff00000)|lx)==0)
/* asin(1)=+-pi/2 with inexact */
return x*pio2_hi+x*pio2_lo;
return (x-x)/(x-x); /* asin(|x|>1) is NaN */
} else if (ix<0x3fe00000) { /* |x|<0.5 */
if(ix<0x3e400000) { /* if |x| < 2**-27 */
if(huge+x>one) return x;/* return x with inexact if x!=0*/
} else
t = x*x;
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
w = p/q;
return x+x*w;
}
/* 1> |x|>= 0.5 */
w = one-fabs(x);
t = w*0.5;
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
s = __ieee754_sqrt(t);
if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
w = p/q;
t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
} else {
w = s;
SET_LOW_WORD(w,0);
c = (t-w*w)/(s+w);
r = p/q;
p = 2.0*s*r-(pio2_lo-2.0*c);
q = pio4_hi-2.0*w;
t = pio4_hi-(p-q);
}
if(hx>0) return t; else return -t;
}

128
StdLib/LibC/Math/e_atan2.c Normal file
View File

@@ -0,0 +1,128 @@
/* @(#)e_atan2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_atan2.c,v 1.12 2002/05/26 22:01:48 wiz Exp $");
#endif
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// unary minus operator applied to unsigned type, result still unsigned
#pragma warning ( disable : 4146 )
#endif
/* __ieee754_atan2(y,x)
* Method :
* 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
* 2. Reduce x to positive by (if x and y are unexceptional):
* ARG (x+iy) = arctan(y/x) ... if x > 0,
* ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
*
* Special cases:
*
* ATAN2((anything), NaN ) is NaN;
* ATAN2(NAN , (anything) ) is NaN;
* ATAN2(+-0, +(anything but NaN)) is +-0 ;
* ATAN2(+-0, -(anything but NaN)) is +-pi ;
* ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
* ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
* ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
* ATAN2(+-INF,+INF ) is +-pi/4 ;
* ATAN2(+-INF,-INF ) is +-3pi/4;
* ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
#include "math.h"
#include "math_private.h"
static const double
tiny = 1.0e-300,
zero = 0.0,
pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
double
__ieee754_atan2(double y, double x)
{
double z;
int32_t k,m,hx,hy,ix,iy;
u_int32_t lx,ly;
EXTRACT_WORDS(hx,lx,x);
ix = hx&0x7fffffff;
EXTRACT_WORDS(hy,ly,y);
iy = hy&0x7fffffff;
if(((ix|((lx|-lx)>>31))>0x7ff00000)||
((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */
return x+y;
if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */
m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
/* when y = 0 */
if((iy|ly)==0) {
switch(m) {
case 0:
case 1: return y; /* atan(+-0,+anything)=+-0 */
case 2: return pi+tiny;/* atan(+0,-anything) = pi */
case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
}
}
/* when x = 0 */
if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
/* when x is INF */
if(ix==0x7ff00000) {
if(iy==0x7ff00000) {
switch(m) {
case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
}
} else {
switch(m) {
case 0: return zero ; /* atan(+...,+INF) */
case 1: return -zero ; /* atan(-...,+INF) */
case 2: return pi+tiny ; /* atan(+...,-INF) */
case 3: return -pi-tiny ; /* atan(-...,-INF) */
}
}
}
/* when y is INF */
if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
/* compute y/x */
k = (iy-ix)>>20;
if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */
else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
else z=atan(fabs(y/x)); /* safe to do y/x */
switch (m) {
case 0: return z ; /* atan(+,+) */
case 1: {
u_int32_t zh;
GET_HIGH_WORD(zh,z);
SET_HIGH_WORD(z,zh ^ 0x80000000);
}
return z ; /* atan(-,+) */
case 2: return pi-(z-pi_lo);/* atan(+,-) */
default: /* case 3 */
return (z-pi_lo)-pi;/* atan(-,-) */
}
}

91
StdLib/LibC/Math/e_cosh.c Normal file
View File

@@ -0,0 +1,91 @@
/* @(#)e_cosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_cosh.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");
#endif
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// C4756: overflow in constant arithmetic
#pragma warning ( disable : 4756 )
#endif
/* __ieee754_cosh(x)
* Method :
* mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
* 1. Replace x by |x| (cosh(x) = cosh(-x)).
* 2.
* [ exp(x) - 1 ]^2
* 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
* 2*exp(x)
*
* exp(x) + 1/exp(x)
* ln2/2 <= x <= 22 : cosh(x) := -------------------
* 2
* 22 <= x <= lnovft : cosh(x) := exp(x)/2
* lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
* ln2ovft < x : cosh(x) := huge*huge (overflow)
*
* Special cases:
* cosh(x) is |x| if x is +INF, -INF, or NaN.
* only cosh(0)=1 is exact for finite x.
*/
#include "math.h"
#include "math_private.h"
static const double one = 1.0, half=0.5, huge = 1.0e300;
double
__ieee754_cosh(double x)
{
double t,w;
int32_t ix;
u_int32_t lx;
/* High word of |x|. */
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
/* x is INF or NaN */
if(ix>=0x7ff00000) return x*x;
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
if(ix<0x3fd62e43) {
t = expm1(fabs(x));
w = one+t;
if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */
return one+(t*t)/(w+w);
}
/* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
if (ix < 0x40360000) {
t = __ieee754_exp(fabs(x));
return half*t+half/t;
}
/* |x| in [22, log(maxdouble)] return half*exp(|x|) */
if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x));
/* |x| in [log(maxdouble), overflowthresold] */
GET_LOW_WORD(lx,x);
if (ix<0x408633CE ||
((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
w = __ieee754_exp(half*fabs(x));
t = half*w;
return t*w;
}
/* |x| > overflowthresold, cosh(x) overflow */
return huge*huge;
}

167
StdLib/LibC/Math/e_exp.c Normal file
View File

@@ -0,0 +1,167 @@
/* @(#)e_exp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_exp.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");
#endif
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// C4756: overflow in constant arithmetic
#pragma warning ( disable : 4756 )
#endif
/* __ieee754_exp(x)
* Returns the exponential of x.
*
* Method
* 1. Argument reduction:
* Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
* Given x, find r and integer k such that
*
* x = k*ln2 + r, |r| <= 0.5*ln2.
*
* Here r will be represented as r = hi-lo for better
* accuracy.
*
* 2. Approximation of exp(r) by a special rational function on
* the interval [0,0.34658]:
* Write
* R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
* We use a special Reme algorithm on [0,0.34658] to generate
* a polynomial of degree 5 to approximate R. The maximum error
* of this polynomial approximation is bounded by 2**-59. In
* other words,
* R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
* (where z=r*r, and the values of P1 to P5 are listed below)
* and
* | 5 | -59
* | 2.0+P1*z+...+P5*z - R(z) | <= 2
* | |
* The computation of exp(r) thus becomes
* 2*r
* exp(r) = 1 + -------
* R - r
* r*R1(r)
* = 1 + r + ----------- (for better accuracy)
* 2 - R1(r)
* where
* 2 4 10
* R1(r) = r - (P1*r + P2*r + ... + P5*r ).
*
* 3. Scale back to obtain exp(x):
* From step 1, we have
* exp(x) = 2^k * exp(r)
*
* Special cases:
* exp(INF) is INF, exp(NaN) is NaN;
* exp(-INF) is 0, and
* for finite argument, only exp(0)=1 is exact.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Misc. info.
* For IEEE double
* if x > 7.09782712893383973096e+02 then exp(x) overflow
* if x < -7.45133219101941108420e+02 then exp(x) underflow
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
#include "math.h"
#include "math_private.h"
static const double
one = 1.0,
halF[2] = {0.5,-0.5,},
huge = 1.0e+300,
twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/
o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */
ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
-6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */
ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
-1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */
invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
double
__ieee754_exp(double x) /* default IEEE double exp */
{
double y,hi,lo,c,t;
int32_t k,xsb;
u_int32_t hx;
hi = lo = 0;
k = 0;
GET_HIGH_WORD(hx,x);
xsb = (hx>>31)&1; /* sign bit of x */
hx &= 0x7fffffff; /* high word of |x| */
/* filter out non-finite argument */
if(hx >= 0x40862E42) { /* if |x|>=709.78... */
if(hx>=0x7ff00000) {
u_int32_t lx;
GET_LOW_WORD(lx,x);
if(((hx&0xfffff)|lx)!=0)
return x+x; /* NaN */
else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
}
if(x > o_threshold) return huge*huge; /* overflow */
if(x < u_threshold) return twom1000*twom1000; /* underflow */
}
/* argument reduction */
if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
} else {
k = (int32_t)(invln2*x+halF[xsb]);
t = k;
hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
lo = t*ln2LO[0];
}
x = hi - lo;
}
else if(hx < 0x3e300000) { /* when |x|<2**-28 */
if(huge+x>one) return one+x;/* trigger inexact */
}
else k = 0;
/* x is now in primary range */
t = x*x;
c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
if(k==0) return one-((x*c)/(c-2.0)-x);
else y = one-((lo-(x*c)/(2.0-c))-hi);
if(k >= -1021) {
u_int32_t hy;
GET_HIGH_WORD(hy,y);
SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */
return y;
} else {
u_int32_t hy;
GET_HIGH_WORD(hy,y);
SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */
return y*twom1000;
}
}

138
StdLib/LibC/Math/e_fmod.c Normal file
View File

@@ -0,0 +1,138 @@
/* @(#)e_fmod.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_fmod.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");
#endif
/*
* __ieee754_fmod(x,y)
* Return x mod y in exact arithmetic
* Method: shift and subtract
*/
#include "math.h"
#include "math_private.h"
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// unary minus operator applied to unsigned type, result still unsigned
#pragma warning ( disable : 4146 )
#endif
static const double one = 1.0, Zero[] = {0.0, -0.0,};
double
__ieee754_fmod(double x, double y)
{
int32_t n,hx,hy,hz,ix,iy,sx,i;
u_int32_t lx,ly,lz;
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
sx = hx&0x80000000; /* sign of x */
hx ^=sx; /* |x| */
hy &= 0x7fffffff; /* |y| */
/* purge off exception values */
if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */
((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */
return (x*y)/(x*y);
if(hx<=hy) {
if((hx<hy)||(lx<ly)) return x; /* |x|<|y| return x */
if(lx==ly)
return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
}
/* determine ix = ilogb(x) */
if(hx<0x00100000) { /* subnormal x */
if(hx==0) {
for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
} else {
for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
}
} else ix = (hx>>20)-1023;
/* determine iy = ilogb(y) */
if(hy<0x00100000) { /* subnormal y */
if(hy==0) {
for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
} else {
for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
}
} else iy = (hy>>20)-1023;
/* set up {hx,lx}, {hy,ly} and align y to x */
if(ix >= -1022)
hx = 0x00100000|(0x000fffff&hx);
else { /* subnormal x, shift x to normal */
n = -1022-ix;
if(n<=31) {
hx = (hx<<n)|(lx>>(32-n));
lx <<= n;
} else {
hx = lx<<(n-32);
lx = 0;
}
}
if(iy >= -1022)
hy = 0x00100000|(0x000fffff&hy);
else { /* subnormal y, shift y to normal */
n = -1022-iy;
if(n<=31) {
hy = (hy<<n)|(ly>>(32-n));
ly <<= n;
} else {
hy = ly<<(n-32);
ly = 0;
}
}
/* fix point fmod */
n = ix - iy;
while(n--) {
hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
else {
if((hz|lz)==0) /* return sign(x)*0 */
return Zero[(u_int32_t)sx>>31];
hx = hz+hz+(lz>>31); lx = lz+lz;
}
}
hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
if(hz>=0) {hx=hz;lx=lz;}
/* convert back to floating value and restore the sign */
if((hx|lx)==0) /* return sign(x)*0 */
return Zero[(u_int32_t)sx>>31];
while(hx<0x00100000) { /* normalize x */
hx = hx+hx+(lx>>31); lx = lx+lx;
iy -= 1;
}
if(iy>= -1022) { /* normalize output */
hx = ((hx-0x00100000)|((iy+1023)<<20));
INSERT_WORDS(x,hx|sx,lx);
} else { /* subnormal output */
n = -1022 - iy;
if(n<=20) {
lx = (lx>>n)|((u_int32_t)hx<<(32-n));
hx >>= n;
} else if (n<=31) {
lx = (hx<<(32-n))|(lx>>n); hx = sx;
} else {
lx = hx>>(n-32); hx = sx;
}
INSERT_WORDS(x,hx|sx,lx);
x *= one; /* create necessary signal */
}
return x; /* exact output */
}

155
StdLib/LibC/Math/e_log.c Normal file
View File

@@ -0,0 +1,155 @@
/** @file
Compute the logrithm of x.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
e_log.c 5.1 93/09/24
NetBSD: e_log.c,v 1.12 2002/05/26 22:01:51 wiz Exp
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// potential divide by 0 -- near line 118, (x-x)/zero is on purpose
#pragma warning ( disable : 4723 )
#endif
/* __ieee754_log(x)
* Return the logrithm of x
*
* Method :
* 1. Argument Reduction: find k and f such that
* x = 2^k * (1+f),
* where sqrt(2)/2 < 1+f < sqrt(2) .
*
* 2. Approximation of log(1+f).
* Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
* = 2s + 2/3 s**3 + 2/5 s**5 + .....,
* = 2s + s*R
* We use a special Reme algorithm on [0,0.1716] to generate
* a polynomial of degree 14 to approximate R The maximum error
* of this polynomial approximation is bounded by 2**-58.45. In
* other words,
* 2 4 6 8 10 12 14
* R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
* (the values of Lg1 to Lg7 are listed in the program)
* and
* | 2 14 | -58.45
* | Lg1*s +...+Lg7*s - R(z) | <= 2
* | |
* Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
* In order to guarantee error in log below 1ulp, we compute log
* by
* log(1+f) = f - s*(f - R) (if f is not too large)
* log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
*
* 3. Finally, log(x) = k*ln2 + log(1+f).
* = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
* Here ln2 is split into two floating point number:
* ln2_hi + ln2_lo,
* where n*ln2_hi is always exact for |n| < 2000.
*
* Special cases:
* log(x) is NaN with signal if x < 0 (including -INF) ;
* log(+INF) is +INF; log(0) is -INF with signal;
* log(NaN) is that NaN with no signal.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
#include "math.h"
#include "math_private.h"
#include <errno.h>
static const double
ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
static const double zero = 0.0;
double
__ieee754_log(double x)
{
double hfsq,f,s,z,R,w,t1,t2,dk;
int32_t k,hx,i,j;
u_int32_t lx;
EXTRACT_WORDS(hx,lx,x);
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) {
errno = EDOM;
return (x-x)/zero; /* log(-#) = NaN */
}
k -= 54; x *= two54; /* subnormal number, scale up x */
GET_HIGH_WORD(hx,x);
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
hx &= 0x000fffff;
i = (hx+0x95f64)&0x100000;
SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
k += (i>>20);
f = x-1.0;
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
if(f==zero) { if(k==0) return zero; else {dk=(double)k;
return dk*ln2_hi+dk*ln2_lo;}
}
R = f*f*(0.5-0.33333333333333333*f);
if(k==0) return f-R; else {dk=(double)k;
return dk*ln2_hi-((R-dk*ln2_lo)-f);}
}
s = f/(2.0+f);
dk = (double)k;
z = s*s;
i = hx-0x6147a;
w = z*z;
j = 0x6b851-hx;
t1= w*(Lg2+w*(Lg4+w*Lg6));
t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
i |= j;
R = t2+t1;
if(i>0) {
hfsq=0.5*f*f;
if(k==0) return f-(hfsq-s*(hfsq+R)); else
return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
} else {
if(k==0) return f-s*(f-R); else
return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
}
}

106
StdLib/LibC/Math/e_log10.c Normal file
View File

@@ -0,0 +1,106 @@
/** @file
Compute the base 10 logrithm of x.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
e_log10.c 5.1 93/09/24
NetBSD: e_log10.c,v 1.12 2002/05/26 22:01:51 wiz Exp
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
/* __ieee754_log10(x)
* Return the base 10 logarithm of x
*
* Method :
* Let log10_2hi = leading 40 bits of log10(2) and
* log10_2lo = log10(2) - log10_2hi,
* ivln10 = 1/log(10) rounded.
* Then
* n = ilogb(x),
* if(n<0) n = n+1;
* x = scalbn(x,-n);
* log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
*
* Note 1:
* To guarantee log10(10**n)=n, where 10**n is normal, the rounding
* mode must set to Round-to-Nearest.
* Note 2:
* [1/log(10)] rounded to 53 bits has error .198 ulps;
* log10 is monotonic at all binary break points.
*
* Special cases:
* log10(x) is NaN with signal if x < 0;
* log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
* log10(NaN) is that NaN with no signal;
* log10(10**N) = N for N=0,1,...,22.
*
* Constants:
* The hexadecimal values are the intended ones for the following constants.
* The decimal values may be used, provided that the compiler will convert
* from decimal to binary accurately enough to produce the hexadecimal values
* shown.
*/
#include "math.h"
#include "math_private.h"
#include <errno.h>
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// potential divide by 0 -- near line 80, (x-x)/zero is on purpose
#pragma warning ( disable : 4723 )
#endif
static const double
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
static const double zero = 0.0;
double
__ieee754_log10(double x)
{
double y,z;
int32_t i,k,hx;
u_int32_t lx;
EXTRACT_WORDS(hx,lx,x);
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) {
errno = EDOM;
return (x-x)/zero; /* log(-#) = NaN */
}
k -= 54; x *= two54; /* subnormal number, scale up x */
GET_HIGH_WORD(hx,x);
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
i = ((u_int32_t)k&0x80000000)>>31;
hx = (hx&0x000fffff)|((0x3ff-i)<<20);
y = (double)(k+i);
SET_HIGH_WORD(x,hx);
z = y*log10_2lo + ivln10*__ieee754_log(x);
return z+y*log10_2hi;
}

85
StdLib/LibC/Math/e_log2.c Normal file
View File

@@ -0,0 +1,85 @@
/* @(#)e_log.c 1.3 95/01/18 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunSoft, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_log2.c,v 1.1 2005/07/21 12:55:58 christos Exp $");
#endif
#include "math.h"
#include "math_private.h"
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// potential divide by 0 -- near line 53, (x-x)/zero is on purpose
#pragma warning ( disable : 4723 )
#endif
static const double
ln2 = 0.6931471805599452862268,
two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
static const double zero = 0.0;
double
__ieee754_log2(double x)
{
double hfsq,f,s,z,R,w,t1,t2,dk;
int32_t k,hx,i,j;
u_int32_t lx;
EXTRACT_WORDS(hx,lx,x);
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 54; x *= two54; /* subnormal number, scale up x */
GET_HIGH_WORD(hx,x);
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
hx &= 0x000fffff;
i = (hx+0x95f64)&0x100000;
SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
k += (i>>20);
f = x-1.0;
dk = (double)k;
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
if (f==zero)
return (dk);
R = f*f*(0.5-0.33333333333333333*f);
return (dk-(R-f)/ln2);
}
s = f/(2.0+f);
z = s*s;
i = hx-0x6147a;
w = z*z;
j = 0x6b851-hx;
t1= w*(Lg2+w*(Lg4+w*Lg6));
t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
i |= j;
R = t2+t1;
if(i>0) {
hfsq=0.5*f*f;
return (dk-(hfsq-s*(hfsq+R)-f)/ln2);
} else
return (dk-((s*(f-R))-f)/ln2);
}

323
StdLib/LibC/Math/e_pow.c Normal file
View File

@@ -0,0 +1,323 @@
/** @file
Compute the base 10 logrithm of x.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
e_pow.c 5.1 93/09/24
NetBSD: e_pow.c,v 1.13 2004/06/30 18:43:15 drochner Exp
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// C4723: potential divide by zero.
#pragma warning ( disable : 4723 )
// C4756: overflow in constant arithmetic
#pragma warning ( disable : 4756 )
#endif
/* __ieee754_pow(x,y) return x**y
*
* n
* Method: Let x = 2 * (1+f)
* 1. Compute and return log2(x) in two pieces:
* log2(x) = w1 + w2,
* where w1 has 53-24 = 29 bit trailing zeros.
* 2. Perform y*log2(x) = n+y' by simulating multi-precision
* arithmetic, where |y'|<=0.5.
* 3. Return x**y = 2**n*exp(y'*log2)
*
* Special cases:
* 1. (anything) ** 0 is 1
* 2. (anything) ** 1 is itself
* 3. (anything) ** NAN is NAN
* 4. NAN ** (anything except 0) is NAN
* 5. +-(|x| > 1) ** +INF is +INF
* 6. +-(|x| > 1) ** -INF is +0
* 7. +-(|x| < 1) ** +INF is +0
* 8. +-(|x| < 1) ** -INF is +INF
* 9. +-1 ** +-INF is NAN
* 10. +0 ** (+anything except 0, NAN) is +0
* 11. -0 ** (+anything except 0, NAN, odd integer) is +0
* 12. +0 ** (-anything except 0, NAN) is +INF
* 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
* 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
* 15. +INF ** (+anything except 0,NAN) is +INF
* 16. +INF ** (-anything except 0,NAN) is +0
* 17. -INF ** (anything) = -0 ** (-anything)
* 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
* 19. (-anything except 0 and inf) ** (non-integer) is NAN
*
* Accuracy:
* pow(x,y) returns x**y nearly rounded. In particular
* pow(integer,integer)
* always returns the correct integer provided it is
* representable.
*
* Constants :
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
#include "math.h"
#include "math_private.h"
#include <errno.h>
static const double
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
zero = 0.0,
one = 1.0,
two = 2.0,
two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
huge = 1.0e300,
tiny = 1.0e-300,
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
double
__ieee754_pow(double x, double y)
{
double z,ax,z_h,z_l,p_h,p_l;
double y1,t1,t2,r,s,t,u,v,w;
int32_t i,j,k,yisint,n;
int32_t hx,hy,ix,iy;
u_int32_t lx,ly;
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
/* y==zero: x**0 = 1 */
if((iy|ly)==0) return one;
/* +-NaN return x+y */
if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
return x+y;
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if(hx<0) {
if(iy>=0x43400000) yisint = 2; /* even integer y */
else if(iy>=0x3ff00000) {
k = (iy>>20)-0x3ff; /* exponent */
if(k>20) {
j = ly>>(52-k);
if((u_int32_t)(j<<(52-k))==ly) yisint = 2-(j&1);
} else if(ly==0) {
j = iy>>(20-k);
if((j<<(20-k))==iy) yisint = 2-(j&1);
}
}
}
/* special value of y */
if(ly==0) {
if (iy==0x7ff00000) { /* y is +-inf */
if(((ix-0x3ff00000)|lx)==0)
return y - y; /* inf**+-1 is NaN */
else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zero;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy<0)?-y: zero;
}
if(iy==0x3ff00000) { /* y is +-1 */
if(hy<0) return one/x; else return x;
}
if(hy==0x40000000) return x*x; /* y is 2 */
if(hy==0x3fe00000) { /* y is 0.5 */
if(hx>=0) /* x >= +0 */
return __ieee754_sqrt(x);
}
}
ax = fabs(x);
/* special value of x */
if(lx==0) {
if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
z = ax; /*x is +-0,+-inf,+-1*/
if(hy<0) z = one/z; /* z = (1/|x|) */
if(hx<0) {
if(((ix-0x3ff00000)|yisint)==0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
} else if(yisint==1)
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
return z;
}
}
n = (hx>>31)+1;
/* (x<0)**(non-int) is NaN */
if((n|yisint)==0) {
errno = EDOM;
return (x-x)/(x-x);
}
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */
/* |y| is huge */
if(iy>0x41e00000) { /* if |y| > 2**31 */
if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
}
/* over/underflow if x is not close to one */
if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny;
if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny;
/* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = ax-one; /* t has 20 trailing zeros */
w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
SET_LOW_WORD(t1,0);
t2 = v-(t1-u);
} else {
double ss,s2,s_h,s_l,t_h,t_l;
n = 0;
/* take care subnormal number */
if(ix<0x00100000)
{ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
n += ((ix)>>20)-0x3ff;
j = ix&0x000fffff;
/* determine interval */
ix = j|0x3ff00000; /* normalize ix */
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
else {k=0;n+=1;ix -= 0x00100000;}
SET_HIGH_WORD(ax,ix);
/* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one/(ax+bp[k]);
ss = u*v;
s_h = ss;
SET_LOW_WORD(s_h,0);
/* t_h=ax+bp[k] High */
t_h = zero;
SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
t_l = ax - (t_h-bp[k]);
s_l = v*((u-s_h*t_h)-s_h*t_l);
/* compute log(ax) */
s2 = ss*ss;
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
r += s_l*(s_h+ss);
s2 = s_h*s_h;
t_h = 3.0+s2+r;
SET_LOW_WORD(t_h,0);
t_l = r-((t_h-3.0)-s2);
/* u+v = ss*(1+...) */
u = s_h*t_h;
v = s_l*t_h+t_l*ss;
/* 2/(3log2)*(ss+...) */
p_h = u+v;
SET_LOW_WORD(p_h,0);
p_l = v-(p_h-u);
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l*p_h+p_l*cp+dp_l[k];
/* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */
t = (double)n;
t1 = (((z_h+z_l)+dp_h[k])+t);
SET_LOW_WORD(t1,0);
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
}
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
y1 = y;
SET_LOW_WORD(y1,0);
p_l = (y-y1)*t1+y*t2;
p_h = y1*t1;
z = p_l+p_h;
EXTRACT_WORDS(j,i,z);
if (j>=0x40900000) { /* z >= 1024 */
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
return s*huge*huge; /* overflow */
else {
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
}
} else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
return s*tiny*tiny; /* underflow */
else {
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
}
/*
* compute 2**(p_h+p_l)
*/
i = j&0x7fffffff;
k = (i>>20)-0x3ff;
n = 0;
if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j+(0x00100000>>(k+1));
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
t = zero;
SET_HIGH_WORD(t,n&~(0x000fffff>>k));
n = ((n&0x000fffff)|0x00100000)>>(20-k);
if(j<0) n = -n;
p_h -= t;
}
t = p_l+p_h;
SET_LOW_WORD(t,0);
u = t*lg2_h;
v = (p_l-(t-p_h))*lg2+t*lg2_l;
z = u+v;
w = v-(z-u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
r = (z*t1)/(t1-two)-(w+z*w);
z = one-(r-z);
GET_HIGH_WORD(j,z);
j += (n<<20);
if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */
else SET_HIGH_WORD(z,j);
return s*z;
}

View File

@@ -0,0 +1,169 @@
/* @(#)e_rem_pio2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_rem_pio2.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");
#endif
/* __ieee754_rem_pio2(x,y)
*
* return the remainder of x rem pi/2 in y[0]+y[1]
* use __kernel_rem_pio2()
*/
#include "math.h"
#include "math_private.h"
/*
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
*/
static const int32_t two_over_pi[] = {
0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
};
static const int32_t npio2_hw[] = {
0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
0x404858EB, 0x404921FB,
};
/*
* invpio2: 53 bits of 2/pi
* pio2_1: first 33 bit of pi/2
* pio2_1t: pi/2 - pio2_1
* pio2_2: second 33 bit of pi/2
* pio2_2t: pi/2 - (pio2_1+pio2_2)
* pio2_3: third 33 bit of pi/2
* pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
*/
static const double
zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
int32_t
__ieee754_rem_pio2(double x, double *y)
{
double z,w,t,r,fn;
double tx[3];
int32_t e0,i,j,nx,n,ix,hx;
u_int32_t low;
z = 0;
GET_HIGH_WORD(hx,x); /* high word of x */
ix = hx&0x7fffffff;
if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
{y[0] = x; y[1] = 0; return 0;}
if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */
if(hx>0) {
z = x - pio2_1;
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
y[0] = z - pio2_1t;
y[1] = (z-y[0])-pio2_1t;
} else { /* near pi/2, use 33+33+53 bit pi */
z -= pio2_2;
y[0] = z - pio2_2t;
y[1] = (z-y[0])-pio2_2t;
}
return 1;
} else { /* negative x */
z = x + pio2_1;
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
y[0] = z + pio2_1t;
y[1] = (z-y[0])+pio2_1t;
} else { /* near pi/2, use 33+33+53 bit pi */
z += pio2_2;
y[0] = z + pio2_2t;
y[1] = (z-y[0])+pio2_2t;
}
return -1;
}
}
if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
t = fabs(x);
n = (int32_t) (t*invpio2+half);
fn = (double)n;
r = t-fn*pio2_1;
w = fn*pio2_1t; /* 1st round good to 85 bit */
if(n<32&&ix!=npio2_hw[n-1]) {
y[0] = r-w; /* quick check no cancellation */
} else {
u_int32_t high;
j = ix>>20;
y[0] = r-w;
GET_HIGH_WORD(high,y[0]);
i = j-((high>>20)&0x7ff);
if(i>16) { /* 2nd iteration needed, good to 118 */
t = r;
w = fn*pio2_2;
r = t-w;
w = fn*pio2_2t-((t-r)-w);
y[0] = r-w;
GET_HIGH_WORD(high,y[0]);
i = j-((high>>20)&0x7ff);
if(i>49) { /* 3rd iteration need, 151 bits acc */
t = r; /* will cover all possible cases */
w = fn*pio2_3;
r = t-w;
w = fn*pio2_3t-((t-r)-w);
y[0] = r-w;
}
}
}
y[1] = (r-y[0])-w;
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
/*
* all other (large) arguments
*/
if(ix>=0x7ff00000) { /* x is inf or NaN */
y[0]=y[1]=x-x; return 0;
}
/* set z = scalbn(|x|,ilogb(x)-23) */
GET_LOW_WORD(low,x);
SET_LOW_WORD(z,low);
e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));
for(i=0;i<2;i++) {
tx[i] = (double)((int32_t)(z));
z = (z-tx[i])*two24;
}
tx[2] = z;
nx = 3;
while(tx[nx-1]==zero) nx--; /* skip zero term */
n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
return n;
}

79
StdLib/LibC/Math/e_sinh.c Normal file
View File

@@ -0,0 +1,79 @@
/* @(#)e_sinh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: e_sinh.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");
#endif
#include "math.h"
#include "math_private.h"
/* __ieee754_sinh(x)
* Method :
* mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
* 1. Replace x by |x| (sinh(-x) = -sinh(x)).
* 2.
* E + E/(E+1)
* 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
* 2
*
* 22 <= x <= lnovft : sinh(x) := exp(x)/2
* lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
* ln2ovft < x : sinh(x) := x*shuge (overflow)
*
* Special cases:
* sinh(x) is |x| if x is +INF, -INF, or NaN.
* only sinh(0)=0 is exact for finite x.
*/
static const double one = 1.0, shuge = 1.0e307;
double
__ieee754_sinh(double x)
{
double t,w,h;
int32_t ix,jx;
u_int32_t lx;
/* High word of |x|. */
GET_HIGH_WORD(jx,x);
ix = jx&0x7fffffff;
/* x is INF or NaN */
if(ix>=0x7ff00000) return x+x;
h = 0.5;
if (jx<0) h = -h;
/* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
if (ix < 0x40360000) { /* |x|<22 */
if (ix<0x3e300000) /* |x|<2**-28 */
if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
t = expm1(fabs(x));
if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
return h*(t+t/(t+one));
}
/* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
/* |x| in [log(maxdouble), overflowthresold] */
GET_LOW_WORD(lx,x);
if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
w = __ieee754_exp(0.5*fabs(x));
t = h*w;
return t*w;
}
/* |x| > overflowthresold, sinh(x) overflow */
return x*shuge;
}

464
StdLib/LibC/Math/e_sqrt.c Normal file
View File

@@ -0,0 +1,464 @@
/** @file
Compute the logrithm of x.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
e_sqrt.c 5.1 93/09/24
NetBSD: e_sqrt.c,v 1.12 2002/05/26 22:01:52 wiz Exp
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#include <errno.h>
#include "math.h"
#include "math_private.h"
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// potential divide by 0 -- near line 129, (x-x)/(x-x) is on purpose
#pragma warning ( disable : 4723 )
#endif
/* __ieee754_sqrt(x)
* Return correctly rounded sqrt.
* ------------------------------------------
* | Use the hardware sqrt if you have one |
* ------------------------------------------
* Method:
* Bit by bit method using integer arithmetic. (Slow, but portable)
* 1. Normalization
* Scale x to y in [1,4) with even powers of 2:
* find an integer k such that 1 <= (y=x*2^(2k)) < 4, then
* sqrt(x) = 2^k * sqrt(y)
* 2. Bit by bit computation
* Let q = sqrt(y) truncated to i bit after binary point (q = 1),
* i 0
* i+1 2
* s = 2*q , and y = 2 * ( y - q ). (1)
* i i i i
*
* To compute q from q , one checks whether
* i+1 i
*
* -(i+1) 2
* (q + 2 ) <= y. (2)
* i
* -(i+1)
* If (2) is false, then q = q ; otherwise q = q + 2 .
* i+1 i i+1 i
*
* With some algebric manipulation, it is not difficult to see
* that (2) is equivalent to
* -(i+1)
* s + 2 <= y (3)
* i i
*
* The advantage of (3) is that s and y can be computed by
* i i
* the following recurrence formula:
* if (3) is false
*
* s = s , y = y ; (4)
* i+1 i i+1 i
*
* otherwise,
* -i -(i+1)
* s = s + 2 , y = y - s - 2 (5)
* i+1 i i+1 i i
*
* One may easily use induction to prove (4) and (5).
* Note. Since the left hand side of (3) contain only i+2 bits,
* it does not necessary to do a full (53-bit) comparison
* in (3).
* 3. Final rounding
* After generating the 53 bits result, we compute one more bit.
* Together with the remainder, we can decide whether the
* result is exact, bigger than 1/2ulp, or less than 1/2ulp
* (it will never equal to 1/2ulp).
* The rounding mode can be detected by checking whether
* huge + tiny is equal to huge, and whether huge - tiny is
* equal to huge for some floating point number "huge" and "tiny".
*
* Special cases:
* sqrt(+-0) = +-0 ... exact
* sqrt(inf) = inf
* sqrt(-ve) = NaN ... with invalid signal
* sqrt(NaN) = NaN ... with invalid signal for signaling NaN
*
* Other methods : see the appended file at the end of the program below.
*---------------
*/
static const double one = 1.0, tiny=1.0e-300;
double
__ieee754_sqrt(double x)
{
double z;
int32_t sign = (int)0x80000000;
int32_t ix0,s0,q,m,t,i;
u_int32_t r,t1,s1,ix1,q1;
EXTRACT_WORDS(ix0,ix1,x);
/* take care of Inf and NaN */
if((ix0&0x7ff00000)==0x7ff00000) {
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
sqrt(-inf)=sNaN */
}
/* take care of zero */
if(ix0<=0) {
if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
else if(ix0<0) {
errno = EDOM;
return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
}
}
/* normalize x */
m = (ix0>>20);
if(m==0) { /* subnormal x */
while(ix0==0) {
m -= 21;
ix0 |= (ix1>>11); ix1 <<= 21;
}
for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
m -= i-1;
ix0 |= (ix1>>(32-i));
ix1 <<= i;
}
m -= 1023; /* unbias exponent */
ix0 = (ix0&0x000fffff)|0x00100000;
if(m&1){ /* odd m, double x to make it even */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
}
m >>= 1; /* m = [m/2] */
/* generate sqrt(x) bit by bit */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
r = 0x00200000; /* r = moving bit from right to left */
while(r!=0) {
t = s0+r;
if(t<=ix0) {
s0 = t+r;
ix0 -= t;
q += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
r = sign;
while(r!=0) {
t1 = s1+r;
t = s0;
if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
s1 = t1+r;
if(((t1&sign)==(u_int32_t)sign)&&(s1&sign)==0) s0 += 1;
ix0 -= t;
if (ix1 < t1) ix0 -= 1;
ix1 -= t1;
q1 += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
/* use floating add to find out rounding direction */
if((ix0|ix1)!=0) {
z = one-tiny; /* trigger inexact flag */
if (z>=one) {
z = one+tiny;
if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
else if (z>one) {
if (q1==(u_int32_t)0xfffffffe) q+=1;
q1+=2;
} else
q1 += (q1&1);
}
}
ix0 = (q>>1)+0x3fe00000;
ix1 = q1>>1;
if ((q&1)==1) ix1 |= sign;
ix0 += (m <<20);
INSERT_WORDS(z,ix0,ix1);
return z;
}
/*
Other methods (use floating-point arithmetic)
-------------
(This is a copy of a drafted paper by Prof W. Kahan
and K.C. Ng, written in May, 1986)
Two algorithms are given here to implement sqrt(x)
(IEEE double precision arithmetic) in software.
Both supply sqrt(x) correctly rounded. The first algorithm (in
Section A) uses newton iterations and involves four divisions.
The second one uses reciproot iterations to avoid division, but
requires more multiplications. Both algorithms need the ability
to chop results of arithmetic operations instead of round them,
and the INEXACT flag to indicate when an arithmetic operation
is executed exactly with no roundoff error, all part of the
standard (IEEE 754-1985). The ability to perform shift, add,
subtract and logical AND operations upon 32-bit words is needed
too, though not part of the standard.
A. sqrt(x) by Newton Iteration
(1) Initial approximation
Let x0 and x1 be the leading and the trailing 32-bit words of
a floating point number x (in IEEE double format) respectively
1 11 52 ...widths
------------------------------------------------------
x: |s| e | f |
------------------------------------------------------
msb lsb msb lsb ...order
------------------------ ------------------------
x0: |s| e | f1 | x1: | f2 |
------------------------ ------------------------
By performing shifts and subtracts on x0 and x1 (both regarded
as integers), we obtain an 8-bit approximation of sqrt(x) as
follows.
k := (x0>>1) + 0x1ff80000;
y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits
Here k is a 32-bit integer and T1[] is an integer array containing
correction terms. Now magically the floating value of y (y's
leading 32-bit word is y0, the value of its trailing word is 0)
approximates sqrt(x) to almost 8-bit.
Value of T1:
static int T1[32]= {
0, 1024, 3062, 5746, 9193, 13348, 18162, 23592,
29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215,
83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581,
16499, 12183, 8588, 5674, 3403, 1742, 661, 130,};
(2) Iterative refinement
Apply Heron's rule three times to y, we have y approximates
sqrt(x) to within 1 ulp (Unit in the Last Place):
y := (y+x/y)/2 ... almost 17 sig. bits
y := (y+x/y)/2 ... almost 35 sig. bits
y := y-(y-x/y)/2 ... within 1 ulp
Remark 1.
Another way to improve y to within 1 ulp is:
y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x)
y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x)
2
(x-y )*y
y := y + 2* ---------- ...within 1 ulp
2
3y + x
This formula has one division fewer than the one above; however,
it requires more multiplications and additions. Also x must be
scaled in advance to avoid spurious overflow in evaluating the
expression 3y*y+x. Hence it is not recommended uless division
is slow. If division is very slow, then one should use the
reciproot algorithm given in section B.
(3) Final adjustment
By twiddling y's last bit it is possible to force y to be
correctly rounded according to the prevailing rounding mode
as follows. Let r and i be copies of the rounding mode and
inexact flag before entering the square root program. Also we
use the expression y+-ulp for the next representable floating
numbers (up and down) of y. Note that y+-ulp = either fixed
point y+-1, or multiply y by nextafter(1,+-inf) in chopped
mode.
I := FALSE; ... reset INEXACT flag I
R := RZ; ... set rounding mode to round-toward-zero
z := x/y; ... chopped quotient, possibly inexact
If(not I) then { ... if the quotient is exact
if(z=y) {
I := i; ... restore inexact flag
R := r; ... restore rounded mode
return sqrt(x):=y.
} else {
z := z - ulp; ... special rounding
}
}
i := TRUE; ... sqrt(x) is inexact
If (r=RN) then z=z+ulp ... rounded-to-nearest
If (r=RP) then { ... round-toward-+inf
y = y+ulp; z=z+ulp;
}
y := y+z; ... chopped sum
y0:=y0-0x00100000; ... y := y/2 is correctly rounded.
I := i; ... restore inexact flag
R := r; ... restore rounded mode
return sqrt(x):=y.
(4) Special cases
Square root of +inf, +-0, or NaN is itself;
Square root of a negative number is NaN with invalid signal.
B. sqrt(x) by Reciproot Iteration
(1) Initial approximation
Let x0 and x1 be the leading and the trailing 32-bit words of
a floating point number x (in IEEE double format) respectively
(see section A). By performing shifs and subtracts on x0 and y0,
we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.
k := 0x5fe80000 - (x0>>1);
y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits
Here k is a 32-bit integer and T2[] is an integer array
containing correction terms. Now magically the floating
value of y (y's leading 32-bit word is y0, the value of
its trailing word y1 is set to zero) approximates 1/sqrt(x)
to almost 7.8-bit.
Value of T2:
static int T2[64]= {
0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866,
0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f,
0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d,
0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0,
0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989,
0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd,
0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e,
0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,};
(2) Iterative refinement
Apply Reciproot iteration three times to y and multiply the
result by x to get an approximation z that matches sqrt(x)
to about 1 ulp. To be exact, we will have
-1ulp < sqrt(x)-z<1.0625ulp.
... set rounding mode to Round-to-nearest
y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x)
y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x)
... special arrangement for better accuracy
z := x*y ... 29 bits to sqrt(x), with z*y<1
z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x)
Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that
(a) the term z*y in the final iteration is always less than 1;
(b) the error in the final result is biased upward so that
-1 ulp < sqrt(x) - z < 1.0625 ulp
instead of |sqrt(x)-z|<1.03125ulp.
(3) Final adjustment
By twiddling y's last bit it is possible to force y to be
correctly rounded according to the prevailing rounding mode
as follows. Let r and i be copies of the rounding mode and
inexact flag before entering the square root program. Also we
use the expression y+-ulp for the next representable floating
numbers (up and down) of y. Note that y+-ulp = either fixed
point y+-1, or multiply y by nextafter(1,+-inf) in chopped
mode.
R := RZ; ... set rounding mode to round-toward-zero
switch(r) {
case RN: ... round-to-nearest
if(x<= z*(z-ulp)...chopped) z = z - ulp; else
if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp;
break;
case RZ:case RM: ... round-to-zero or round-to--inf
R:=RP; ... reset rounding mod to round-to-+inf
if(x<z*z ... rounded up) z = z - ulp; else
if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp;
break;
case RP: ... round-to-+inf
if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else
if(x>z*z ...chopped) z = z+ulp;
break;
}
Remark 3. The above comparisons can be done in fixed point. For
example, to compare x and w=z*z chopped, it suffices to compare
x1 and w1 (the trailing parts of x and w), regarding them as
two's complement integers.
...Is z an exact square root?
To determine whether z is an exact square root of x, let z1 be the
trailing part of z, and also let x0 and x1 be the leading and
trailing parts of x.
If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0
I := 1; ... Raise Inexact flag: z is not exact
else {
j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2
k := z1 >> 26; ... get z's 25-th and 26-th
fraction bits
I := i or (k&j) or ((k&(j+j+1))!=(x1&3));
}
R:= r ... restore rounded mode
return sqrt(x):=z.
If multiplication is cheaper than the foregoing red tape, the
Inexact flag can be evaluated by
I := i;
I := (z*z!=x) or I.
Note that z*z can overwrite I; this value must be sensed if it is
True.
Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be
zero.
--------------------
z1: | f2 |
--------------------
bit 31 bit 0
Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd
or even of logb(x) have the following relations:
-------------------------------------------------
bit 27,26 of z1 bit 1,0 of x1 logb(x)
-------------------------------------------------
00 00 odd and even
01 01 even
10 10 odd
10 00 even
11 01 even
-------------------------------------------------
(4) Special cases (see (4) of Section A).
*/

89
StdLib/LibC/Math/k_cos.c Normal file
View File

@@ -0,0 +1,89 @@
/* @(#)k_cos.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: k_cos.c,v 1.11 2002/05/26 22:01:53 wiz Exp $");
#endif
/*
* __kernel_cos( x, y )
* kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
*
* Algorithm
* 1. Since cos(-x) = cos(x), we need only to consider positive x.
* 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
* 3. cos(x) is approximated by a polynomial of degree 14 on
* [0,pi/4]
* 4 14
* cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
* where the remez error is
*
* | 2 4 6 8 10 12 14 | -58
* |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
* | |
*
* 4 6 8 10 12 14
* 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
* cos(x) = 1 - x*x/2 + r
* since cos(x+y) ~ cos(x) - sin(x)*y
* ~ cos(x) - x*y,
* a correction term is necessary in cos(x) and hence
* cos(x+y) = 1 - (x*x/2 - (r - x*y))
* For better accuracy when x > 0.3, let qx = |x|/4 with
* the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.
* Then
* cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).
* Note that 1-qx and (x*x/2-qx) is EXACT here, and the
* magnitude of the latter is at least a quarter of x*x/2,
* thus, reducing the rounding error in the subtraction.
*/
#include "math.h"
#include "math_private.h"
static const double
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
double
__kernel_cos(double x, double y)
{
double a,hz,z,r,qx;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff; /* ix = |x|'s high word*/
if(ix<0x3e400000) { /* if x < 2**27 */
if(((int)x)==0) return one; /* generate inexact */
}
z = x*x;
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
if(ix < 0x3FD33333) /* if |x| < 0.3 */
return one - (0.5*z - (z*r - x*y));
else {
if(ix > 0x3fe90000) { /* x > 0.78125 */
qx = 0.28125;
} else {
INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */
}
hz = 0.5*z-qx;
a = one-qx;
return a - (hz - (z*r-x*y));
}
}

View File

@@ -0,0 +1,305 @@
/* @(#)k_rem_pio2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: k_rem_pio2.c,v 1.11 2003/01/04 23:43:03 wiz Exp $");
#endif
/*
* __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
* double x[],y[]; int e0,nx,prec; int ipio2[];
*
* __kernel_rem_pio2 return the last three digits of N with
* y = x - N*pi/2
* so that |y| < pi/2.
*
* The method is to compute the integer (mod 8) and fraction parts of
* (2/pi)*x without doing the full multiplication. In general we
* skip the part of the product that are known to be a huge integer (
* more accurately, = 0 mod 8 ). Thus the number of operations are
* independent of the exponent of the input.
*
* (2/pi) is represented by an array of 24-bit integers in ipio2[].
*
* Input parameters:
* x[] The input value (must be positive) is broken into nx
* pieces of 24-bit integers in double precision format.
* x[i] will be the i-th 24 bit of x. The scaled exponent
* of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
* match x's up to 24 bits.
*
* Example of breaking a double positive z into x[0]+x[1]+x[2]:
* e0 = ilogb(z)-23
* z = scalbn(z,-e0)
* for i = 0,1,2
* x[i] = floor(z)
* z = (z-x[i])*2**24
*
*
* y[] output result in an array of double precision numbers.
* The dimension of y[] is:
* 24-bit precision 1
* 53-bit precision 2
* 64-bit precision 2
* 113-bit precision 3
* The actual value is the sum of them. Thus for 113-bit
* precison, one may have to do something like:
*
* long double t,w,r_head, r_tail;
* t = (long double)y[2] + (long double)y[1];
* w = (long double)y[0];
* r_head = t+w;
* r_tail = w - (r_head - t);
*
* e0 The exponent of x[0]
*
* nx dimension of x[]
*
* prec an integer indicating the precision:
* 0 24 bits (single)
* 1 53 bits (double)
* 2 64 bits (extended)
* 3 113 bits (quad)
*
* ipio2[]
* integer array, contains the (24*i)-th to (24*i+23)-th
* bit of 2/pi after binary point. The corresponding
* floating value is
*
* ipio2[i] * 2^(-24(i+1)).
*
* External function:
* double scalbn(), floor();
*
*
* Here is the description of some local variables:
*
* jk jk+1 is the initial number of terms of ipio2[] needed
* in the computation. The recommended value is 2,3,4,
* 6 for single, double, extended,and quad.
*
* jz local integer variable indicating the number of
* terms of ipio2[] used.
*
* jx nx - 1
*
* jv index for pointing to the suitable ipio2[] for the
* computation. In general, we want
* ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
* is an integer. Thus
* e0-3-24*jv >= 0 or (e0-3)/24 >= jv
* Hence jv = max(0,(e0-3)/24).
*
* jp jp+1 is the number of terms in PIo2[] needed, jp = jk.
*
* q[] double array with integral value, representing the
* 24-bits chunk of the product of x and 2/pi.
*
* q0 the corresponding exponent of q[0]. Note that the
* exponent for q[i] would be q0-24*i.
*
* PIo2[] double precision array, obtained by cutting pi/2
* into 24 bits chunks.
*
* f[] ipio2[] in floating point
*
* iq[] integer array by breaking up q[] in 24-bits chunk.
*
* fq[] final product of x*(2/pi) in fq[0],..,fq[jk]
*
* ih integer. If >0 it indicates q[] is >= 0.5, hence
* it also indicates the *sign* of the result.
*
*/
/*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
#include "math.h"
#include "math_private.h"
static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
static const double PIo2[] = {
1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
};
static const double
zero = 0.0,
one = 1.0,
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
int
__kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
{
int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
double z,fw,f[20],fq[20],q[20];
/* initialize jk*/
jk = init_jk[prec];
jp = jk;
/* determine jx,jv,q0, note that 3>q0 */
jx = nx-1;
jv = (e0-3)/24; if(jv<0) jv=0;
q0 = e0-24*(jv+1);
/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
j = jv-jx; m = jx+jk;
for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
/* compute q[0],q[1],...q[jk] */
for (i=0;i<=jk;i++) {
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
}
jz = jk;
recompute:
/* distill q[] into iq[] reversingly */
for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
fw = (double)((int32_t)(twon24* z));
iq[i] = (int32_t)(z-two24*fw);
z = q[j-1]+fw;
}
/* compute n */
z = scalbn(z,q0); /* actual value of z */
z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
n = (int32_t) z;
z -= (double)n;
ih = 0;
if(q0>0) { /* need iq[jz-1] to determine n */
i = (iq[jz-1]>>(24-q0)); n += i;
iq[jz-1] -= i<<(24-q0);
ih = iq[jz-1]>>(23-q0);
}
else if(q0==0) ih = iq[jz-1]>>23;
else if(z>=0.5) ih=2;
if(ih>0) { /* q > 0.5 */
n += 1; carry = 0;
for(i=0;i<jz ;i++) { /* compute 1-q */
j = iq[i];
if(carry==0) {
if(j!=0) {
carry = 1; iq[i] = 0x1000000- j;
}
} else iq[i] = 0xffffff - j;
}
if(q0>0) { /* rare case: chance is 1 in 12 */
switch(q0) {
case 1:
iq[jz-1] &= 0x7fffff; break;
case 2:
iq[jz-1] &= 0x3fffff; break;
}
}
if(ih==2) {
z = one - z;
if(carry!=0) z -= scalbn(one,q0);
}
}
/* check if recomputation is needed */
if(z==zero) {
j = 0;
for (i=jz-1;i>=jk;i--) j |= iq[i];
if(j==0) { /* need recomputation */
for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
f[jx+i] = (double) ipio2[jv+i];
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz += k;
goto recompute;
}
}
/* chop off zero terms */
if(z==0.0) {
jz -= 1; q0 -= 24;
while(iq[jz]==0) { jz--; q0-=24;}
} else { /* break z into 24-bit if necessary */
z = scalbn(z,-q0);
if(z>=two24) {
fw = (double)((int32_t)(twon24*z));
iq[jz] = (int32_t)(z-two24*fw);
jz += 1; q0 += 24;
iq[jz] = (int32_t) fw;
} else iq[jz] = (int32_t) z ;
}
/* convert integer "bit" chunk to floating-point value */
fw = scalbn(one,q0);
for(i=jz;i>=0;i--) {
q[i] = fw*(double)iq[i]; fw*=twon24;
}
/* compute PIo2[0,...,jp]*q[jz,...,0] */
for(i=jz;i>=0;i--) {
for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
fq[jz-i] = fw;
}
/* compress fq[] into y[] */
switch(prec) {
case 0:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
break;
case 1:
case 2:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
fw = fq[0]-fw;
for (i=1;i<=jz;i++) fw += fq[i];
y[1] = (ih==0)? fw: -fw;
break;
case 3: /* painful */
for (i=jz;i>0;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (i=jz;i>1;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
if(ih==0) {
y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
} else {
y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
}
}
return n&7;
}

72
StdLib/LibC/Math/k_sin.c Normal file
View File

@@ -0,0 +1,72 @@
/* @(#)k_sin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: k_sin.c,v 1.11 2002/05/26 22:01:53 wiz Exp $");
#endif
/* __kernel_sin( x, y, iy)
* kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
*
* Algorithm
* 1. Since sin(-x) = -sin(x), we need only to consider positive x.
* 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
* 3. sin(x) is approximated by a polynomial of degree 13 on
* [0,pi/4]
* 3 13
* sin(x) ~ x + S1*x + ... + S6*x
* where
*
* |sin(x) 2 4 6 8 10 12 | -58
* |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
* | x |
*
* 4. sin(x+y) = sin(x) + sin'(x')*y
* ~ sin(x) + (1-x*x/2)*y
* For better accuracy, let
* 3 2 2 2 2
* r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
* then 3 2
* sin(x) = x + (S1*x + (x *(r-y/2)+y))
*/
#include "math.h"
#include "math_private.h"
static const double
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
double
__kernel_sin(double x, double y, int iy)
{
double z,r,v;
int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff; /* high word of x */
if(ix<0x3e400000) /* |x| < 2**-27 */
{if((int)x==0) return x;} /* generate inexact */
z = x*x;
v = z*x;
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
if(iy==0) return x+v*(S1+z*r);
else return x-((z*(half*y-v*r)-y)-v*S1);
}

156
StdLib/LibC/Math/k_tan.c Normal file
View File

@@ -0,0 +1,156 @@
/* @(#)k_tan.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: k_tan.c,v 1.12 2004/07/22 18:24:09 drochner Exp $");
#endif
/* __kernel_tan( x, y, k )
* kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input k indicates whether tan (if k=1) or
* -1/tan (if k= -1) is returned.
*
* Algorithm
* 1. Since tan(-x) = -tan(x), we need only to consider positive x.
* 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
* 3. tan(x) is approximated by a odd polynomial of degree 27 on
* [0,0.67434]
* 3 27
* tan(x) ~ x + T1*x + ... + T13*x
* where
*
* |tan(x) 2 4 26 | -59.2
* |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
* | x |
*
* Note: tan(x+y) = tan(x) + tan'(x)*y
* ~ tan(x) + (1+x*x)*y
* Therefore, for better accuracy in computing tan(x+y), let
* 3 2 2 2 2
* r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
* then
* 3 2
* tan(x+y) = x + (T1*x + (x *(r+y)+y))
*
* 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
* tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
* = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
*/
#include "math.h"
#include "math_private.h"
static const double xxx[] = {
3.33333333333334091986e-01, /* 3FD55555, 55555563 */
1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */
5.39682539762260521377e-02, /* 3FABA1BA, 1BB341FE */
2.18694882948595424599e-02, /* 3F9664F4, 8406D637 */
8.86323982359930005737e-03, /* 3F8226E3, E96E8493 */
3.59207910759131235356e-03, /* 3F6D6D22, C9560328 */
1.45620945432529025516e-03, /* 3F57DBC8, FEE08315 */
5.88041240820264096874e-04, /* 3F4344D8, F2F26501 */
2.46463134818469906812e-04, /* 3F3026F7, 1A8D1068 */
7.81794442939557092300e-05, /* 3F147E88, A03792A6 */
7.14072491382608190305e-05, /* 3F12B80F, 32F0A7E9 */
-1.85586374855275456654e-05, /* BEF375CB, DB605373 */
2.59073051863633712884e-05, /* 3EFB2A70, 74BF7AD4 */
/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */
/* pio4 */ 7.85398163397448278999e-01, /* 3FE921FB, 54442D18 */
/* pio4lo */ 3.06161699786838301793e-17 /* 3C81A626, 33145C07 */
};
#define one xxx[13]
#define pio4 xxx[14]
#define pio4lo xxx[15]
#define T xxx
double
__kernel_tan(double x, double y, int iy)
{
double z, r, v, w, s;
int32_t ix, hx;
GET_HIGH_WORD(hx, x); /* high word of x */
ix = hx & 0x7fffffff; /* high word of |x| */
if (ix < 0x3e300000) { /* x < 2**-28 */
if ((int) x == 0) { /* generate inexact */
u_int32_t low;
GET_LOW_WORD(low, x);
if(((ix | low) | (iy + 1)) == 0)
return one / fabs(x);
else {
if (iy == 1)
return x;
else { /* compute -1 / (x+y) carefully */
double a, t;
z = w = x + y;
SET_LOW_WORD(z, 0);
v = y - (z - x);
t = a = -one / w;
SET_LOW_WORD(t, 0);
s = one + t * z;
return t + a * (s + t * v);
}
}
}
}
if (ix >= 0x3FE59428) { /* |x| >= 0.6744 */
if (hx < 0) {
x = -x;
y = -y;
}
z = pio4 - x;
w = pio4lo - y;
x = z + w;
y = 0.0;
}
z = x * x;
w = z * z;
/*
* Break x^5*(T[1]+x^2*T[2]+...) into
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
*/
r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] +
w * T[11]))));
v = z * (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] +
w * T[12])))));
s = z * x;
r = y + z * (s * (r + v) + y);
r += T[0] * s;
w = x + r;
if (ix >= 0x3FE59428) {
v = (double) iy;
return (double) (1 - ((hx >> 30) & 2)) *
(v - 2.0 * (x - (w * w / (w + v) - r)));
}
if (iy == 1)
return w;
else {
/*
* if allow error up to 2 ulp, simply return
* -1.0 / (x+r) here
*/
/* compute -1.0 / (x+r) accurately */
double a, t;
z = w;
SET_LOW_WORD(z, 0);
v = r - (z - x); /* z+v = r+x */
t = a = -1.0 / w; /* a = -1.0/w */
SET_LOW_WORD(t, 0);
s = 1.0 + t * z;
return t + a * (s + t * v);
}
}

Some files were not shown because too many files have changed in this diff Show More