Skip to content

Commit

Permalink
fix(gcc): compatibility with GCC14
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jul 17, 2024
1 parent d616754 commit bd1888c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions constantine/platforms/intrinsics/addcarry_subborrow.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,24 @@ when X86:
else:
{.pragma: intrinsics, header:"<x86intrin.h>", nodecl.}

func addcarry_u32(carryIn: Carry, a, b: Ct[uint32], sum: var Ct[uint32]): Carry {.importc: "_addcarry_u32", intrinsics.}
func subborrow_u32(borrowIn: Borrow, a, b: Ct[uint32], diff: var Ct[uint32]): Borrow {.importc: "_subborrow_u32", intrinsics.}
func addcarry_u32(carryIn: Carry, a, b: culong, sum: var culong): Carry {.importc: "_addcarry_u32", intrinsics.}
func subborrow_u32(borrowIn: Borrow, a, b: culong, diff: var culong): Borrow {.importc: "_subborrow_u32", intrinsics.}

func addcarry_u64(carryIn: Carry, a, b: Ct[uint64], sum: var Ct[uint64]): Carry {.importc: "_addcarry_u64", intrinsics.}
func subborrow_u64(borrowIn: Borrow, a, b: Ct[uint64], diff: var Ct[uint64]): Borrow {.importc: "_subborrow_u64", intrinsics.}
# Note, Nim uint64 maps to uint64_t which maps to long unsigned int on 64-bit instead of long long unsigned int
func addcarry_u64(carryIn: Carry, a, b: culonglong, sum: var culonglong): Carry {.importc: "_addcarry_u64", intrinsics.}
func subborrow_u64(borrowIn: Borrow, a, b: culonglong, diff: var culonglong): Borrow {.importc: "_subborrow_u64", intrinsics.}

template addcarry_u32(carryIn: Carry, a, b: Ct[uint32], sum: var Ct[uint32]): Carry =
addcarry_u32(carryIn, cast[culong](a), cast[culong](b), cast[ptr culong](sum.addr)[])

template subborrow_u32(borrowIn: Borrow, a, b: Ct[uint32], sum: var Ct[uint32]): Borrow =
subborrow_u32(borrowIn, cast[culong](a), cast[culong](b), cast[ptr culong](sum.addr)[])

template addcarry_u64(carryIn: Carry, a, b: Ct[uint64], sum: var Ct[uint64]): Carry =
addcarry_u64(carryIn, cast[culong](a), cast[culong](b), cast[ptr culonglong](sum.addr)[])

template subborrow_u64(borrowIn: Borrow, a, b: Ct[uint64], sum: var Ct[uint64]): Borrow =
subborrow_u64(borrowIn, cast[culonglong](a), cast[culonglong](b), cast[ptr culonglong](sum.addr)[])

# ############################################################
#
Expand Down

0 comments on commit bd1888c

Please sign in to comment.