Skip to content

Instantly share code, notes, and snippets.

@angeloped
Created January 20, 2023 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angeloped/90dfacfd7aab0b541acf29f66055c791 to your computer and use it in GitHub Desktop.
Save angeloped/90dfacfd7aab0b541acf29f66055c791 to your computer and use it in GitHub Desktop.
Boolean Comparing Operation | MHIP kernel component
#include <stdio.h>
// Boolean Comparing Operation | MHIP kernel component
// Bryan Pedrosa
// 1/20/2023
// modes:
//[0x0]BOOL_EQ - equal
//[0x1]BOOL_LT - less than
//[0x2]BOOL_GT - greater than
//[0x3]BOOL_LE - less than equal
//[0x4]BOOL_GE - greater than equal
int BOOL_OP(int mode, int size, int A[], int B[]){
int status = 0x0; // EQ
for(int i=0; i<size; i++){
if( A[i] < B[i] ){
status = 0x1; // LT
break;
}
if( A[i] > B[i] ){
status = 0x2; // GT
break;
}
}
if(mode < 0x3){
return status == mode; // EQ/LT/GT combined (0x0/0x1/0x2)
}else{
return (status==0x0) | (status==mode-2); // LE/GE combined (0x3/0x4)
}
}
int main(){
int A[3] = {0,0,1};
int B[3] = {0,1,1};
printf("%d\n", BOOL_OP(0x3, 3, A, B) );
}
# Boolean Comparing Operation | MHIP kernel component
# Bryan Pedrosa
# 1/20/2023
# modes:
#[0x0]BOOL_EQ - equal
#[0x1]BOOL_LT - less than
#[0x2]BOOL_GT - greater than
#[0x3]BOOL_LE - less than equal
#[0x4]BOOL_GE - greater than equal
def BOOL_OP(mode, size, A, B):
status = 0x0 # EQ
for i in range(size):
if A[i] < B[i]:
status = 0x1 # LT
break
if A[i] > B[i]:
status = 0x2 # GT
break
if mode < 0x3:
return status == mode # EQ/LT/GT combined (0x0/0x1/0x2)
else:
return (status==0x0) | (status==mode-2) # LE/GE combined (0x3/0x4)
A = [0,0,1]
B = [0,1,1]
print(BOOL_OP(0x3, 3, A, B))
print(BOOL_OP(0x3, 3, "001", "011"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment