Skip to content

Commit

Permalink
Mark all field functions as const
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinas committed Apr 12, 2023
1 parent be563d5 commit 1182641
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
10 changes: 5 additions & 5 deletions fields.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include "fields.h"

// GF(2^8) with X^8 + X^4 + X^3 + X^1 + 1
static const uint8_t bf8_modulus = (1 << 4) | (1 << 3) | (1 << 1) | 1;
#define bf8_modulus (UINT8_C((1 << 4) | (1 << 3) | (1 << 1) | 1))
// GF(2^64) with X^64 + X^4 + X^3 + X^1 + 1
static const uint64_t bf64_modulus = (1 << 4) | (1 << 3) | (1 << 1) | 1;
#define bf64_modulus (UINT64_C((1 << 4) | (1 << 3) | (1 << 1) | 1))
// GF(2^128) with X^128 + X^7 + X^2 + X^1 + 1
static const uint64_t bf128_modulus = (1 << 7) | (1 << 2) | (1 << 1) | 1;
#define bf128_modulus (UINT64_C((1 << 7) | (1 << 2) | (1 << 1) | 1))
// GF(2^192) with X^192 + X^7 + X^2 + X^1 + 1
static const uint64_t bf192_modulus = (1 << 7) | (1 << 2) | (1 << 1) | 1;
#define bf192_modulus (UINT64_C((1 << 7) | (1 << 2) | (1 << 1) | 1))
// GF(2^256) with X^256 + X^10 + X^5 + X^2 + 1
static const uint64_t bf256_modulus = (1 << 10) | (1 << 5) | (1 << 2) | 1;
#define bf256_modulus (UINT64_C((1 << 10) | (1 << 5) | (1 << 2) | 1))

// GF(2^8) implementation

Expand Down
20 changes: 10 additions & 10 deletions fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ typedef struct {
uint64_t values[4];
} bf256_t;

bf8_t bf8_add(bf8_t lhs, bf8_t rhs);
bf8_t bf8_mul(bf8_t lhs, bf8_t rhs);
ATTR_CONST bf8_t bf8_add(bf8_t lhs, bf8_t rhs);
ATTR_CONST bf8_t bf8_mul(bf8_t lhs, bf8_t rhs);

bf64_t bf64_add(bf64_t lhs, bf64_t rhs);
bf64_t bf64_mul(bf64_t lhs, bf64_t rhs);
ATTR_CONST bf64_t bf64_add(bf64_t lhs, bf64_t rhs);
ATTR_CONST bf64_t bf64_mul(bf64_t lhs, bf64_t rhs);

bf128_t bf128_add(bf128_t lhs, bf128_t rhs);
bf128_t bf128_mul(bf128_t lhs, bf128_t rhs);
ATTR_CONST bf128_t bf128_add(bf128_t lhs, bf128_t rhs);
ATTR_CONST bf128_t bf128_mul(bf128_t lhs, bf128_t rhs);

bf192_t bf192_add(bf192_t lhs, bf192_t rhs);
bf192_t bf192_mul(bf192_t lhs, bf192_t rhs);
ATTR_CONST bf192_t bf192_add(bf192_t lhs, bf192_t rhs);
ATTR_CONST bf192_t bf192_mul(bf192_t lhs, bf192_t rhs);

bf256_t bf256_add(bf256_t lhs, bf256_t rhs);
bf256_t bf256_mul(bf256_t lhs, bf256_t rhs);
ATTR_CONST bf256_t bf256_add(bf256_t lhs, bf256_t rhs);
ATTR_CONST bf256_t bf256_mul(bf256_t lhs, bf256_t rhs);

FAEST_END_C_DECL

Expand Down
10 changes: 8 additions & 2 deletions macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,20 @@
#define ATTR_ALWAYS_INLINE
#endif

/* pure attribute */
/* pure attribute
Functions can be marked as pure if their only effect is their return value. The return value
itself may only be computed from reading global variables and the arguments.
*/
#if defined(__GNUC__) || __has_attribute(pure)
#define ATTR_PURE __attribute__((pure))
#else
#define ATTR_PURE
#endif

/* const attribute */
/* constr attribute
Functions can be marked as pure if their only effect is their return value. The return value
itself may only be computed from the arguments.
*/
#if defined(__GNUC__) || __has_attribute(const)
#define ATTR_CONST __attribute__((const))
#else
Expand Down

0 comments on commit 1182641

Please sign in to comment.