Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
uclamp.c File Reference

Implements the OP_UCLAMP opcode for unsigned N-bit wrapping. More...

Go to the source code of this file.

Functions

 if (bits<=0)
else if (bits >=64)
 push_value (vm, make_int((int64_t) wrapped))
 free_value (v)

Variables

case OP_UCLAMP
int bits = inst.operand
int64_t vi = (v.type == VAL_INT) ? v.i : 0
uint64_t mask
 else
uint64_t wrapped = ((uint64_t)vi) & mask
 break

Detailed Description

Implements the OP_UCLAMP opcode for unsigned N-bit wrapping.

This VM opcode masks an integer to the lower N bits (N taken from the instruction operand), effectively performing an unsigned wrap-around into the range [0 .. 2^N - 1].

Stack contract:

  • Pops: value (int)
  • Pushes: value (int)

Definition in file uclamp.c.

Function Documentation

◆ free_value()

free_value(v)

◆ if() [1/2]

else if(bits >=64)

Definition at line 32 of file uclamp.c.

◆ if() [2/2]

if(bits<=0)

Definition at line 30 of file uclamp.c.

◆ push_value()

push_value(vm,
make_int((int64_t) wrapped) )

Variable Documentation

◆ bits

int bits = inst.operand

Definition at line 26 of file uclamp.c.

◆ break

break

Definition at line 41 of file uclamp.c.

◆ else

else
Initial value:
{
mask = (1ULL << bits) - 1ULL
int bits
Definition sclamp.c:30
uint64_t mask
Definition uclamp.c:29

Definition at line 34 of file uclamp.c.

◆ mask

uint64_t mask

Definition at line 29 of file uclamp.c.

◆ OP_UCLAMP

case OP_UCLAMP

Definition at line 23 of file uclamp.c.

◆ vi

int64_t vi = (v.type == VAL_INT) ? v.i : 0

Definition at line 27 of file uclamp.c.

◆ wrapped

uint64_t wrapped = ((uint64_t)vi) & mask

Definition at line 38 of file uclamp.c.