<commit_before>package is.hail.annotations

import is.hail.asm4s
import is.hail.asm4s.{Code, coerce}
import is.hail.expr.types.physical._
import is.hail.utils._

object Region {
  type Size = Int
  val REGULAR: Size = 0
  val SMALL: Size = 1
  val TINY: Size = 2
  val TINIER: Size = 3

  val SIZES: Array[Long] = Array(64 * 1024, 8 * 1024, 1024, 256)
  val BLOCK_THRESHOLD: Long = 4 * 1024

  def scoped[T](f: Region => T): T = using(Region())(f)

  def smallScoped[T](f: Region => T): T = using(Region(SMALL))(f)

  def tinyScoped[T](f: Region => T): T = using(Region(TINY))(f)

  def loadInt(addr: Long): Int = Memory.loadInt(addr)

  def loadLong(addr: Long): Long = Memory.loadLong(addr)

  def loadFloat(addr: Long): Float = Memory.loadFloat(addr)

  def loadDouble(addr: Long): Double = Memory.loadDouble(addr)

  def loadAddress(addr: Long): Long = Memory.loadLong(addr)

  def loadByte(addr: Long): Byte = Memory.loadByte(addr)

  def storeInt(addr: Long, v: Int): Unit = Memory.storeInt(addr, v)

  def storeLong(addr: Long, v: Long): Unit = Memory.storeLong(addr, v)

  def storeFloat(addr: Long, v: Float): Unit = Memory.storeFloat(addr, v)

  def storeDouble(addr: Long, v: Double): Unit = Memory.storeDouble(addr, v)

  def storeAddress(addr: Long, v: Long): Unit = Memory.storeAddress(addr, v)

  def storeByte(addr: Long, v: Byte): Unit = Memory.storeByte(addr, v)

  def loadBoolean(addr: Long): Boolean = if (Memory.loadByte(addr) == 0) false else true

  def storeBoolean(addr: Long, v: Boolean): Unit = Memory.storeByte(addr, if (v) 1 else 0)

  def loadBytes(addr: Long, n: Int): Array[Byte] = {
    val a = new Array[Byte](n)
    Memory.copyToArray(a, 0, addr, n)
    a
  }

  def loadBytes(addr: Long, dst: Array[Byte], dstOff: Long, n: Long): Unit =
    Memory.copyToArray(dst, dstOff, addr, n)

  def storeBytes(addr: Long, src: Array[Byte]): Unit =
    Memory.copyFromArray(addr, src, 0, src.length)

  def storeBytes(addr: Long, src: Array[Byte], srcOff: Long, n: Long): Unit =
    Memory.copyFromArray(addr, src, srcOff, n)

  def copyFrom(srcOff: Long, dstOff: Long, n: Long): Unit =
    Memory.memcpy(dstOff, srcOff, n)

  def setMemory(offset: Long, size: Long, b: Byte): Unit = Memory.memset(offset, size, b)

  def loadBit(byteOff: Long, bitOff: Long): Boolean = {
    val b = byteOff + (bitOff >> 3)
    (loadByte(b) & (1 << (bitOff & 7))) != 0
  }

  def setBit(byteOff: Long, bitOff: Long) {
    val b = byteOff + (bitOff >> 3)
    storeByte(b,
      (loadByte(b) | (1 << (bitOff & 7))).toByte)
  }
<commit_msg>[hail] Implement memset with a while loop (#7049)<commit_after>package is.hail.annotations

import is.hail.asm4s
import is.hail.asm4s.{Code, coerce}
import is.hail.expr.types.physical._
import is.hail.utils._

object Region {
  type Size = Int
  val REGULAR: Size = 0
  val SMALL: Size = 1
  val TINY: Size = 2
  val TINIER: Size = 3

  val SIZES: Array[Long] = Array(64 * 1024, 8 * 1024, 1024, 256)
  val BLOCK_THRESHOLD: Long = 4 * 1024

  def scoped[T](f: Region => T): T = using(Region())(f)

  def smallScoped[T](f: Region => T): T = using(Region(SMALL))(f)

  def tinyScoped[T](f: Region => T): T = using(Region(TINY))(f)

  def loadInt(addr: Long): Int = Memory.loadInt(addr)

  def loadLong(addr: Long): Long = Memory.loadLong(addr)

  def loadFloat(addr: Long): Float = Memory.loadFloat(addr)

  def loadDouble(addr: Long): Double = Memory.loadDouble(addr)

  def loadAddress(addr: Long): Long = Memory.loadLong(addr)

  def loadByte(addr: Long): Byte = Memory.loadByte(addr)

  def storeInt(addr: Long, v: Int): Unit = Memory.storeInt(addr, v)

  def storeLong(addr: Long, v: Long): Unit = Memory.storeLong(addr, v)

  def storeFloat(addr: Long, v: Float): Unit = Memory.storeFloat(addr, v)

  def storeDouble(addr: Long, v: Double): Unit = Memory.storeDouble(addr, v)

  def storeAddress(addr: Long, v: Long): Unit = Memory.storeAddress(addr, v)

  def storeByte(addr: Long, v: Byte): Unit = Memory.storeByte(addr, v)

  def loadBoolean(addr: Long): Boolean = if (Memory.loadByte(addr) == 0) false else true

  def storeBoolean(addr: Long, v: Boolean): Unit = Memory.storeByte(addr, if (v) 1 else 0)

  def loadBytes(addr: Long, n: Int): Array[Byte] = {
    val a = new Array[Byte](n)
    Memory.copyToArray(a, 0, addr, n)
    a
  }

  def loadBytes(addr: Long, dst: Array[Byte], dstOff: Long, n: Long): Unit =
    Memory.copyToArray(dst, dstOff, addr, n)

  def storeBytes(addr: Long, src: Array[Byte]): Unit =
    Memory.copyFromArray(addr, src, 0, src.length)

  def storeBytes(addr: Long, src: Array[Byte], srcOff: Long, n: Long): Unit =
    Memory.copyFromArray(addr, src, srcOff, n)

  def copyFrom(srcOff: Long, dstOff: Long, n: Long): Unit =
    Memory.memcpy(dstOff, srcOff, n)

  def setMemory(offset: Long, size: Long, b: Byte): Unit = {
    var x = 0L
    while (x < size) {
      Memory.storeByte(offset + x, b)
      x += 1
    }
  }

  def loadBit(byteOff: Long, bitOff: Long): Boolean = {
    val b = byteOff + (bitOff >> 3)
    (loadByte(b) & (1 << (bitOff & 7))) != 0
  }

  def setBit(byteOff: Long, bitOff: Long) {
    val b = byteOff + (bitOff >> 3)
    storeByte(b,
      (loadByte(b) | (1 << (bitOff & 7))).toByte)
  }

{'fraction_non_alphanumeric': 0.15326923076923077, 'fraction_numerical': 0.016923076923076923, 'mean_word_length': 3.824675324675325, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5390696', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1879, 'n_words': 555}