1 /*
2     Copyright (C) 2018 Daniel Schultz
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
10 */
11 
12 #include "mpoly.h"
13 
14 
mpoly_monomials_shift_right_ui(ulong * Aexps,flint_bitcnt_t Abits,slong Alength,const ulong * user_exps,const mpoly_ctx_t mctx)15 void mpoly_monomials_shift_right_ui(ulong * Aexps, flint_bitcnt_t Abits,
16                 slong Alength, const ulong * user_exps, const mpoly_ctx_t mctx)
17 {
18     slong i;
19     slong N = mpoly_words_per_exp(Abits, mctx);
20     ulong * texps;
21     TMP_INIT;
22 
23     TMP_START;
24 
25     texps = (ulong *) TMP_ALLOC(N*sizeof(ulong));
26 
27     mpoly_set_monomial_ui(texps, user_exps, Abits, mctx);
28 
29     if (Abits <= FLINT_BITS)
30     {
31 #if FLINT_WANT_ASSERT
32         ulong mask = mpoly_overflow_mask_sp(Abits);
33 #endif
34         for (i = 0; i < Alength; i++)
35         {
36             mpoly_monomial_sub(Aexps + N*i, Aexps + N*i, texps, N);
37             FLINT_ASSERT(!mpoly_monomial_overflows(Aexps + N*i, N, mask));
38         }
39     }
40     else
41     {
42         for (i = 0; i < Alength; i++)
43         {
44             mpoly_monomial_sub_mp(Aexps + N*i, Aexps + N*i, texps, N);
45             FLINT_ASSERT(!mpoly_monomial_overflows_mp(Aexps + N*i, N, Abits));
46         }
47     }
48 
49     TMP_END;
50 }
51 
52 
mpoly_monomials_shift_right_ffmpz(ulong * Aexps,flint_bitcnt_t Abits,slong Alength,const fmpz * user_exps,const mpoly_ctx_t mctx)53 void mpoly_monomials_shift_right_ffmpz(ulong * Aexps, flint_bitcnt_t Abits,
54                 slong Alength, const fmpz * user_exps, const mpoly_ctx_t mctx)
55 {
56     slong i;
57     slong N = mpoly_words_per_exp(Abits, mctx);
58     ulong * texps;
59     TMP_INIT;
60 
61     TMP_START;
62 
63     texps = (ulong *) TMP_ALLOC(N*sizeof(ulong));
64 
65     mpoly_set_monomial_ffmpz(texps, user_exps, Abits, mctx);
66 
67     if (Abits <= FLINT_BITS)
68     {
69 #if FLINT_WANT_ASSERT
70         ulong mask = mpoly_overflow_mask_sp(Abits);
71 #endif
72         for (i = 0; i < Alength; i++)
73         {
74             mpoly_monomial_sub(Aexps + N*i, Aexps + N*i, texps, N);
75             FLINT_ASSERT(!mpoly_monomial_overflows(Aexps + N*i, N, mask));
76         }
77     }
78     else
79     {
80         for (i = 0; i < Alength; i++)
81         {
82             mpoly_monomial_sub_mp(Aexps + N*i, Aexps + N*i, texps, N);
83             FLINT_ASSERT(!mpoly_monomial_overflows_mp(Aexps + N*i, N, Abits));
84         }
85     }
86 
87     TMP_END;
88 }
89 
90 
91