Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libc/config/baremetal/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.ukbits
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
libc.src.stdfix.bitshr
libc.src.stdfix.bitsuhr
libc.src.stdfix.bitsr
libc.src.stdfix.bitsur
libc.src.stdfix.bitslr
libc.src.stdfix.bitsulr
libc.src.stdfix.bitshk
libc.src.stdfix.bitsuhk
libc.src.stdfix.bitsk
libc.src.stdfix.bitsuk
libc.src.stdfix.bitslk
libc.src.stdfix.bitsulk
)
endif()

Expand Down
12 changes: 12 additions & 0 deletions libc/config/baremetal/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.ukbits
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
libc.src.stdfix.bitshr
libc.src.stdfix.bitsuhr
libc.src.stdfix.bitsr
libc.src.stdfix.bitsur
libc.src.stdfix.bitslr
libc.src.stdfix.bitsulr
libc.src.stdfix.bitshk
libc.src.stdfix.bitsuhk
libc.src.stdfix.bitsk
libc.src.stdfix.bitsuk
libc.src.stdfix.bitslk
libc.src.stdfix.bitsulk
)
endif()

Expand Down
13 changes: 13 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,19 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
# TODO: https://github.com/llvm/llvm-project/issues/115778
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
libc.src.stdfix.bitshr
libc.src.stdfix.bitsuhr
libc.src.stdfix.bitsr
libc.src.stdfix.bitsur
libc.src.stdfix.bitslr
libc.src.stdfix.bitsulr
libc.src.stdfix.bitshk
libc.src.stdfix.bitsuhk
libc.src.stdfix.bitsk
libc.src.stdfix.bitsuk
libc.src.stdfix.bitslk
libc.src.stdfix.bitsulk

)
endif()

Expand Down
12 changes: 12 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.ukbits
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
libc.src.stdfix.bitshr
libc.src.stdfix.bitsuhr
libc.src.stdfix.bitsr
libc.src.stdfix.bitsur
libc.src.stdfix.bitslr
libc.src.stdfix.bitsulr
libc.src.stdfix.bitshk
libc.src.stdfix.bitsuhk
libc.src.stdfix.bitsk
libc.src.stdfix.bitsuk
libc.src.stdfix.bitslk
libc.src.stdfix.bitsulk
)
endif()

