define basic fixed-point macros

This commit is contained in:
EDiasAlberto
2024-10-15 15:13:40 +01:00
committed by Gleb Koval
parent f969b02630
commit 112432dde0
2 changed files with 27 additions and 1 deletions

View File

@@ -4,6 +4,28 @@
/* Fixed Point Arithmetic bit count constants */
#define NUM_INT_BITS 11
#define NUM_FRAC_BITS 20
#define CONVERSION_CONST 1 << NUM_FRAC_BITS /* f = 2^q, (2^20) */
#define CONVERSION_CONST (1 << NUM_FRAC_BITS) /* f = 2^q, (2^20) */
/* Fixed Point Arithmetic conversion operations */
/* Converts an integer n to a fixed point number */
#define INT_TO_FP(n) ((n) * (CONVERSION_CONST))
/* Handles conversion of fixed point to integer. First version truncates, second one rounds */
#define FLOOR_FP_TO_INT(x) ((x) / (CONVERSION_CONST))
#define ROUNDING_FP_TO_INT(x) ((x) >= 0 ? ((x) + ((CONVERSION_CONST) / 2)) : ((x) - ((CONVERSION_CONST) / 2)))
/* Fixed Point Arithmetic addition operations */
#define FP_ADD(x, y) ((x) + (y))
#define FP_SUBTRACT(x, y) ((x) - (y))
/* Addition and Subtraction but between a fixed point and an integer */
#define FP_ADD_INT(x, n) ((x) + ((n) * (CONVERSION_CONST)))
#define FP_SUBTRACT_INT(x, n) ((x) - ((n) * (CONVERSION_CONST)))
/* Fixed Point Arithmetic multiplication operations */
#define FP_MULTIPLY(x, y) ((int64_t)(x)) * (y) / (CONVERSION_CONST)
#define FP_DIVIDE(x, y) ((int64_t)(x)) * (CONVERSION_CONST) / (y)
/* Multiplication and division but between a fixed point and an integer */
#define FP_MULTIPLY_INT(x, n) ((x) * (n))
#define FP_DIVIDE_INT(x, n) ((x) / (n))
#endif //FIXED_POINT_H

View File

@@ -93,6 +93,10 @@ struct thread
/* Shared between thread.c and synch.c. */
struct list_elem elem; /* List element. */
/* MLFQS items */
int nice; /* Nice value for this thread */
int32_t recent_cpu; /* Amount of time this process received */
#ifdef USERPROG
/* Owned by userprog/process.c. */
uint32_t *pagedir; /* Page directory. */