A WIP Float32 soft FPU implementation

Related tags

GUI softfpu-rs
Overview

Software-emulated FPU in Rust

Use 32-bit unsigned integer to represent Float32 in IEEE-754 and do float calculation.

Usage

There is an operator-trait-based API:

Add

let v0_1 = soft_f32::F32::from_u32(0x3DCCCCCD);  // 0.1
let v0_2 = soft_f32::F32::from_u32(0x3E4CCCCD);  // 0.2

let v0_3 = v0_1 + v0_2; // 0.1 + 0.2

assert_eq!(v0_3.value(), 0x3E99999A);

and a procedure-style API:

let v0_1 = 0x3DCCCCCD;  // 0.1
let v0_2 = 0x3E4CCCCD;  // 0.2

let v0_3 = soft_f32::f32_add(v0_1, v0_2); // 0.1 + 0.2

assert_eq!(v0_3, 0x3E99999A);

Subtract

let v0_1 = soft_f32::F32::from_u32(0x3DCCCCCD);  // 0.1
let v0_2 = soft_f32::F32::from_u32(0x3E4CCCCD);  // 0.2

let v0_1_result = v0_2 - v0_1;  // 0.2 - 0.1

assert_eq!(v0_1_result.value(), 0x3DCCCCCD);

Multiply

let v0_1 = soft_f32::F32::from_u32(0x3DCCCCCD);  // 0.1
let v0_2 = soft_f32::F32::from_u32(0x3E4CCCCD);  // 0.2

let v0_02 = v0_2 * v0_1;    // 0.2 * 0.1

assert_eq!(v0_02.value(), 0x3CA3D70B);

Division

let v0_1 = soft_f32::F32::from_u32(0x3DCCCCCD);  // 0.1
let v0_2 = soft_f32::F32::from_u32(0x3E4CCCCD);  // 0.2

let v0_5 = v0_1 / v0_2; // 0.1 / 0.2

assert_eq!(v0_5.value(), 0x3F000000);

Squared-root

let v0_01 = crate::soft_f32::F32::from_u32(0x3C23D70A); // 0.01

let v0_1 = v0_01.sqrt();    // sqrt(0.01)

assert_eq!(v0_1.value(), 0x3DCCCCCD);

Comparison

let v0_1 = 0x3DCCCCCD;  // 0.1
let v0_2 = 0x3E4CCCCD;  // 0.2

assert_eq!(v0_1 < v0_2, true);
assert_eq!(v0_1 <= v0_2, true);
assert_eq!(v0_1 < v0_1, false);
assert_eq!(v0_1 <= v0_1, true);
assert_eq!(v0_1 == v0_1, true);
assert_eq!(v0_1 != v0_1, false);

Development

Currently only aiming at implementing Float32.

TODOs

  • Publish on crate.io
  • Float32 Log2 (v0.2.X)
  • Float32 Exp (v0.2.X)
  • Float32 Sin, Cos (v0.2.X)
  • Float80 (v0.3.X)

Conclusion

It is a by-product of one of my projects to bring a float number subsystem into a PL that is not capable of handling float numbers. And finally, implement a more complex system.

You might also like...
Some WIP payload in Rust running on M1.

m1saka Some WIP payload in Rust running on M1. Project informations The aim of this payload is to provide exploration capabilities while providing a s

(WIP) Taking the pain away from file (de)compression

Ouch! ouch loosely stands for Obvious Unified Compression files Helper and aims to be an easy and intuitive way of compressing and decompressing files

🔭 Annict での今期の視聴状況を SVG 画像として出力するサーバ (WIP)

annict-profile-card 🔭 Annict の視聴状況などを SVG 画像として出力する API サーバ (WIP) Annict GraphQL API を使用しています。

Cross-platform Window library in Rust for Tauri. [WIP]

Cross-platform application window creation library in Rust that supports all major platforms like Windows, macOS, Linux, iOS and Android. Built for you, maintained for Tauri.

WIP / POC for using the BL602 wifi blob from Rust

BL602 Wifi Rust This is work in progress and currently more a proof of concept. The code is awfully hacked together - just enough to make it work. It

WIP

What is that? AwesomeWM but oxidized and rewritten as Wayland Compositor Awesome-rs is supposed to replace (currently archived) project called way-coo

Command-line program to manage PS battle logs. WIP.

psbattletools psbattletools is a command-line tool written in Rust for manipulating Pokémon Showdown battle logs. Installation psbattletools currently

A scriptable discord bot (WIP)

Status This project is currently a VERY EARLY WORK IN PROGRESS. Contact me on discord for more details: Jonas747#0001 (105487308693757952) BotLoader (

Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

Simple WIP GPGPU framework for Rust built on top of wgpu

gpgpu A simple GPU compute library based on wgpu. It is meant to be used alongside wgpu if desired. To start using gpgpu, just create a Framework inst

WIP: A Rust client for caniuse.com
WIP: A Rust client for caniuse.com

caniuse-rs A Rust client for caniuse.com. It pulls data from caniuse.com and caches it locally, in a transformed JSON structure that is easier to reas

(WIP) Rust bindings to QuickJS

(WIP) rusty_qjs Rust bindings to QuickJS. Todo JSValue::new_... returns a Result specific JSValue type, like JsString, JsNumber...? catch unwind for e

[WIP] An experimental Java-like language and it's virtual machine, for learning Java and JVM.

