Skip to content

Commit

Permalink
feat: add uint256_t library
Browse files Browse the repository at this point in the history
Contains modifications to the include paths to make them work with Arduino
  • Loading branch information
as-iotex committed Apr 15, 2022
1 parent b90156e commit 345d572
Show file tree
Hide file tree
Showing 17 changed files with 3,005 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/extern/uint256_t/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 - 2017 Jason Lee @ calccrypto at gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
49 changes: 49 additions & 0 deletions src/extern/uint256_t/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# uint256_t

An unsigned 256 bit integer type for C++

Copyright (c) 2013 - 2018 Jason Lee @ calccrypto at gmail.com

Please see LICENSE file for license.

[![uint256_t](https://github.com/calccrypto/uint256_t/actions/workflows/uint256_t.yml/badge.svg)](https://github.com/calccrypto/uint256_t/actions/workflows/uint256_t.yml)

## Acknowledgements
With much help from Auston Sterling

Thanks to Stefan Deigmüller for finding
a bug in operator*.

Thanks to François Dessenne for convincing me
to do a general rewrite of this class.

Thanks to John Skaller for making symbols visible
when compiling as a shared library.

## Usage
This is simple implementation of an unsigned 256 bit
integer type in C++. It's meant to be used like a standard
`uintX_t`, except with a larger bit size than those provided
by C/C++.

`uint256_t` requires [`uint128_t`](https://github.com/calccrypto/uint128_t), which is included.

### In Code
All that needs to be done in code is `#include "uint256_t.h"`

```c++
#include <iostream>
#include "uint256_t.h"

int main() {
uint256_t a = 1;
uint256_t b = 2;
std::cout << (a | b) << std::endl;
return 0;
}
```

### Compilation
A C++ compiler supporting at least C++11 is required.

Compilation can be done by directly including `uint128_t.cpp` and `uint256_t.cpp` in your compile command, e.g. `g++ -std=c++11 main.cpp uint128_t.cpp uint256_t.cpp`, or other ways, such as linking the `uint128_t.o` and `uint256_t.o` files, or creating a library, and linking the library in.
26 changes: 26 additions & 0 deletions src/extern/uint256_t/endianness.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _ENDIANNESS_H_
#define _ENDIANNESS_H_
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
defined(__BIG_ENDIAN__) || \
defined(__ARMEB__) || \
defined(__THUMBEB__) || \
defined(__AARCH64EB__) || \
defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
#ifndef __BIG_ENDIAN__
#define __BIG_ENDIAN__
#endif
#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
defined(__LITTLE_ENDIAN__) || \
defined(__ARMEL__) || \
defined(__THUMBEL__) || \
defined(__AARCH64EL__) || \
defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \
defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || \
defined(_X86_) || defined(_IA64_) || defined(ARDUINO)
#ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__
#endif
#else
#error "I don't know what architecture this is!"
#endif
#endif
231 changes: 231 additions & 0 deletions src/extern/uint256_t/uint128_t/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
language: cpp

os: linux
dist: trusty

jobs:
include:
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
env:
- CXX_COMPILER="g++-4.9"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
env:
- CXX_COMPILER="g++-5"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env:
- CXX_COMPILER="g++-6"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env:
- CXX_COMPILER="g++-7"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
packages:
- libstdc++-4.9-dev
- clang-3.6
env:
- CXX_COMPILER="clang++-3.6"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.7
packages:
- libstdc++-4.9-dev
- clang-3.7
env:
- CXX_COMPILER="clang++-3.7"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
packages:
- libstdc++-4.9-dev
- clang-3.8
env:
- CXX_COMPILER="clang++-3.8"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-3.9
packages:
- libstdc++-7-dev
- clang-3.9
env:
- CXX_COMPILER="clang++-3.9"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
packages:
- libstdc++-7-dev
- clang-4.0
env:
- CXX_COMPILER="clang++-4.0"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages:
- libstdc++-7-dev
- clang-5.0
env:
- CXX_COMPILER="clang++-5.0"
- STANDARD="c++11"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
env:
- CXX_COMPILER="g++-4.9"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
env:
- CXX_COMPILER="g++-5"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env:
- CXX_COMPILER="g++-6"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env:
- CXX_COMPILER="g++-7"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
packages:
- libstdc++-4.9-dev
- clang-3.6
env:
- CXX_COMPILER="clang++-3.6"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.7
packages:
- libstdc++-4.9-dev
- clang-3.7
env:
- CXX_COMPILER="clang++-3.7"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
packages:
- libstdc++-4.9-dev
- clang-3.8
env:
- CXX_COMPILER="clang++-3.8"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-3.9
packages:
- libstdc++-7-dev
- clang-3.9
env:
- CXX_COMPILER="clang++-3.9"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
packages:
- libstdc++-7-dev
- clang-4.0
env:
- CXX_COMPILER="clang++-4.0"
- STANDARD="c++14"
- addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages:
- libstdc++-7-dev
- clang-5.0
env:
- CXX_COMPILER="clang++-5.0"
- STANDARD="c++14"

before_install:
- export CXX="${CXX_COMPILER}"

install:
# not much better than git submodules, but there was never a need/want for the repo in this repo
- cd ..
- git clone https://github.com/google/googletest.git
- cd googletest
- git reset --hard d62d6c6556d96dda924382547c54a4b3afedb22c
- mkdir build
- cd build
- cmake .. -DCMAKE_INSTALL_PREFIX=install
- make -j $(nproc --all)
- make -j install
- cd ../../uint128_t/tests

script:
- make -j $(nproc --all)
- make run
21 changes: 21 additions & 0 deletions src/extern/uint256_t/uint128_t/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 - 2017 Jason Lee @ calccrypto at gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading

0 comments on commit 345d572

Please sign in to comment.