[libre-riscv-dev] Introduction

Jacob Lifshay programmerjake at gmail.com
Mon Feb 4 12:46:14 GMT 2019


On Mon, Feb 4, 2019, 04:06 Luke Kenneth Casson Leighton <lkcl at lkcl.net
wrote:

> Rust means that the build and development of the hardware will be
> critically reliant on an unnecessarily large set of dependencies.
>
I don't think it is that big: rust is available on more platforms than most
people care to develop on (I can even build from android, which no one
should be developing on).
The rust crates that it transitively depends on are cc, c99, and
softfloat-sys, so it is much less complicated than the vulkan driver (the
vulkan driver's mess is because the canonical definition of the Vulkan API
is in xml and json and because we are building llvm, which is huge, hence
we need lots of build-time dependences to translate that all).
the actual source is (excluding softfloat-sys) about 600 loc, with about
half of that just being the list of softfloat functions that can be called.

softfloat-sys is just the declarations of functions and types and constants
declared in softfloat.h along with the build script.

One of the other benefits of rust is that it has a standardised build
system (cargo), extensive docs, and a very helpful community.
softfloat by itself is somewhat of a pain to build, by comparison:
makefiles with weird linking errors if you build with -O0 and dependencies
are much harder to get working in C than they are in Rust.

Also, softfloat-sys is published to the crates.io package index, so anyone
else who needs softfloat bindings can use it. I used (only for
softfloat-sys, the rest is lgpl like normal) the same 3-clause bsd license
as softfloat itself uses, to allow others to use it in the same ways as
softfloat.

>
> I assumed c by suggesting using scanf, as it is tge language softfloat is
> written in.
>
> Reading a string with scanf is dead simple.
>
> A switch statement or just a strcmp set of if statements or even just a 1
> character read is sufficient.
>
I'm using a macro to reduce code duplication by about 20 loc per softfloat
function.

>
> The fadd switch statement is a scanf of 2 ints.
>
> The fmuladd switch statement is 3.
>
> Real simple, no need for rust or a stack or a parser  or any complexity of
> any kind.


>
> On Monday, February 4, 2019, Jacob Lifshay <programmerjake at gmail.com>
> wrote:
>
> > I implemented the calculator in rust:
> > https://salsa.debian.org/Kazan-team/softfloat-verify
> >
> > Supports RPN and multiple calculations per invocation by having one
> > space-separated sequence of calculations per line. It prints and clears
> the
> > stack after each line.
> > See https://docs.rs/softfloat-sys/0.1.1/softfloat_sys/ for the list of
> > supported functions and constants.
> >
> > Since I had to write the softfloat rust bindings and I didn't want to
> take
> > much time, I only implemented it for linux x86_64.
> >
> > I had to work around a bug in softfloat where they used C inline
> functions
> > but didn't supply the out-of-line definitions, so it won't build on -O0.
> > Took lots of time to figure out.
> >
> > You will want to use softfloat_detectTininess_write_helper and
> > softfloat_roundingMode_write_helper to set the correct rounding modes and
> > tininess detection.
> > You will also want to use softfloat_exceptionFlags_read_helper and
> > softfloat_exceptionFlags_write_helper to clear and check the exception
> > flags.
> >
> > Build instructions:
> > Install dependencies: sudo apt install cmake build-essential git
> > Get rust from https://rustup.rs/
> >
> > git clone https://salsa.debian.org/Kazan-team/softfloat-verify
> > cd softfloat-verify
> > cargo build
> > ./softfloat-verify <<<"2 i32_to_f128 f128_sqrt"
> > observe the f128 sqrt of 2.
> >
> > Jacob Lifshay
> >
> > On Sat, Feb 2, 2019 at 11:25 PM Luke Kenneth Casson Leighton <
> > lkcl at lkcl.net>
> > wrote:
> >
> > > On Sunday, February 3, 2019, Jacob Lifshay <programmerjake at gmail.com>
> > > wrote:
> > >
> > > > I could write the calculator, shouldn't take very long. It will use
> > > > integers for i/o, they will be bitcasted to the fp types. This way we
> > > avoid
> > > > problems with decimal representations while still being simple enough
> > to
> > > > implement since not everything can read/write hex floats (like
> > > > 0x1234.5678P+25).
> > >
> > >
> > > Yeh definitely int representation, fscanf does the job.
> > >
> > >
> > > >
> > > > Should I use infix notation, lisp-like S expressions, or RPN?
> > > > I think we should not use infix notation as it's harder to parse and
> > not
> > > as
> > > > clear which order operators are being applied.
> > > >
> > > > RPN is the easiest to parse.
> > > > S expressions maintain the familiar operation nesting and is second
> > > easiest
> > > > to parse.
> > >
> > >
> > > I hadn't thought about it, basically needs to be dead simple, yet
> enough
> > to
> > > represent FMULADD.
> > >
> > > even avoid stack, put operator first then operands, because operator
> can
> > be
> > > done as a switch statement then straight to read of num of ops, then
> > print
> > > result. Loop.
> > >
> > > fscanf to read line up to \n to get operator.
> > > switch statement
> > > fscanf with %x's to read operands.
> > >
> > >
> > >
> > >
> > >
> > > --
> > > ---
> > > crowd-funded eco-conscious hardware:
> https://www.crowdsupply.com/eoma68
> > > _______________________________________________
> > > libre-riscv-dev mailing list
> > > libre-riscv-dev at lists.libre-riscv.org
> > > http://lists.libre-riscv.org/mailman/listinfo/libre-riscv-dev
> > >
> > _______________________________________________
> > libre-riscv-dev mailing list
> > libre-riscv-dev at lists.libre-riscv.org
> > http://lists.libre-riscv.org/mailman/listinfo/libre-riscv-dev
> >
>
>
> --
> ---
> crowd-funded eco-conscious hardware: https://www.crowdsupply.com/eoma68
> _______________________________________________
> libre-riscv-dev mailing list
> libre-riscv-dev at lists.libre-riscv.org
> http://lists.libre-riscv.org/mailman/listinfo/libre-riscv-dev
>


More information about the libre-riscv-dev mailing list