From 112432dde02dea4ccf2c7a4286fbdd930d3b6044 Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Tue, 15 Oct 2024 15:13:40 +0100 Subject: [PATCH] define basic fixed-point macros --- src/threads/fixed-point.h | 24 +++++++++++++++++++++++- src/threads/thread.h | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/threads/fixed-point.h b/src/threads/fixed-point.h index 201ccb4..9b0140c 100644 --- a/src/threads/fixed-point.h +++ b/src/threads/fixed-point.h @@ -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 diff --git a/src/threads/thread.h b/src/threads/thread.h index f36d7ac..3019926 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -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. */