Expand Down
84 changes: 84 additions & 0 deletions libc/newhdrgen/yaml/stdfix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,90 @@ functions:
arguments:
- type: uint_ulk_t
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitshr
standards:
- stdc_ext
return_type: int_hr_t
arguments:
- type: short fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsuhr
standards:
- stdc_ext
return_type: uint_uhr_t
arguments:
- type: unsigned short fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsr
standards:
- stdc_ext
return_type: int_r_t
arguments:
- type: fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsur
standards:
- stdc_ext
return_type: uint_ur_t
arguments:
- type: unsigned fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitslr
standards:
- stdc_ext
return_type: int_lr_t
arguments:
- type: long fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsulr
standards:
- stdc_ext
return_type: uint_ulr_t
arguments:
- type: unsigned long fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitshk
standards:
- stdc_ext
return_type: int_hk_t
arguments:
- type: short accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsuhk
standards:
- stdc_ext
return_type: uint_uhk_t
arguments:
- type: unsigned short accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsk
standards:
- stdc_ext
return_type: int_k_t
arguments:
- type: accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsuk
standards:
- stdc_ext
return_type: uint_uk_t
arguments:
- type: unsigned accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitslk
standards:
- stdc_ext
return_type: uint_ulr_t
arguments:
- type: long accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: bitsulk
standards:
- stdc_ext
return_type: uint_ulk_t
arguments:
- type: unsigned long accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: roundhk
standards:
- stdc_ext
Expand Down
13 changes: 13 additions & 0 deletions libc/spec/stdc_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def StdcExt : StandardSpec<"stdc_ext"> {
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">,

GuardedFunctionSpec<"bitshr", RetValSpec<IntHrT>, [ArgSpec<ShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsr", RetValSpec<IntRT>, [ArgSpec<FractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitslr", RetValSpec<IntLrT>, [ArgSpec<LongFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitshk", RetValSpec<IntHkT>, [ArgSpec<ShortAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsk", RetValSpec<IntKT>, [ArgSpec<AccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitslk", RetValSpec<IntLkT>, [ArgSpec<LongAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsuhr", RetValSpec<UIntUhrT>, [ArgSpec<UnsignedShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsur", RetValSpec<UIntUrI>, [ArgSpec<UnsignedFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsuk", RetValSpec<UIntUkT>, [ArgSpec<UnsignedAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsulr", RetValSpec<UIntUlrT>, [ArgSpec<UnsignedLongFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsuhk", RetValSpec<UIntUhkT>, [ArgSpec<UnsignedShortAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"bitsulk", RetValSpec<UIntUlkT>, [ArgSpec<UnsignedLongAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
]
>;

Expand Down
12 changes: 12 additions & 0 deletions libc/src/stdfix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
libc.src.__support.CPP.bit
libc.src.__support.fixed_point.fx_bits
)

add_entrypoint_object(
bits${suffix}
HDRS
bits${suffix}.h
SRCS
bits${suffix}.cpp
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.fixed_point.fx_bits
)

endforeach()

add_entrypoint_object(
Expand Down
19 changes: 19 additions & 0 deletions libc/src/stdfix/bitshk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of bitshk 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 "bitshk.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(int_hk_t, bitshk, (short accum x)) {
return cpp::bit_cast<int_hk_t, short accum>(x);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so I didn't notice this with the fxbits patch, but I think a simple bitcast won't suffice if the fixed point representation has padding bits since the padding could be any value. By default the only upstream representation for fx types doesn't use padding, but anyone use -fpadding-on-unsigned-fixed-point might be affected by this. I believe this could be addressed by just masking out the padding bits for the unsigned types after the bit_cast.

https://github.com/llvm/llvm-project/pull/114318/files#diff-aa94f9761108563a2750a9c9be57772371129073ff15c1b4e0a9ab6790a2c260R55 added the mask in FXBits which could be borrowed for this patch.

}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/stdfix/bitshk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation header for bitshk ------------------------*- 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_BITSHK_H
#define LLVM_LIBC_SRC_STDFIX_BITSHK_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 {

int_hk_t bitshk(short accum x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDFIX_BITSHK_H
19 changes: 19 additions & 0 deletions libc/src/stdfix/bitshr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of bitshr 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 "bitshr.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(int_hr_t, bitshr, (short fract x)) {
return cpp::bit_cast<int_hr_t, short fract>(x);
}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/stdfix/bitshr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation header for bitshr ------------------------*- 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_BITSHR_H
#define LLVM_LIBC_SRC_STDFIX_BITSHR_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 {

int_hr_t bitshr(short fract x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDFIX_BITSHR_H
19 changes: 19 additions & 0 deletions libc/src/stdfix/bitsk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of bitsk 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 "bitsk.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(int_k_t, bitsk, (accum x)) {
return cpp::bit_cast<int_k_t, accum>(x);
}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/stdfix/bitsk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation header for bitsk -------------------------*- 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_BITSK_H
#define LLVM_LIBC_SRC_STDFIX_BITSK_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 {

int_k_t bitsk(accum x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDFIX_BITSK_H
19 changes: 19 additions & 0 deletions libc/src/stdfix/bitslk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of bitslk 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 "bitslk.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(int_lk_t, bitslk, (long accum x)) {
return cpp::bit_cast<int_lk_t, long accum>(x);
}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/stdfix/bitslk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation header for bitslk ------------------------*- 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_BITSLK_H
#define LLVM_LIBC_SRC_STDFIX_BITSLK_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 {

int_lk_t bitslk(long accum x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDFIX_BITSLK_H
19 changes: 19 additions & 0 deletions libc/src/stdfix/bitslr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of bitslr 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 "bitslr.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(int_lr_t, bitslr, (long fract x)) {
return cpp::bit_cast<int_lr_t, long fract>(x);
}

} // namespace LIBC_NAMESPACE_DECL
Loading
Loading