<commit_before>#ifndef UTILITY_H
#define UTILITY_H

#include <stddef.h>
#include <stdint.h>// int32 etc
#include <stdarg.h>

#ifdef SUP_OS_KERNEL
#include <vector>
#include <string>
#endif


typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef long long int lint;
typedef unsigned long long int ulint;

static_assert(sizeof(char) == 1);
static_assert(sizeof(uchar) == 1);
static_assert(sizeof(short) == 2);
static_assert(sizeof(ushort) == 2);
static_assert(sizeof(int) == 4);
static_assert(sizeof(uint) == 4);
static_assert(sizeof(lint) == 8);
static_assert(sizeof(ulint) == 8);


typedef int8_t i8;
typedef uint8_t u8;
typedef int16_t i16;
typedef uint16_t u16;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef intptr_t iptr;
typedef uintptr_t uptr;

static_assert(sizeof(int8_t)==1);
static_assert(sizeof(uint8_t)==1);
static_assert(sizeof(int16_t)==2);
static_assert(sizeof(uint16_t)==2);
static_assert(sizeof(int32_t)==4);
static_assert(sizeof(uint32_t)==4);
static_assert(sizeof(int64_t)==8);
static_assert(sizeof(uint64_t)==8);
static_assert(sizeof(iptr) == sizeof(void*));
static_assert(sizeof(uptr) == sizeof(void*));


void outb(u16 port, u8 data);
u8 inb(u16 port);
void outw(u16 port, u16 data);
u16 inw(u16 port);

void wrmsr(u32 num,u64 value); // read and write MSR from C
u64 rdmsr(u32 num);

template<typename T> T min(const T& a, const T& b) {
    if(a < b) {
        return a;
    } else {
        return b;
    }
}

template<typename T> T max(const T& a, const T& b) {
    if(a < b) {
        return b;
    } else {
        return a;
    }
}

inline void* getCR2(){
    void* res;
    asm("mov %%cr2,%0" :
        "=r"(res)
        :
        :
        );
    return res;
}



[[noreturn]] void vbsod(const char* s, va_list ap);
extern "C" [[noreturn]]  void bsod(const char* s, ...);

void reboot();

//Trick to have S__LINE _ a string containing the line number
#define __S(x) #x
#define __S_(x) __S(x)<commit_msg>Add alignup, add test for size_t size<commit_after>#ifndef UTILITY_H
#define UTILITY_H

#include <stddef.h>
#include <stdint.h>// int32 etc
#include <stdarg.h>

#ifdef SUP_OS_KERNEL
#include <vector>
#include <string>
#endif


typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef long long int lint;
typedef unsigned long long int ulint;

static_assert(sizeof(char) == 1);
static_assert(sizeof(uchar) == 1);
static_assert(sizeof(short) == 2);
static_assert(sizeof(ushort) == 2);
static_assert(sizeof(int) == 4);
static_assert(sizeof(uint) == 4);
static_assert(sizeof(lint) == 8);
static_assert(sizeof(ulint) == 8);


typedef int8_t i8;
typedef uint8_t u8;
typedef int16_t i16;
typedef uint16_t u16;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef intptr_t iptr;
typedef uintptr_t uptr;

static_assert(sizeof(int8_t)==1);
static_assert(sizeof(uint8_t)==1);
static_assert(sizeof(int16_t)==2);
static_assert(sizeof(uint16_t)==2);
static_assert(sizeof(int32_t)==4);
static_assert(sizeof(uint32_t)==4);
static_assert(sizeof(int64_t)==8);
static_assert(sizeof(uint64_t)==8);
#ifdef SUP_OS_KERNEL
static_assert(sizeof(size_t)==8);
#endif
static_assert(sizeof(iptr) == sizeof(void*));
static_assert(sizeof(uptr) == sizeof(void*));


void outb(u16 port, u8 data);
u8 inb(u16 port);
void outw(u16 port, u16 data);
u16 inw(u16 port);

void wrmsr(u32 num,u64 value); // read and write MSR from C
u64 rdmsr(u32 num);

template<typename T> T min(const T& a, const T& b) {
    if(a < b) {
        return a;
    } else {
        return b;
    }
}

template<typename T> T max(const T& a, const T& b) {
    if(a < b) {
        return b;
    } else {
        return a;
    }
}

inline void* getCR2(){
    void* res;
    asm("mov %%cr2,%0" :
        "=r"(res)
        :
        :
        );
    return res;
}



[[noreturn]] void vbsod(const char* s, va_list ap);
extern "C" [[noreturn]]  void bsod(const char* s, ...);

void reboot();

template<typename T> T alignup(T n, T multiple) {
    if(n == 0) return 0; //we don't want to use -1 when T is unsigned
    return (n-1) + (multiple - ((n-1)%multiple));
}

//Trick to have S__LINE _ a string containing the line number
#define __S(x) #x
#define __S_(x) __S(x)
{'fraction_non_alphanumeric': 0.14647756335735876, 'fraction_numerical': 0.04092071611253197, 'mean_word_length': 4.459390862944162, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5580266', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1659, 'n_words': 440}