The Standard Library #
The standard library of HalideOS is a set of a few abstractions for some common data structures and utility functions that we used to again and again for the kernel as well as the shell programs.
All the classes and the functions are encapsulated in the hldstd namespace for clarity.
- Files:
include/halidestdlib.handsrc/halidestdlib.cpp - Namespaces:
hldstd,hldstd::math
Classes
hldstd::stringhltstd::stack<T>
Functions
Refer below for details on return types with accurate namespaces.
hldstd::stringComparehldstd::stringLengthhldstd::math::powhldstd::math::abs
Classes #
hldstd::string
#
A regular string class to maintain a character array and it’s size, with some conversion functions.
Functions
string(int x);- Contructor to convertinttostringstring(double x, int digits_after_point);- Constructor to convertdoubletostringstring(char *str);- Constructor to convert a rawchar*tostringstring(bool val);- Constructor to convertbooltostringstring(string &other);- Copy Constructorint size();- Returns size of the stringchar at(int i);- Returns the character at index i of the stringchar *c_ptr();- Returns a rawchar *to the stringint to_int();- Converts thestringtointdouble to_double();- Converts thestringtodouble
hldstd::stack<T>
#
A standard stack or LIFO list with the standard operations. This is a template class, the stack
can hold any data-type T
Functions
All functions are template functions with <typename T>
stack(int size, T x);- Constructor to initialise the stack with size and the first element;bool pop();-falsefor underflow,truefor successful popbool push(T x);-falsefor overflow,truefor successful pushT top();- Returns the top element of the stackbool isEmpty();- Check if stack is empty or not.
Functions #
Some simple mathematical functions are declared in the math namespace.
int hldstd::stringCompare(char *, char *)- Compare 2 strings from the char pointersint hldstd::stringLength(char *)- Get length of stringdouble hldstd::math::pow(double x, int y)- x^yint hldstd::math::abs(int x)- |x|