Path: blob/main/Modules/_hacl/include/krml/fstar_uint128_struct_endianness.h
12 views
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.1Licensed under the Apache 2.0 License. */23#ifndef FSTAR_UINT128_STRUCT_ENDIANNESS_H4#define FSTAR_UINT128_STRUCT_ENDIANNESS_H56/* Hand-written implementation of endianness-related uint128 functions7* for the extracted uint128 implementation */89/* Access 64-bit fields within the int128. */10#define HIGH64_OF(x) ((x)->high)11#define LOW64_OF(x) ((x)->low)1213/* A series of definitions written using pointers. */1415inline static void load128_le_(uint8_t *b, uint128_t *r) {16LOW64_OF(r) = load64_le(b);17HIGH64_OF(r) = load64_le(b + 8);18}1920inline static void store128_le_(uint8_t *b, uint128_t *n) {21store64_le(b, LOW64_OF(n));22store64_le(b + 8, HIGH64_OF(n));23}2425inline static void load128_be_(uint8_t *b, uint128_t *r) {26HIGH64_OF(r) = load64_be(b);27LOW64_OF(r) = load64_be(b + 8);28}2930inline static void store128_be_(uint8_t *b, uint128_t *n) {31store64_be(b, HIGH64_OF(n));32store64_be(b + 8, LOW64_OF(n));33}3435#ifndef KRML_NOSTRUCT_PASSING3637inline static uint128_t load128_le(uint8_t *b) {38uint128_t r;39load128_le_(b, &r);40return r;41}4243inline static void store128_le(uint8_t *b, uint128_t n) {44store128_le_(b, &n);45}4647inline static uint128_t load128_be(uint8_t *b) {48uint128_t r;49load128_be_(b, &r);50return r;51}5253inline static void store128_be(uint8_t *b, uint128_t n) {54store128_be_(b, &n);55}5657#else /* !defined(KRML_STRUCT_PASSING) */5859# define print128 print128_60# define load128_le load128_le_61# define store128_le store128_le_62# define load128_be load128_be_63# define store128_be store128_be_6465#endif /* KRML_STRUCT_PASSING */6667#endif686970