-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[libc][stdfix] Implement idivfx
functions in LLVM libc
#133005
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
b974968
f9b0de4
ec355df
fc30ed0
6a3c052
6bcec01
078e558
7b54572
65eb2ea
693ce40
e59067d
05ba8d3
c245ea5
85ee5ed
aebbcc7
276793b
3e3c403
b1145cf
d30de69
cce1821
dc7713c
c31a661
2d341ee
44bb098
01cacf5
26baea9
832669c
04c1742
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 |
---|---|---|
|
@@ -19,10 +19,19 @@ | |
if (LIBC_UNLIKELY((ptr) == nullptr)) \ | ||
__builtin_trap(); \ | ||
} while (0) | ||
#define LIBC_CRASH_ON_VALUE(var, value) \ | ||
do { \ | ||
if (LIBC_UNLIKELY((var) == (value))) \ | ||
__builtin_trap(); \ | ||
} while (0) | ||
|
||
Comment on lines
+22
to
+27
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. I'm not sure this is necessary. Can you explain why this would be more useful than 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. For this, I just followed what tue suggested. Since divide by 0 is UB as mentioned in the standard, we thought of making this macro, similar to LIBC_CRASH_ON_NULLPTR. Should I change it to 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. This is an option for hardening against UB, and it needs a different macro from |
||
#else | ||
#define LIBC_CRASH_ON_NULLPTR(ptr) \ | ||
do { \ | ||
} while (0) | ||
#define LIBC_CRASH_ON_VALUE(var, value) \ | ||
do { \ | ||
} while (0) | ||
#endif | ||
|
||
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_NULL_CHECK_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation of idivk 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 "idivk.h" | ||
#include "include/llvm-libc-macros/stdfix-macros.h" // accum | ||
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION | ||
#include "src/__support/fixed_point/fx_bits.h" // fixed_point | ||
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(int, idivk, (accum x, accum y)) { | ||
return fixed_point::idiv<accum, int>(x, y); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation header for idivk ------------------------*- 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_IDIVK_H | ||
#define LLVM_LIBC_SRC_STDFIX_IDIVK_H | ||
|
||
#include "include/llvm-libc-macros/stdfix-macros.h" // accum | ||
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
int idivk(accum x, accum y); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_STDFIX_IDIVK_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation of idivlk 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 "idivlk.h" | ||
#include "include/llvm-libc-macros/stdfix-macros.h" // long accum | ||
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION | ||
#include "src/__support/fixed_point/fx_bits.h" // fixed_point | ||
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(long int, idivlk, (long accum x, long accum y)) { | ||
return fixed_point::idiv<long accum, long int>(x, y); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation header for idivlk -----------------------*- 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_IDIVLK_H | ||
#define LLVM_LIBC_SRC_STDFIX_IDIVLK_H | ||
|
||
#include "include/llvm-libc-macros/stdfix-macros.h" // long accum | ||
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
long int idivlk(long accum x, long accum y); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_STDFIX_IDIVLK_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation of idivlr 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 "idivlr.h" | ||
#include "include/llvm-libc-macros/stdfix-macros.h" // long fract | ||
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION | ||
#include "src/__support/fixed_point/fx_bits.h" // fixed_point | ||
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(long int, idivlr, (long fract x, long fract y)) { | ||
return fixed_point::idiv<long fract, long int>(x, y); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation header for idivlr -----------------------*- 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_IDIVLR_H | ||
#define LLVM_LIBC_SRC_STDFIX_IDIVLR_H | ||
|
||
#include "include/llvm-libc-macros/stdfix-macros.h" // long fract | ||
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
long int idivlr(long fract x, long fract y); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_STDFIX_IDIVLR_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation of idivr 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 "idivr.h" | ||
#include "include/llvm-libc-macros/stdfix-macros.h" // fract | ||
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION | ||
#include "src/__support/fixed_point/fx_bits.h" // fixed_point | ||
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(int, idivr, (fract x, fract y)) { | ||
return fixed_point::idiv<fract, int>(x, y); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks duplicated, I think you mean
libc.src.stdfix.idivlk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the bug! i'll put up a patch