mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
determining array base offset: replaced trick code with proper code
This commit is contained in:
@@ -35,7 +35,7 @@ class BLIT {
|
||||
val writeAddr = toAddr(x, y)
|
||||
|
||||
UnsafeHelper.memcpyRaw(
|
||||
bytes, (if (AppLoader.is32BitJVM) 8 else 16) + yy * width,
|
||||
bytes, UnsafeHelper.getArrayOffset(bytes) + yy * width,
|
||||
null, framebuffer.ptr + writeAddr,
|
||||
width.toLong()
|
||||
)
|
||||
|
||||
@@ -39,6 +39,8 @@ fun main(args: Array<String>) {
|
||||
|
||||
|
||||
|
||||
val rangeSize = 64
|
||||
val textLen = (rangeSize - 1).toString().length
|
||||
for (tries in 0 until 16) {
|
||||
repeat(BlockCodex.DYNAMIC_RANDOM_CASES + 12) { repeats ->
|
||||
val x = 349 + repeats
|
||||
@@ -48,7 +50,7 @@ fun main(args: Array<String>) {
|
||||
val offset = XXHash32.hash(((x and 0xFFFF).shl(16) or (y and 0xFFFF)).toLittle(), 10000)
|
||||
|
||||
//print("${offset.toString().padStart(2, '0')} ")
|
||||
print("${offset.fmod(BlockCodex.DYNAMIC_RANDOM_CASES).toString().padStart(2, '0')} ")
|
||||
print("${offset.fmod(rangeSize).toString().padStart(textLen, '0')} ")
|
||||
}
|
||||
println()
|
||||
println()
|
||||
|
||||
@@ -19,30 +19,11 @@ class UnsafeTest {
|
||||
private val memsize = 512L // must be big enough value so that your OS won't always return zero-filled pieces
|
||||
|
||||
fun main() {
|
||||
var ptr = unsafe.allocateMemory(memsize)
|
||||
printDump(ptr)
|
||||
val intarray = intArrayOf(5,4,3,2,1)
|
||||
|
||||
unsafe.setMemory(ptr, memsize, 0x00.toByte())
|
||||
printDump(ptr)
|
||||
val arrayBaseOffset = UnsafeHelper.getArrayOffset(intarray) // should be 16 or 12 on 64-bit JVM
|
||||
|
||||
for (k in 0 until 13) {
|
||||
unsafe.putByte(ptr + k, (-1 - k).toByte())
|
||||
}
|
||||
printDump(ptr)
|
||||
|
||||
// test shingled memory copy -- how would it work out?
|
||||
UnsafeHelper.memcpy(ptr, ptr + 3L, 13L)
|
||||
|
||||
printDump(ptr)
|
||||
|
||||
|
||||
println(ptr)
|
||||
ptr = unsafe.reallocateMemory(ptr, 256L)
|
||||
println(ptr)
|
||||
|
||||
|
||||
// that's all for today!
|
||||
unsafe.freeMemory(ptr)
|
||||
println(arrayBaseOffset)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user