summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2025-11-16 22:24:52 +0100
committernasr <nsrddyn@gmail.com>2025-11-16 22:24:52 +0100
commita66ec9fb875ece99c35cbe8c63d13228043d3d84 (patch)
tree004f05e422db4de220dd65f8af836900774dca72
parente4e3a567ab3e4f9a0329a0e7ebf0bfdabff07895 (diff)
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.
-rw-r--r--src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala45
1 files 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
+ }
+
+
}