darn

Deliver A Random Number

darn RT, L

Returns a random number from the hardware RNG. (L=3: Raw, L=1: Conditioned, L=0: 32-bit).

Details

Delivers a random number from the hardware random number generator into GPR RT. The L field controls the output mode: L=3 returns raw entropy, L=1 returns conditioned/whitened entropy, and L=0 returns a 32-bit conditioned value. This instruction requires the darn facility to be enabled and does not affect any condition or status registers.

Pseudocode Operation

if L = 3 then
  RT ← raw_random_64()
elif L = 1 then
  RT ← conditioned_random_64()
elif L = 0 then
  RT ← (0 || conditioned_random_32())
else
  UNDEFINED

Programming Note

The random number generator provides a minimum of 0.5 bits of entropy per bit. For L=0, the random number range is 0:0xFFFFFFFF. For L=1 and L=2, the random number range is 0:0xFFFFFFFF_FFFFFFFE. L=3 is reserved. A raw random number is unconditioned noise source output. A conditioned random number has been processed by hardware to reduce bias. 32-bit software running in an environment that does not preserve the high-order 32 bits of GPRs across invocations of the system error handler, signal handlers, event-based branch handlers, etc., may use the L=0 variant of darn and interpret the value 0xFFFFFFFF to indicate an error condition. When the error value is obtained, software is expected to repeat the operation. If a non-error value has not been obtained after several attempts, a software random number generation method should be used.

Example

darn r3, 0

Encoding

Binary Layout
31
0
RT
6
/
11
L
14
755
16
/
21
 
Format X-form
Opcode 0x7C0005E6
Extension Base

Operands

  • RT
    Target
  • L
    Mode