From eb22fef00196c2ea87784207d658648fcbf6581d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 24 Sep 2020 13:26:03 +0200 Subject: [PATCH] Added 64 bit width to sizes and handle it in memory implementations. --- .../java/li/cil/circuity/api/vm/device/memory/Sizes.java | 2 ++ .../cil/circuity/vm/device/memory/ByteBufferMemory.java | 3 +++ .../li/cil/circuity/vm/device/memory/UnsafeMemory.java | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/src/main/java/li/cil/circuity/api/vm/device/memory/Sizes.java b/src/main/java/li/cil/circuity/api/vm/device/memory/Sizes.java index 3f9316d9..eda4b395 100644 --- a/src/main/java/li/cil/circuity/api/vm/device/memory/Sizes.java +++ b/src/main/java/li/cil/circuity/api/vm/device/memory/Sizes.java @@ -4,8 +4,10 @@ public final class Sizes { public static final int SIZE_8 = 8; public static final int SIZE_16 = 16; public static final int SIZE_32 = 32; + public static final int SIZE_64 = 64; public static final int SIZE_8_LOG2 = 0; public static final int SIZE_16_LOG2 = 1; public static final int SIZE_32_LOG2 = 2; + public static final int SIZE_64_LOG2 = 3; } diff --git a/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java b/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java index 04a255df..2f51c740 100644 --- a/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java +++ b/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java @@ -34,6 +34,9 @@ public class ByteBufferMemory implements PhysicalMemory { return data.getShort(offset); case Sizes.SIZE_32_LOG2: return data.getInt(offset); + case Sizes.SIZE_64_LOG2: + // TODO Widen API to support 64 bit values and addresses. + return (int) data.getLong(offset); default: throw new IllegalArgumentException(); } diff --git a/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java b/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java index 4aa45a08..fe6dbe9d 100644 --- a/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java +++ b/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java @@ -60,6 +60,10 @@ public final class UnsafeMemory implements PhysicalMemory { case Sizes.SIZE_32_LOG2: assert (offset & 0b11) == 0; return UNSAFE.getInt(address + offset); + case Sizes.SIZE_64_LOG2: + assert (offset & 0b111) == 0; + // TODO Widen API to support 64 bit values and addresses. + return (int) UNSAFE.getLong(address + offset); default: throw new IllegalArgumentException(); } @@ -80,6 +84,10 @@ public final class UnsafeMemory implements PhysicalMemory { assert (offset & 0b11) == 0; UNSAFE.putInt(address + offset, value); break; + case Sizes.SIZE_64_LOG2: + assert (offset & 0b111) == 0; + UNSAFE.putLong(address + offset, value); + break; default: throw new IllegalArgumentException(); }