Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/clanker_cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ jobs:
- arch: i386
distro: debian:bookworm
install: apt-get update && apt-get install -y build-essential clang
- arch: aarch64
distro: ubuntu:22.04
install: apt-get update && apt-get install -y build-essential clang
# more archs here
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
Expand All @@ -49,3 +47,15 @@ jobs:
make test &&
make example
"

aarch64:
name: Linux aarch64 (native)
runs-on: ubuntu-22.04-arm
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential clang
- name: make test
run: touch ffc.h && make test
- name: make example
run: make example
48 changes: 8 additions & 40 deletions ffc.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,13 @@ bool ffc_int_kind_is_signed(ffc_int_kind ik) {

ffc_internal ffc_inline
ffc_value_bits ffc_get_value_bits(ffc_value value, ffc_value_kind vk) {
ffc_value_bits bits;
if (vk == FFC_VALUE_KIND_DOUBLE) {
#if _MSC_VER && !defined(__clang__)
ffc_value_bits bits;
bits.di = ffc_get_double_bits(value.d);
return bits;
#else
return (ffc_value_bits){.di=ffc_get_double_bits(value.d)};
#endif
} else {
return (ffc_value_bits){.fi=ffc_get_float_bits(value.f)};
bits.fi = ffc_get_float_bits(value.f);
}
return bits;
}

ffc_internal ffc_inline
Expand Down Expand Up @@ -1422,14 +1418,10 @@ ffc_result ffc_parse_int_string(
}

if (p == pend || base < 2 || base > 36) {
#if _MSC_VER && !defined(__clang__)
ffc_result invalid_input_result;
invalid_input_result.ptr = (char*)p;
invalid_input_result.outcome = FFC_OUTCOME_INVALID_INPUT;
return invalid_input_result;
#else
return (ffc_result){ .ptr = (char*)p, .outcome = FFC_OUTCOME_INVALID_INPUT };
#endif
}

ffc_result answer;
Expand Down Expand Up @@ -1474,11 +1466,7 @@ ffc_result ffc_parse_int_string(

if (digit_count == 0) {
if (has_leading_zeros) {
#if _MSC_VER && !defined(__clang__)
value->u64 = 0;
#else
*value = (ffc_int_value){0}; // Largest variants are defined first so this will clear the entire union
#endif
value->u64 = 0; // Must zero the largest variant!
answer.outcome = FFC_OUTCOME_OK;
answer.ptr = p;
} else {
Expand Down Expand Up @@ -1887,24 +1875,16 @@ bool ffc_sv_large_add_from_zero(ffc_sv* x, ffc_bigint_limb_span y) {
// grade-school multiplication algorithm
ffc_internal
bool ffc_bigint_long_mul(ffc_sv* x, ffc_bigint_limb_span y) {
#if defined(_MSC_VER) && !defined(__clang__)
ffc_bigint_limb_span xs;
xs.ptr = x->data;
xs.len = x->len;
#else
ffc_bigint_limb_span xs = (ffc_bigint_limb_span){ .ptr = x->data, .len = x->len };
#endif

// full copy of x into z
ffc_sv z = ffc_sv_create(xs);

#if defined(_MSC_VER) && !defined(__clang__)
ffc_bigint_limb_span zs;
zs.ptr = z.data;
zs.len = z.len;
#else
ffc_bigint_limb_span zs = (ffc_bigint_limb_span){ .ptr = z.data, .len = z.len };
#endif

if (y.len != 0) {
ffc_bigint_limb y0 = ffc_span_index(y, 0);
Expand All @@ -1918,13 +1898,9 @@ bool ffc_bigint_long_mul(ffc_sv* x, ffc_bigint_limb_span y) {
zi.len = 0;
FFC_TRY(ffc_sv_try_extend(&zi, zs));
FFC_TRY(ffc_bigint_small_mul(&zi, yi));
#if defined(_MSC_VER) && !defined(__clang__)
ffc_bigint_limb_span zis;
zis.ptr = zi.data;
zis.len = zi.len;
#else
ffc_bigint_limb_span zis = (ffc_bigint_limb_span){zi.data, zi.len};
#endif
FFC_TRY(ffc_bigint_large_add_from(x, zis, index));
}
}
Expand Down Expand Up @@ -1999,13 +1975,10 @@ ffc_inline ffc_internal
ffc_bigint ffc_bigint_empty(void) {
ffc_sv sv;
sv.len = 0;
#if defined(_MSC_VER) && !defined(__clang__)

ffc_bigint sv_bigint;
sv_bigint.vec = sv;
return sv_bigint;
#else
return (ffc_bigint){sv};
#endif
}

ffc_inline ffc_internal
Expand All @@ -2019,13 +1992,10 @@ ffc_bigint ffc_bigint_make(uint64_t value) {
ffc_sv_push_unchecked(&sv, (uint32_t)(value >> 32));
#endif
ffc_sv_normalize(&sv);
#if defined(_MSC_VER) && !defined(__clang__)

ffc_bigint sv_bigint;
sv_bigint.vec = sv;
return sv_bigint;
#else
return (ffc_bigint){sv};
#endif
}

// get the high 64 bits from the vector, and if bits were truncated.
Expand Down Expand Up @@ -2197,13 +2167,11 @@ ffc_internal ffc_inline
bool ffc_bigint_pow5(ffc_bigint* me, uint32_t exp) {
// multiply by a power of 5
size_t large_length = sizeof(ffc_large_power_of_5) / sizeof(ffc_bigint_limb);
#if _MSC_VER && !defined(__clang__)

ffc_bigint_limb_span large;
large.ptr = (ffc_bigint_limb*)ffc_large_power_of_5;
large.len = large_length;
#else
ffc_bigint_limb_span large = (ffc_bigint_limb_span){ .ptr = (ffc_bigint_limb*)ffc_large_power_of_5, .len = large_length};
#endif

while (exp >= pow5_tables_large_step) {
FFC_TRY(ffc_bigint_large_mul(&me->vec, large));
exp -= pow5_tables_large_step;
Expand Down
28 changes: 4 additions & 24 deletions src/bigint.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,24 +322,16 @@ bool ffc_sv_large_add_from_zero(ffc_sv* x, ffc_bigint_limb_span y) {
// grade-school multiplication algorithm
ffc_internal
bool ffc_bigint_long_mul(ffc_sv* x, ffc_bigint_limb_span y) {
#if defined(_MSC_VER) && !defined(__clang__)
ffc_bigint_limb_span xs;
xs.ptr = x->data;
xs.len = x->len;
#else
ffc_bigint_limb_span xs = (ffc_bigint_limb_span){ .ptr = x->data, .len = x->len };
#endif

// full copy of x into z
ffc_sv z = ffc_sv_create(xs);

#if defined(_MSC_VER) && !defined(__clang__)
ffc_bigint_limb_span zs;
zs.ptr = z.data;
zs.len = z.len;
#else
ffc_bigint_limb_span zs = (ffc_bigint_limb_span){ .ptr = z.data, .len = z.len };
#endif

if (y.len != 0) {
ffc_bigint_limb y0 = ffc_span_index(y, 0);
Expand All @@ -353,13 +345,9 @@ bool ffc_bigint_long_mul(ffc_sv* x, ffc_bigint_limb_span y) {
zi.len = 0;
FFC_TRY(ffc_sv_try_extend(&zi, zs));
FFC_TRY(ffc_bigint_small_mul(&zi, yi));
#if defined(_MSC_VER) && !defined(__clang__)
ffc_bigint_limb_span zis;
zis.ptr = zi.data;
zis.len = zi.len;
#else
ffc_bigint_limb_span zis = (ffc_bigint_limb_span){zi.data, zi.len};
#endif
FFC_TRY(ffc_bigint_large_add_from(x, zis, index));
}
}
Expand Down Expand Up @@ -434,13 +422,10 @@ ffc_inline ffc_internal
ffc_bigint ffc_bigint_empty(void) {
ffc_sv sv;
sv.len = 0;
#if defined(_MSC_VER) && !defined(__clang__)

ffc_bigint sv_bigint;
sv_bigint.vec = sv;
return sv_bigint;
#else
return (ffc_bigint){sv};
#endif
}

ffc_inline ffc_internal
Expand All @@ -454,13 +439,10 @@ ffc_bigint ffc_bigint_make(uint64_t value) {
ffc_sv_push_unchecked(&sv, (uint32_t)(value >> 32));
#endif
ffc_sv_normalize(&sv);
#if defined(_MSC_VER) && !defined(__clang__)

ffc_bigint sv_bigint;
sv_bigint.vec = sv;
return sv_bigint;
#else
return (ffc_bigint){sv};
#endif
}

// get the high 64 bits from the vector, and if bits were truncated.
Expand Down Expand Up @@ -632,13 +614,11 @@ ffc_internal ffc_inline
bool ffc_bigint_pow5(ffc_bigint* me, uint32_t exp) {
// multiply by a power of 5
size_t large_length = sizeof(ffc_large_power_of_5) / sizeof(ffc_bigint_limb);
#if _MSC_VER && !defined(__clang__)

ffc_bigint_limb_span large;
large.ptr = (ffc_bigint_limb*)ffc_large_power_of_5;
large.len = large_length;
#else
ffc_bigint_limb_span large = (ffc_bigint_limb_span){ .ptr = (ffc_bigint_limb*)ffc_large_power_of_5, .len = large_length};
#endif

while (exp >= pow5_tables_large_step) {
FFC_TRY(ffc_bigint_large_mul(&me->vec, large));
exp -= pow5_tables_large_step;
Expand Down
10 changes: 3 additions & 7 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,13 @@ bool ffc_int_kind_is_signed(ffc_int_kind ik) {

ffc_internal ffc_inline
ffc_value_bits ffc_get_value_bits(ffc_value value, ffc_value_kind vk) {
ffc_value_bits bits;
if (vk == FFC_VALUE_KIND_DOUBLE) {
#if _MSC_VER && !defined(__clang__)
ffc_value_bits bits;
bits.di = ffc_get_double_bits(value.d);
return bits;
#else
return (ffc_value_bits){.di=ffc_get_double_bits(value.d)};
#endif
} else {
return (ffc_value_bits){.fi=ffc_get_float_bits(value.f)};
bits.fi = ffc_get_float_bits(value.f);
}
return bits;
}

ffc_internal ffc_inline
Expand Down
10 changes: 1 addition & 9 deletions src/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,10 @@ ffc_result ffc_parse_int_string(
}

if (p == pend || base < 2 || base > 36) {
#if _MSC_VER && !defined(__clang__)
ffc_result invalid_input_result;
invalid_input_result.ptr = (char*)p;
invalid_input_result.outcome = FFC_OUTCOME_INVALID_INPUT;
return invalid_input_result;
#else
return (ffc_result){ .ptr = (char*)p, .outcome = FFC_OUTCOME_INVALID_INPUT };
#endif
}

ffc_result answer;
Expand Down Expand Up @@ -561,11 +557,7 @@ ffc_result ffc_parse_int_string(

if (digit_count == 0) {
if (has_leading_zeros) {
#if _MSC_VER && !defined(__clang__)
value->u64 = 0;
#else
*value = (ffc_int_value){0}; // Largest variants are defined first so this will clear the entire union
#endif
value->u64 = 0; // Must zero the largest variant!
answer.outcome = FFC_OUTCOME_OK;
answer.ptr = p;
} else {
Expand Down