Giter Club home page Giter Club logo

zygalm1s1u / boolcast Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 31 KB

This library is intended to be used with the branchless programming technique which generally plays nicer with RISC systems. Sometimes, pipeline hazards (structural, or data) which can potentially manifest as pipeline stalls, can occur through branch instruction sequences that the compiler cannot avoid. These bubbles can be avoided by using arithmetic instructions instead of branching multiple times. Using bits not only saves memory, but also in most cases, speeds up the logic.

C 100.00%
mips mips-architecture mips32 mips64 vr4300 n64-development

boolcast's Introduction

boolCast

Type #include "boolCast.h" to use Booleans in the N64 library, but as bits, rather than bytes. The N64 is rather precious when it comes to memory and saving space and time by using bits is desired. These are build notes for 1.0.6

This library is intended to be used with the branchless programming technique which generally plays nicer with RISC systems. Sometimes, pipeline hazards (structural, or data) which can potentially manifest as pipeline stalls, can occur through branch instruction sequences that the compiler cannot avoid. These bubbles can be avoided by using arithmetic instructions instead of branching multiple times. Using bits not only saves memory, but also in most cases, speeds up the logic.

CAUTION

This library is aimed to be used with the N64, on a MIPS 64 system. The C99 Standard is not defined, so the type names will not conflict. Make sure that there are no conflicting name types for the name "bool".

Prerequisites

Unless you want to build the test file, there is nothing you need. If you want to try it out on the PC first, GCC and make are required.

Getting Started

Make sure to have this in the include chain of your program

#include "boolCast.h"

This will include the library of boolCast. No building is needed to use this library.

To use this in your N64 source: Create an instance of "bool" in your program.

bool flags32;

There are 3 types that the bool can take on, an 8-bit type, 16-bit type, 32-bit type, and a 64-bit type Only ONE type can be used per instance at a time, so one instance can be either 8, 16, 32, or 64 bit; however, make sure to only use one at a time. Declare another instance if more are needed.

flags32.flags32_t = 0u;

To set a bit, use the

BC_SET_FLAG(FLAG, POS)

macro. The first argument is the bool definition, second is the position of the bit to set Let's say we want to set the 32nd bit in the 32 bit flag data type.

 // Change 0000 0000 0000 0000 0000 0000 0000 0000
 // to     1000 0000 0000 0000 0000 0000 0000 0000
 BC_SET_FLAG(flags32.flags32_t, 32);

CAUTION Make sure the bit position being set is compatible with the data type being used. For example, you cannot set the 9th bit in an 8-bit data type. Be cognizant of choices with the flags as this will result in nothing other than potential stack corruption

// DO !!NOT!! do this!!
bool flags8;
BC_SET_FLAG(flags8.flags8_t, 9);

The same rules apply to clearing a flag. To clear a flag, use the

BC_CLEAR_FLAG(FLAG, POS)

macro. The first parameter is the flag type and the second is the position of the bit to clear. Let's say we want to clear the 32nd bit in the 32 bit flag data type.

 flags32.flags32_t = 0x80000000;
 // Change 1000 0000 0000 0000 0000 0000 0000 0000
 // to     0000 0000 0000 0000 0000 0000 0000 0000
 BC_CLEAR_FLAG(flags32.flags32_t, 32);

Test File Built With

Contributing

Currently a WIP, but make pull requests and I will approve ones I see as okay.

Versioning

For the versions available, see the tags on this repository.

Authors

boolcast's People

Contributors

jnoworyta avatar zygalm1s1u avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.