├── .clang-format ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── bfloat16.h ├── msfp.h └── test.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | IndentWidth: 2 3 | 4 | DerivePointerAlignment: false 5 | PointerAlignment: Left 6 | AllowShortFunctionsOnASingleLine: Empty 7 | UseTab: Never 8 | AlwaysBreakTemplateDeclarations: true 9 | ColumnLimit: 80 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "googletest"] 2 | path = googletest 3 | url = https://github.com/google/googletest.git 4 | branch = rv1.10.x 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | dist: xenial 3 | 4 | compiler: 5 | - gcc 6 | - clang 7 | 8 | script: 9 | - mkdir build 10 | - cd build 11 | - mkdir install 12 | - cmake ../ 13 | - make wee_float_tests 14 | - ./wee_float_tests 15 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(WeeFloat VERSION 1.0) 3 | 4 | set(CMAKE_CXX_STANDARD 11) 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | 7 | add_subdirectory(googletest) 8 | 9 | add_executable(wee_float_tests test.cpp) 10 | target_compile_options(wee_float_tests PRIVATE 11 | $<$,$>:-Werror -Wall -Wextra> 12 | $<$:/Wall /WX>) 13 | target_include_directories(wee_float_tests PUBLIC ${GTEST_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}) 14 | target_link_libraries(wee_float_tests gtest_main) 15 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2019 Ewan Crawford 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WeeFloat 2 | 3 | Header only software implementation of reduced precision floating point formats: 4 | 5 | * [BFloat16](https://en.wikichip.org/wiki/brain_floating-point_format) 6 | * [MSPF](https://en.wikichip.org/wiki/microsoft/msfp8) 7 | * [FlexPoint](https://en.wikichip.org/wiki/flexpoint) 8 | 9 | Author: Ewan Crawford 10 | 11 | [![Build Status](https://travis-ci.org/EwanC/WeeFloat.svg)](https://travis-ci.org/EwanC/WeeFloat) master branch 12 | 13 | ## License 14 | 15 | This project is licensed under the MIT license. 16 | -------------------------------------------------------------------------------- /bfloat16.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct BFloat16 final { 6 | BFloat16() = delete; 7 | BFloat16(float){}; 8 | BFloat16(uint16_t){}; 9 | 10 | BFloat16& operator+=(const BFloat16& rhs); 11 | BFloat16& operator-=(const BFloat16& rhs); 12 | BFloat16& operator*=(const BFloat16& rhs); 13 | BFloat16& operator/=(const BFloat16& rhs); 14 | 15 | bool operator<(const BFloat16&) const { 16 | return true; /* stub */ 17 | } 18 | bool operator>(const BFloat16& rhs) const { 19 | return rhs < *this; 20 | } 21 | bool operator<=(const BFloat16& rhs) const { 22 | return !(*this > rhs); 23 | } 24 | bool operator>=(const BFloat16& rhs) const { 25 | return !(*this < rhs); 26 | } 27 | 28 | bool operator==(const BFloat16&) const { 29 | return true; /* do actual comparison */ 30 | } 31 | bool operator!=(const BFloat16& rhs) const { 32 | return !(*this == rhs); 33 | } 34 | 35 | friend std::ostream& operator<<(std::ostream&, const BFloat16&); 36 | }; 37 | -------------------------------------------------------------------------------- /msfp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template 6 | class MSFP final { 7 | MSFP() = delete; 8 | MSFP(float); 9 | MSFP(uint16_t); 10 | }; 11 | -------------------------------------------------------------------------------- /test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(BFloat16, FloatConstructor) { 5 | BFloat16(1.0f); 6 | } 7 | 8 | int main(int argc, char **argv) { 9 | ::testing::InitGoogleTest(&argc, argv); 10 | return RUN_ALL_TESTS(); 11 | } 12 | --------------------------------------------------------------------------------