-
Notifications
You must be signed in to change notification settings - Fork 278
Add flint_mpn_sqrhigh_normalised #2001
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
Merged
fredrik-johansson
merged 1 commit into
flintlib:main
from
albinahlback:sqrhigh_normalized
May 26, 2024
Merged
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
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
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
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
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,88 @@ | ||
| /* | ||
| Copyright (C) 2024 Albin Ahlbäck | ||
|
|
||
| This file is part of FLINT. | ||
|
|
||
| FLINT is free software: you can redistribute it and/or modify it under | ||
| the terms of the GNU Lesser General Public License (LGPL) as published | ||
| by the Free Software Foundation; either version 3 of the License, or | ||
| (at your option) any later version. See <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "mpn_extras.h" | ||
|
|
||
| #if FLINT_HAVE_ASSEMBLY_x86_64_adx || FLINT_HAVE_ASSEMBLY_armv8 | ||
| mp_limb_t flint_mpn_sqrhigh_1(mp_ptr, mp_srcptr); | ||
| mp_limb_t flint_mpn_sqrhigh_2(mp_ptr, mp_srcptr); | ||
| mp_limb_t flint_mpn_sqrhigh_3(mp_ptr, mp_srcptr); | ||
| mp_limb_t flint_mpn_sqrhigh_4(mp_ptr, mp_srcptr); | ||
| mp_limb_t flint_mpn_sqrhigh_5(mp_ptr, mp_srcptr); | ||
| mp_limb_t flint_mpn_sqrhigh_6(mp_ptr, mp_srcptr); | ||
| mp_limb_t flint_mpn_sqrhigh_7(mp_ptr, mp_srcptr); | ||
| mp_limb_t flint_mpn_sqrhigh_8(mp_ptr, mp_srcptr); | ||
|
|
||
| const flint_mpn_sqr_func_t flint_mpn_sqrhigh_func_tab[] = | ||
| { | ||
| NULL, | ||
| flint_mpn_sqrhigh_1, | ||
| flint_mpn_sqrhigh_2, | ||
| flint_mpn_sqrhigh_3, | ||
| flint_mpn_sqrhigh_4, | ||
| flint_mpn_sqrhigh_5, | ||
| flint_mpn_sqrhigh_6, | ||
| flint_mpn_sqrhigh_7, | ||
| flint_mpn_sqrhigh_8 | ||
| }; | ||
| #else | ||
| mp_limb_t flint_mpn_sqrhigh_1(mp_ptr res, mp_srcptr u) | ||
| { | ||
| mp_limb_t low; | ||
| umul_ppmm(res[0], low, u[0], u[0]); | ||
| return low; | ||
| } | ||
|
|
||
| /* todo */ | ||
| mp_limb_t flint_mpn_sqrhigh_2(mp_ptr res, mp_srcptr u) | ||
| { | ||
| mp_limb_t b, low; | ||
| FLINT_MPN_MUL_2X2(res[1], res[0], low, b, u[1], u[0], u[1], u[0]); | ||
| return low; | ||
| } | ||
|
|
||
| /* todo: higher cases */ | ||
|
|
||
| const flint_mpn_sqr_func_t flint_mpn_sqrhigh_func_tab[] = { | ||
| NULL, | ||
| flint_mpn_sqrhigh_1, | ||
| flint_mpn_sqrhigh_2, | ||
| }; | ||
| #endif | ||
|
|
||
| #if FLINT_HAVE_ASSEMBLY_x86_64_adx | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_1(mp_ptr, mp_srcptr); | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_2(mp_ptr, mp_srcptr); | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_3(mp_ptr, mp_srcptr); | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_4(mp_ptr, mp_srcptr); | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_5(mp_ptr, mp_srcptr); | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_6(mp_ptr, mp_srcptr); | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_7(mp_ptr, mp_srcptr); | ||
| mp_limb_pair_t flint_mpn_sqrhigh_normalised_8(mp_ptr, mp_srcptr); | ||
|
|
||
| const flint_mpn_sqrhigh_normalised_func_t flint_mpn_sqrhigh_normalised_func_tab[] = | ||
| { | ||
| NULL, | ||
| flint_mpn_sqrhigh_normalised_1, | ||
| flint_mpn_sqrhigh_normalised_2, | ||
| flint_mpn_sqrhigh_normalised_3, | ||
| flint_mpn_sqrhigh_normalised_4, | ||
| flint_mpn_sqrhigh_normalised_5, | ||
| flint_mpn_sqrhigh_normalised_6, | ||
| flint_mpn_sqrhigh_normalised_7, | ||
| flint_mpn_sqrhigh_normalised_8 | ||
| }; | ||
| #else | ||
| const flint_mpn_sqrhigh_normalised_func_t flint_mpn_sqrhigh_normalised_func_tab[] = | ||
| { | ||
| NULL | ||
| }; | ||
| #endif |
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
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,93 @@ | ||
| /* | ||
| Copyright (C) 2024 Albin Ahlbäck | ||
|
|
||
| This file is part of FLINT. | ||
|
|
||
| FLINT is free software: you can redistribute it and/or modify it under | ||
| the terms of the GNU Lesser General Public License (LGPL) as published | ||
| by the Free Software Foundation; either version 3 of the License, or | ||
| (at your option) any later version. See <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "test_helpers.h" | ||
| #include "mpn_extras.h" | ||
|
|
||
| #define N_MIN 1 | ||
| #define N_MAX 64 | ||
|
|
||
| TEST_FUNCTION_START(flint_mpn_sqrhigh_normalised, state) | ||
| { | ||
| slong ix; | ||
| int result; | ||
|
|
||
| for (ix = 0; ix < 10000 * flint_test_multiplier(); ix++) | ||
| { | ||
| mp_ptr rp_n, rp_u, xp; | ||
| mp_size_t n; | ||
| mp_limb_pair_t res_norm; | ||
| mp_limb_t retlimb, normalised; | ||
|
|
||
| n = N_MIN + n_randint(state, N_MAX - N_MIN + 1); | ||
|
|
||
| rp_n = flint_malloc(sizeof(mp_limb_t) * (n + 1)); | ||
| rp_u = flint_malloc(sizeof(mp_limb_t) * (n + 1)); | ||
| xp = flint_malloc(sizeof(mp_limb_t) * n); | ||
|
|
||
| flint_mpn_rrandom(xp, state, n); | ||
| xp[n - 1] |= (UWORD(1) << (FLINT_BITS - 1)); | ||
|
|
||
| rp_u[0] = flint_mpn_sqrhigh(rp_u + 1, xp, n); | ||
| res_norm = flint_mpn_sqrhigh_normalised(rp_n + 1, xp, n); | ||
|
|
||
| retlimb = res_norm.m1; | ||
| normalised = res_norm.m2; | ||
| rp_n[0] = retlimb; | ||
|
|
||
| result = ((rp_n[n] & (UWORD(1) << (FLINT_BITS - 1))) != UWORD(0)); | ||
| if (!result) | ||
| TEST_FUNCTION_FAIL( | ||
| "Top bit not set in normalised result\n" | ||
| "ix = %wd\n" | ||
| "n = %wd\n" | ||
| "xp = %{ulong*}\n" | ||
| "rp_n = %{ulong*}\n" | ||
| "rp_u = %{ulong*}\n", | ||
| ix, n, xp, n, rp_n, n + 1, rp_u, n + 1); | ||
|
|
||
| if (normalised) | ||
| { | ||
| result = (mpn_lshift(rp_u, rp_u, n + 1, 1) == 0); | ||
| result = result && (mpn_cmp(rp_n, rp_u, n + 1) == 0); | ||
| if (!result) | ||
| TEST_FUNCTION_FAIL( | ||
| "rp_n != rp_u << 1 when normalised\n" | ||
| "ix = %wd\n" | ||
| "n = %wd\n" | ||
| "xp = %{ulong*}\n" | ||
| "rp_n = %{ulong*}\n" | ||
| "rp_u = %{ulong*}\n", | ||
| ix, n, xp, n, rp_n, n + 1, rp_u, n + 1); | ||
| } | ||
| else | ||
| { | ||
| result = (mpn_cmp(rp_n, rp_u, n + 1) == 0); | ||
| if (!result) | ||
| TEST_FUNCTION_FAIL( | ||
| "rp_n != rp_u when unnormalised\n" | ||
| "ix = %wd\n" | ||
| "n = %wd\n" | ||
| "xp = %{ulong*}\n" | ||
| "rp_n = %{ulong*}\n" | ||
| "rp_u = %{ulong*}\n", | ||
| ix, n, xp, n, rp_n, n + 1, rp_u, n + 1); | ||
| } | ||
|
|
||
| flint_free(rp_n); | ||
| flint_free(rp_u); | ||
| flint_free(xp); | ||
| } | ||
|
|
||
| TEST_FUNCTION_END(state); | ||
| } | ||
| #undef N_MIN | ||
| #undef N_MAX |
Oops, something went wrong.
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.