Skip to content

Commit

Permalink
Remove usage of __uint128_t and gcc compiler
Browse files Browse the repository at this point in the history
Use double trick instead: https://codeforces.com/blog/entry/96759
  • Loading branch information
y-richie-y committed Jan 24, 2024
1 parent ef1f8d1 commit c4695ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,6 @@ jobs:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
# https://github.com/egor-tensin/setup-mingw/issues/17
- name: Set up MinGW
uses: egor-tensin/[email protected]
with:
version: 12.2.0
- name: Set environment variables for compiler
env:
CC: x86_64-w64-mingw32-gcc
CXX: x86_64-w64-mingw32-g++
run: |
echo "CC=${CC}" >> $GITHUB_ENV
echo "CXX=${CXX}" >> $GITHUB_ENV
- name: set up python 3.8
uses: actions/setup-python@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion cryptomite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from cryptomite.trevisan import Trevisan
from cryptomite.utils import von_neumann

__version__ = '0.1.1'
__version__ = '0.1.2'
20 changes: 12 additions & 8 deletions src/bigntt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ uint64_t add(uint64_t a, uint64_t b) {
* @pre a,b < P
*/
static uint64_t sub(uint64_t a, uint64_t b) {
__int128_t c = a;
c -= b;
__int128_t d = c + P;
__int128_t e = c >> 64;
// return c if c >= 0 else d
return (c&~e) | (d&e);
uint64_t c = a - b;
if (a < b) {
c += P;
}

return c;
}

uint64_t mul(uint64_t a, uint64_t b) {
__int128_t n = a; n*= b;
return n % P;
// correct if a,b,P < 2^57
uint64_t c = (double)a * b / P;
int64_t ans = int64_t(a * b - c * P) % int64_t(P);
if (ans < 0)
ans += P;
return ans;
}

/**
Expand Down

0 comments on commit c4695ab

Please sign in to comment.