Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:15:26

0001 /*
0002     Copyright (C) 2023 Albin Ahlbäck
0003 
0004     This file is part of FLINT.
0005 
0006     FLINT is free software: you can redistribute it and/or modify it under
0007     the terms of the GNU Lesser General Public License (LGPL) as published
0008     by the Free Software Foundation; either version 3 of the License, or
0009     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
0010 */
0011 
0012 #ifndef LONGLONG_ASM_H
0013 #define LONGLONG_ASM_H
0014 
0015 #if FLINT64
0016 # define _STOR_ULONG __uint128_t
0017 # define _STOR_SLONG __int128_t
0018 #else
0019 # define _STOR_ULONG unsigned long long int
0020 # define _STOR_SLONG long long int
0021 #endif
0022 
0023 #if FLINT_LONG_LONG
0024 # define _FLINT_ADC __builtin_addcll
0025 # define _FLINT_SBB __builtin_subcll
0026 #else
0027 # define _FLINT_ADC __builtin_addcl
0028 # define _FLINT_SBB __builtin_subcl
0029 #endif
0030 
0031 #define add_ssaaaa(s1, s0, a1, a0, b1, b0) \
0032 do \
0033 { \
0034     ulong _carry; \
0035     (s0) = _FLINT_ADC(a0, b0, 0, &_carry); \
0036     (s1) = _FLINT_ADC(a1, b1, _carry, &_carry); \
0037 } while (0)
0038 
0039 #define add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0) \
0040 do \
0041 { \
0042     ulong _carry; \
0043     (s0) = _FLINT_ADC(a0, b0, 0, &_carry); \
0044     (s1) = _FLINT_ADC(a1, b1, _carry, &_carry); \
0045     (s2) = _FLINT_ADC(a2, b2, _carry, &_carry); \
0046 } while (0)
0047 
0048 #define add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0) \
0049 do \
0050 { \
0051     ulong _carry; \
0052     (s0) = _FLINT_ADC(a0, b0, 0, &_carry); \
0053     (s1) = _FLINT_ADC(a1, b1, _carry, &_carry); \
0054     (s2) = _FLINT_ADC(a2, b2, _carry, &_carry); \
0055     (s3) = _FLINT_ADC(a3, b3, _carry, &_carry); \
0056 } while (0)
0057 
0058 #define add_sssssaaaaaaaaaa(s4, s3, s2, s1, s0, a4, a3, a2, a1, a0, b4, b3, b2, b1, b0) \
0059 do \
0060 { \
0061     ulong _carry; \
0062     (s0) = _FLINT_ADC(a0, b0, 0, &_carry); \
0063     (s1) = _FLINT_ADC(a1, b1, _carry, &_carry); \
0064     (s2) = _FLINT_ADC(a2, b2, _carry, &_carry); \
0065     (s3) = _FLINT_ADC(a3, b3, _carry, &_carry); \
0066     (s4) = _FLINT_ADC(a4, b4, _carry, &_carry); \
0067 } while (0)
0068 
0069 #define add_ssssssaaaaaaaaaaaa(s5, s4, s3, s2, s1, s0, a5, a4, a3, a2, a1, a0, b5, b4, b3, b2, b1, b0) \
0070 do \
0071 { \
0072     ulong _carry; \
0073     (s0) = _FLINT_ADC(a0, b0, 0, &_carry); \
0074     (s1) = _FLINT_ADC(a1, b1, _carry, &_carry); \
0075     (s2) = _FLINT_ADC(a2, b2, _carry, &_carry); \
0076     (s3) = _FLINT_ADC(a3, b3, _carry, &_carry); \
0077     (s4) = _FLINT_ADC(a4, b4, _carry, &_carry); \
0078     (s5) = _FLINT_ADC(a5, b5, _carry, &_carry); \
0079 } while (0)
0080 
0081 #define add_sssssssaaaaaaaaaaaaaa(s6, s5, s4, s3, s2, s1, s0, a6, a5, a4, a3, a2, a1, a0, b6, b5, b4, b3, b2, b1, b0) \
0082 do \
0083 { \
0084     ulong _carry; \
0085     (s0) = _FLINT_ADC(a0, b0, 0, &_carry); \
0086     (s1) = _FLINT_ADC(a1, b1, _carry, &_carry); \
0087     (s2) = _FLINT_ADC(a2, b2, _carry, &_carry); \
0088     (s3) = _FLINT_ADC(a3, b3, _carry, &_carry); \
0089     (s4) = _FLINT_ADC(a4, b4, _carry, &_carry); \
0090     (s5) = _FLINT_ADC(a5, b5, _carry, &_carry); \
0091     (s6) = _FLINT_ADC(a6, b6, _carry, &_carry); \
0092 } while (0)
0093 
0094 #define add_ssssssssaaaaaaaaaaaaaaaa(s7, s6, s5, s4, s3, s2, s1, s0, a7, a6, a5, a4, a3, a2, a1, a0, b7, b6, b5, b4, b3, b2, b1, b0) \
0095 do \
0096 { \
0097     ulong _carry; \
0098     (s0) = _FLINT_ADC(a0, b0, 0, &_carry); \
0099     (s1) = _FLINT_ADC(a1, b1, _carry, &_carry); \
0100     (s2) = _FLINT_ADC(a2, b2, _carry, &_carry); \
0101     (s3) = _FLINT_ADC(a3, b3, _carry, &_carry); \
0102     (s4) = _FLINT_ADC(a4, b4, _carry, &_carry); \
0103     (s5) = _FLINT_ADC(a5, b5, _carry, &_carry); \
0104     (s6) = _FLINT_ADC(a6, b6, _carry, &_carry); \
0105     (s7) = _FLINT_ADC(a7, b7, _carry, &_carry); \
0106 } while (0)
0107 
0108 
0109 #define sub_ddmmss(s1, s0, a1, a0, b1, b0) \
0110 do \
0111 { \
0112     ulong _carry; \
0113     (s0) = _FLINT_SBB(a0, b0, 0, &_carry); \
0114     (s1) = _FLINT_SBB(a1, b1, _carry, &_carry); \
0115 } while (0)
0116 
0117 #define sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0) \
0118 do \
0119 { \
0120     ulong _carry; \
0121     (s0) = _FLINT_SBB(a0, b0, 0, &_carry); \
0122     (s1) = _FLINT_SBB(a1, b1, _carry, &_carry); \
0123     (s2) = _FLINT_SBB(a2, b2, _carry, &_carry); \
0124 } while (0)
0125 
0126 #define sub_ddddmmmmssss(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0) \
0127 do \
0128 { \
0129     ulong _carry; \
0130     (s0) = _FLINT_SBB(a0, b0, 0, &_carry); \
0131     (s1) = _FLINT_SBB(a1, b1, _carry, &_carry); \
0132     (s2) = _FLINT_SBB(a2, b2, _carry, &_carry); \
0133     (s3) = _FLINT_SBB(a3, b3, _carry, &_carry); \
0134 } while (0)
0135 
0136 #define sub_dddddmmmmmsssss(s4, s3, s2, s1, s0, a4, a3, a2, a1, a0, b4, b3, b2, b1, b0) \
0137 do \
0138 { \
0139     ulong _carry; \
0140     (s0) = _FLINT_SBB(a0, b0, 0, &_carry); \
0141     (s1) = _FLINT_SBB(a1, b1, _carry, &_carry); \
0142     (s2) = _FLINT_SBB(a2, b2, _carry, &_carry); \
0143     (s3) = _FLINT_SBB(a3, b3, _carry, &_carry); \
0144     (s4) = _FLINT_SBB(a4, b4, _carry, &_carry); \
0145 } while (0)
0146 
0147 #define sub_ddddddmmmmmmssssss(s5, s4, s3, s2, s1, s0, a5, a4, a3, a2, a1, a0, b5, b4, b3, b2, b1, b0) \
0148 do \
0149 { \
0150     ulong _carry; \
0151     (s0) = _FLINT_SBB(a0, b0, 0, &_carry); \
0152     (s1) = _FLINT_SBB(a1, b1, _carry, &_carry); \
0153     (s2) = _FLINT_SBB(a2, b2, _carry, &_carry); \
0154     (s3) = _FLINT_SBB(a3, b3, _carry, &_carry); \
0155     (s4) = _FLINT_SBB(a4, b4, _carry, &_carry); \
0156     (s5) = _FLINT_SBB(a5, b5, _carry, &_carry); \
0157 } while (0)
0158 
0159 #define sub_dddddddmmmmmmmsssssss(s6, s5, s4, s3, s2, s1, s0, a6, a5, a4, a3, a2, a1, a0, b6, b5, b4, b3, b2, b1, b0) \
0160 do \
0161 { \
0162     ulong _carry; \
0163     (s0) = _FLINT_SBB(a0, b0, 0, &_carry); \
0164     (s1) = _FLINT_SBB(a1, b1, _carry, &_carry); \
0165     (s2) = _FLINT_SBB(a2, b2, _carry, &_carry); \
0166     (s3) = _FLINT_SBB(a3, b3, _carry, &_carry); \
0167     (s4) = _FLINT_SBB(a4, b4, _carry, &_carry); \
0168     (s5) = _FLINT_SBB(a5, b5, _carry, &_carry); \
0169     (s6) = _FLINT_SBB(a6, b6, _carry, &_carry); \
0170 } while (0)
0171 
0172 #define sub_ddddddddmmmmmmmmssssssss(s7, s6, s5, s4, s3, s2, s1, s0, a7, a6, a5, a4, a3, a2, a1, a0, b7, b6, b5, b4, b3, b2, b1, b0) \
0173 do \
0174 { \
0175     ulong _carry; \
0176     (s0) = _FLINT_SBB(a0, b0, 0, &_carry); \
0177     (s1) = _FLINT_SBB(a1, b1, _carry, &_carry); \
0178     (s2) = _FLINT_SBB(a2, b2, _carry, &_carry); \
0179     (s3) = _FLINT_SBB(a3, b3, _carry, &_carry); \
0180     (s4) = _FLINT_SBB(a4, b4, _carry, &_carry); \
0181     (s5) = _FLINT_SBB(a5, b5, _carry, &_carry); \
0182     (s6) = _FLINT_SBB(a6, b6, _carry, &_carry); \
0183     (s7) = _FLINT_SBB(a7, b7, _carry, &_carry); \
0184 } while (0)
0185 
0186 #define _mul_ppmm(big_type, small_type, r1, r0, u, v) \
0187 do \
0188 { \
0189     big_type __rx = (big_type) ((small_type) u) * (big_type) ((small_type) v); \
0190     (r0) = (small_type) __rx; \
0191     (r1) = (small_type) (__rx >> FLINT_BITS); \
0192 } while (0)
0193 
0194 #define umul_ppmm(r1, r0, u, v) _mul_ppmm(_STOR_ULONG, ulong, r1, r0, u, v)
0195 #define smul_ppmm(r1, r0, u, v) _mul_ppmm(_STOR_SLONG, slong, r1, r0, u, v)
0196 
0197 #endif