-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc][stdfix] Implement fixed point fxbits functions in llvm-libc #114912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b9e2b53
fd76b63
2da28ff
b684e13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===-- Definition of stdfix integer types --------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TYPES_STDFIX_TYPES_H | ||
#define LLVM_LIBC_TYPES_STDFIX_TYPES_H | ||
|
||
typedef signed char int_hr_t; | ||
typedef signed short int int_r_t; | ||
typedef signed int int_lr_t; | ||
typedef signed short int_hk_t; | ||
typedef signed int int_k_t; | ||
typedef signed long int_lk_t; | ||
typedef unsigned char uint_uhr_t; | ||
typedef unsigned short int uint_ur_t; | ||
typedef unsigned int uint_ulr_t; | ||
typedef unsigned short int uint_uhk_t; | ||
typedef unsigned int uint_uk_t; | ||
typedef unsigned long uint_ulk_t; | ||
|
||
#endif // LLVM_LIBC_TYPES_STDFIX_TYPES_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,26 @@ def UnsignedShortAccumType : NamedType<"unsigned short accum">; | |
def UnsignedAccumType : NamedType<"unsigned accum">; | ||
def UnsignedLongAccumType : NamedType<"unsigned long accum">; | ||
|
||
def IntHrT : NamedType <"int_hr_t">; | ||
def IntRT : NamedTypes<"int_r_t">; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Buildbots are failing with:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/NamedTypes/NamedType/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushed 8366be7 |
||
def IntLrT : NamedType<"int_lr_t">; | ||
def IntHkT : NamedType<"int_hk_t">; | ||
def IntKT : NamedType<"int_k_t">; | ||
def IntLkT : NamedType<"int_lk_t">; | ||
def UIntUhrT : NamedType<"uint_uhr_t">; | ||
def UIntUrT : NamedType<"uint_ur_t">; | ||
def UIntUlrT : NamedType<"uint_ulr_t">; | ||
def UIntUhkT : NamedType<"uint_uhk_t">; | ||
def UIntUkT : NamedType<"uint_uk_t">; | ||
def UIntUlkT : NamedType<"uint_ulk_t">; | ||
|
||
def StdcExt : StandardSpec<"stdc_ext"> { | ||
// From ISO/IEC TR 18037:2008 standard: | ||
// https://standards.iso.org/ittf/PubliclyAvailableStandards/c051126_ISO_IEC_TR_18037_2008.zip | ||
HeaderSpec StdFix = HeaderSpec< | ||
"stdfix.h", | ||
[], // macros | ||
[], // types | ||
[IntHrT,IntRT, IntLrT, IntHkT, IntKT, IntLkT, UIntUhrT, UIntUrT, UIntUlrT, UIntUhkT, UIntUkT, UIntUlkT], // types | ||
[], // enums | ||
[ // functions | ||
GuardedFunctionSpec<"abshr", RetValSpec<ShortFractType>, [ArgSpec<ShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
|
@@ -47,6 +60,19 @@ def StdcExt : StandardSpec<"stdc_ext"> { | |
GuardedFunctionSpec<"rounduhk", RetValSpec<UnsignedShortAccumType>, [ArgSpec<UnsignedShortAccumType>, ArgSpec<IntType>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"rounduk", RetValSpec<UnsignedAccumType>, [ArgSpec<UnsignedAccumType>, ArgSpec<IntType>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"roundulk", RetValSpec<UnsignedLongAccumType>, [ArgSpec<UnsignedLongAccumType>, ArgSpec<IntType>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
|
||
GuardedFunctionSpec<"hrbits", RetValSpec<ShortFractType>, [ArgSpec<IntHrT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"rbits", RetValSpec<FractType>, [ArgSpec<IntRT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"lrbits", RetValSpec<LongFractType>, [ArgSpec<IntLrT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"hkbits", RetValSpec<ShortAccumType>, [ArgSpec<IntHkT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"kbits", RetValSpec<AccumType>, [ArgSpec<IntKT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"lkbits", RetValSpec<LongAccumType>, [ArgSpec<IntLkT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"uhrbits", RetValSpec<UnsignedShortFractType>, [ArgSpec<UIntUhrT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"urbits", RetValSpec<UnsignedFractType>, [ArgSpec<UIntUrT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"ukbits", RetValSpec<UnsignedAccumType>, [ArgSpec<UIntUkT>], "LIBC_COMPILER_HAS_FIXED_POINT"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a comma on the end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
GuardedFunctionSpec<"ulrbits", RetValSpec<UnsignedLongFractType>, [ArgSpec<UIntUlrT>], "LIBC_COMPILER_HAS_FIXED_POINT">, | ||
GuardedFunctionSpec<"uhkbits", RetValSpec<UnsignedShortAccumType>, [ArgSpec<UIntUhkT>], "LIBC_COMPILER_HAS_FIXED_POINT"> | ||
GuardedFunctionSpec<"ulkbits", RetValSpec<UnsignedLongAccumType>, [ArgSpec<UIntUlkT>], "LIBC_COMPILER_HAS_FIXED_POINT"> | ||
] | ||
>; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Implementation of hkbits function ---------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "hkbits.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/fixed_point/fx_bits.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
LLVM_LIBC_FUNCTION(short accum, hkbits, (int_hk_t x)) { | ||
return cpp::bit_cast<short accum, int_hk_t>(x); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Implementation header for hkbits ------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_STDFIX_HKBITS_H | ||
#define LLVM_LIBC_SRC_STDFIX_HKBITS_H | ||
|
||
#include "include/llvm-libc-macros/stdfix-macros.h" | ||
#include "include/llvm-libc-types/stdfix-types.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
short accum hkbits(int_hk_t x); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_STDFIX_HKBITS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Implementation of hrbits function ---------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "hrbits.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/fixed_point/fx_bits.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
LLVM_LIBC_FUNCTION(short fract, hrbits, (int_hr_t x)) { | ||
return cpp::bit_cast<short fract, int_hr_t>(x); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Implementation header for hrbits ------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_STDFIX_HRBITS_H | ||
#define LLVM_LIBC_SRC_STDFIX_HRBITS_H | ||
|
||
#include "include/llvm-libc-macros/stdfix-macros.h" | ||
#include "include/llvm-libc-types/stdfix-types.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
short fract hrbits(int_hr_t x); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_STDFIX_HRBITS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Implementation of kbits function ----------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "kbits.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/fixed_point/fx_bits.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
LLVM_LIBC_FUNCTION(accum, kbits, (int_k_t x)) { | ||
return cpp::bit_cast<accum, int_k_t>(x); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Uh oh!
There was an error while loading. Please reload this page.