From a66ec9fb875ece99c35cbe8c63d13228043d3d84 Mon Sep 17 00:00:00 2001 From: nasr Date: Sun, 16 Nov 2025 22:24:52 +0100 Subject: [PATCH] feature: calculating if a number is a prime still not there yet, haven't figured out the functional programming style of scala + have to find a way to make calculating primes a bit heavier on the ALU, and stress the branch predictor aswell. Still figuring stuff out. --- .../scala/com/nsrddyn/cpu/ALU/Prime.scala | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala b/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala index 7a80df4..2ad3ba6 100644 --- a/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala +++ b/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala @@ -1,5 +1,46 @@ package com.nsrddyn -class Prime { - + + +class Prime(threads: Int) { + + /* + * Calculate all primes up to limit + * This should stress the ALU in someway, + * doing this in a predictable manner, + * will hopefully keep the cpu pipeline busy + * and that way stress the branch predictor + * + * */ + + + // TODO: bad implementation of scala, scala prefers functional programming which something I am not doing here + + def run(n: Long): Unit = { + + + var iterator = 0 + + // TODO: run the isPrime checks + + } + + def isPrime(n: Int): Boolean = { + + for + i <- 2 to 5 + if isWholeNumber(n % i) == true then + true + + false + + // TODO: calculate if the number is a prime number + // TODO: fix errors + } + + def isWholeNumber(n: Int | Float): Boolean = { + // TODO: calculate if the number is a whole number + } + + }