-
Notifications
You must be signed in to change notification settings - Fork 15
Floating Point Frontend #34
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
Open
andrealinux1
wants to merge
1
commit into
revng:develop
Choose a base branch
from
andrealinux1:feature/floating-point-frontend
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
share/revng/test/configuration/revng-qa/for-floating-point.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # | ||
| # This file is distributed under the MIT License. See LICENSE.md for details. | ||
| # | ||
|
|
||
| tags: | ||
| - name: for-floating-point | ||
|
|
||
| # We force VFPv3 with hardfloat calling convention on armv7a, in order to | ||
| # avoid the toolchain emitting calls to the libgcc helpers for double | ||
| # precision FP. | ||
| - name: arm-double-vfp | ||
| variables: | ||
| GCC_CFLAGS: | ||
| - -mfpu=vfpv3 | ||
| - -mfloat-abi=hard | ||
|
|
||
| sources: | ||
| - tags: [simple-executable, static, nostdlib, nostartfiles, for-floating-point] | ||
| repeat-for: | ||
| - [arm, arm-double-vfp] | ||
| - [mips] | ||
| - [mipsel] | ||
| - [x86-64] | ||
| - [s390x] | ||
| - [i386] | ||
| - [aarch64] | ||
| prefix: share/revng/test/tests/floating-point | ||
| members: | ||
| - floating-point.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * This file is distributed under the MIT License. See LICENSE.md for details. | ||
| */ | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| typedef float float32_t; | ||
| typedef double float64_t; | ||
|
|
||
| _Static_assert(sizeof(float32_t) == 4, "float32_t must be 4 bytes wide"); | ||
| _Static_assert(sizeof(float64_t) == 8, "float64_t must be 8 bytes wide"); | ||
|
|
||
| #define WEAK __attribute__((weak)) | ||
|
|
||
| /* | ||
| * The operands and results are globals: the compiler cannot constant-fold the | ||
| * floating-point work away, so the softfloat calls reliably emerge in the | ||
| * lifted IR. The matching `CHECK` directives live in the `.filecheck` file in | ||
| * the `revng` repository. | ||
| */ | ||
| float64_t float64_a, float64_b, float64_result; | ||
| float32_t float32_a, float32_b, float32_result; | ||
| int32_t int32_a, int32_result; | ||
| int64_t int64_a, int64_result; | ||
|
|
||
| WEAK void add_float64(void) { | ||
| float64_result = float64_a + float64_b; | ||
| } | ||
|
|
||
| WEAK void add_float32(void) { | ||
| float32_result = float32_a + float32_b; | ||
| } | ||
|
|
||
| WEAK void mul_float64(void) { | ||
| float64_result = float64_a * float64_b; | ||
| } | ||
|
|
||
| WEAK void mul_float32(void) { | ||
| float32_result = float32_a * float32_b; | ||
| } | ||
|
|
||
| WEAK void div_float64(void) { | ||
| float64_result = float64_a / float64_b; | ||
| } | ||
|
|
||
| WEAK void div_float32(void) { | ||
| float32_result = float32_a / float32_b; | ||
| } | ||
|
|
||
| WEAK void compare_float64(void) { | ||
| int32_result = float64_a > float64_b; | ||
| } | ||
|
|
||
| WEAK void compare_float32(void) { | ||
| int32_result = float32_a > float32_b; | ||
| } | ||
|
|
||
| WEAK void convert_int32_t_to_float64(void) { | ||
| float64_result = int32_a; | ||
| } | ||
|
|
||
| WEAK void convert_float64_to_int32_t(void) { | ||
| int32_result = float64_a; | ||
| } | ||
|
|
||
| WEAK void convert_int32_t_to_float32(void) { | ||
| float32_result = int32_a; | ||
| } | ||
|
|
||
| WEAK void convert_float32_to_int32_t(void) { | ||
| int32_result = float32_a; | ||
| } | ||
|
|
||
| /* | ||
| * On 32-bit architectures, the toolchain lowers 64-bit-integer <-> floating | ||
| * point conversions through libgcc helpers, which then use the underlying | ||
| * 32-bit primitives, which are already tested. | ||
| * Their `CHECK-64` directives in the `.filecheck` file are gated on the same | ||
| * architectures. | ||
| */ | ||
| #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8 | ||
|
|
||
| WEAK void convert_int64_t_to_float64(void) { | ||
| float64_result = int64_a; | ||
| } | ||
|
|
||
| WEAK void convert_float64_to_int64_t(void) { | ||
| int64_result = float64_a; | ||
| } | ||
|
|
||
| WEAK void convert_int64_t_to_float32(void) { | ||
| float32_result = int64_a; | ||
| } | ||
|
|
||
| WEAK void convert_float32_to_int64_t(void) { | ||
| int64_result = float32_a; | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| void _start(void) { | ||
| add_float64(); | ||
| add_float32(); | ||
| mul_float64(); | ||
| mul_float32(); | ||
| div_float64(); | ||
| div_float32(); | ||
| compare_float64(); | ||
| compare_float32(); | ||
| convert_int32_t_to_float64(); | ||
| convert_float64_to_int32_t(); | ||
| convert_int32_t_to_float32(); | ||
| convert_float32_to_int32_t(); | ||
| #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8 | ||
|
Contributor
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. Why?
Contributor
Author
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 added a comment explaining this on top of the first
|
||
| convert_int64_t_to_float64(); | ||
| convert_float64_to_int64_t(); | ||
| convert_int64_t_to_float32(); | ||
| convert_float32_to_int64_t(); | ||
| #endif | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.