Sky VM An experimental Java-like language and it's virtual machine, for learning Java and JVM. Dependencies Rust (rust-lang/rust) 2021 Edition, dual-l

[WIP] wadachi scrapes your GitHub Activities.

wadachi wadachi scrapes your GitHub Activities. Usage | Examples | Docs This library is currently under development. Dependencies [dependencies] wadac

I2P SAMv3 library in Rust (WIP)

SOLITUDE (WIP) i2p SAMv3 library written in Rust for use in the EVA project. Examples Echo Server Creates a UDP service that returns and prints whatev

Neural Networks in Rust, without backpropagation. WIP

Deep Thought As of right now, this crate is far from a usable state. This crate implements feedforward-neural Networks in rust. Unlike the vast majori

WIP cycle-accurate Atari 2600 emulator in Rust

Description This project's primary focus is to create a cycle-accurate emulator of the Atari 2600, and to include tools to create verifiable TASes (e.

A Rust port of the
A Rust port of the "Heroes of Math & Mech" game. Currently macOS, Windows, Linux and iOS app. WIP.

[WIP] Герои Мата и Меха Попытка переписать известный в узких кругах текстовый квест «Герои Мата и Меха» на Rust. Ещё не закончено! Оригинальная версия

WIP, POC of node js driver for pulsar backed by rust

WIP not ready at all, POC for node js rurt based pulsar driver pulsar-node-rust-client This project was bootstrapped by create-neon. Installing pulsar

Comments
  • Unexpected results from f32_sub

    Unexpected results from f32_sub

    Subtraction cannot handle "0" cases:

    assert_eq!(crate::soft_f32::f32_sub(0x0, 0xBDCCCCCE), 0x3DCCCCCE);
    assert_eq!(crate::soft_f32::f32_sub(0x0, 0x3DCCCCCE), 0xBDCCCCCE);
    assert_eq!(crate::soft_f32::f32_sub(0x0, 0x0), 0x0);
    assert_eq!(crate::soft_f32::f32_sub(0x0, 0x80000000), 0x0);
    
    opened by Inokinoki 0
  • Add more test cases for f32_mul

    Add more test cases for f32_mul

    There are still many branches which are not well tested.

    eg.

    exp of a or b is 0: https://github.com/Inokinoki/softfpu-rs/blob/dcb6a6c97bd6030a5a20374ee05d0645fa8fbdd0/src/soft_f32/soft_f32_mul.rs#L59 https://github.com/Inokinoki/softfpu-rs/blob/dcb6a6c97bd6030a5a20374ee05d0645fa8fbdd0/src/soft_f32/soft_f32_mul.rs#L69

    test 
    opened by Inokinoki 0
Owner
Inoki
Ph.D Student @somewhere & Open-Source enthusiast @KDE Community.
Inoki
Crate for simple implementation of Component for Native API 1C:Enterprise written in rust

Гайд по использованию на русском языке можно посмотреть здесь и задать вопросы по использованию, но не оставляйте там комментарии об ошибках, т.к. там

Maxim Kozlov 40 Sep 30, 2023
Simulation tools for animating interacting soft objects

Softy Simulation tools and libraries for animating rigid and soft objects (including cloth) subject to frictional contacts against smooth implicit sur

Egor Larionov 23 Jul 7, 2022
A lookahead compressor/limiter that's soft as a lamb.

lamb ?? A lookahead compressor/limiter that's soft as a lamb. Lamb was made with these goals in mind: Be as clean as possible Give the user full contr

Bart Brouns 9 Mar 6, 2024
crispmacs is a WIP implementation of Emacs from scratch in Rust.

crispmacs is a WIP implementation of Emacs from scratch in Rust.

rust 3 Jul 31, 2022
🍊 WIP: Yet another implementation of MikanOS for aarch64 CPUs, written in Rust.

?? mikan Yet another implementation of MikanOS for aarch64 CPUs, written in Rust. MikanOS (uchan-nos/mikanos) was originally created by @uchan-nos, wh

Naoki Ikeguchi 2 Aug 16, 2022
This is the core library with the full abstraction and implementation of the Minecraft protocol and logic. (Currently WIP)

MineRust (WIP) This is the core library with the full abstraction and implementation of the Minecraft protocol and logic. This project is currently WI

MineRust Project Suite 2 Nov 20, 2022
WIP: Rust implementation of packs for ruby

packs WIP: Rust implementation of packs and packwerk for ruby Features It's entirely built in Rust, so it's really fast, and doesn't require any exter

Alex Evanczuk 9 Jun 7, 2023
Cassandra DB native client written in Rust language. Find 1.x versions on https://github.com/AlexPikalov/cdrs/tree/v.1.x Looking for an async version? - Check WIP https://github.com/AlexPikalov/cdrs-async

CDRS CDRS is looking for maintainers CDRS is Apache Cassandra driver written in pure Rust. ?? Looking for an async version? async-std https://github.c

Alex Pikalov 338 Jan 1, 2023
Build beautiful desktop apps with flutter and rust. 🌠 (wip)

flutter-rs Build flutter desktop app in dart & rust. Get Started Install requirements Rust flutter sdk Develop install the cargo flutter command cargo

null 2k Dec 26, 2022
WIP: Parse archived parler pages into structured html

parler-parse Parler HTML goes in (stdin), structured JSON comes out (stdout) Might be useful for feeding into elasticsearch or cross-referencing with

Christopher Tarquini 15 Feb 16, 2021