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

Implements the OP_SHR opcode logical right shift (uint32). More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 free_value (vs)
 free_value (va)
 push_value (vm, make_int((int64_t)(uint64_t) r))

Variables

case OP_SHR
Value va = pop_value(vm)
uint32_t a = (va.type == VAL_INT) ? (uint32_t)va.i : 0u
uint32_t s = (vs.type == VAL_INT) ? (uint32_t)vs.i : 0u
s &uint32_t r = (s == 0u) ? a : (a >> s)
 break

Detailed Description

Implements the OP_SHR opcode logical right shift (uint32).

Opcode snippet included by vm.c. Performs a 32-bit unsigned logical right shift of an integer operand by a masked shift count.

Stack effects:

  • pops: s, a
  • pushes: (uint32_t)(a >> (s & 31))

Notes:

  • Both a (value) and s (shift) are taken from VAL_INT; non-integers are 0.
  • The shift count is masked to 0..31. A zero shift returns a unchanged.
  • Logical (zero-filling) right shift is used (no sign extend).
  • Result is pushed as VAL_INT with the 32-bit value preserved in the low bits.

Definition in file shr.c.

Function Documentation

◆ free_value() [1/2]

free_value(va)

◆ free_value() [2/2]

free_value(vs)

◆ push_value()

push_value(vm,
make_int((int64_t)(uint64_t) r) )

Variable Documentation

◆ a

uint32_t a = (va.type == VAL_INT) ? (uint32_t)va.i : 0u

Definition at line 31 of file shr.c.

◆ break

break

Definition at line 38 of file shr.c.

◆ OP_SHR

case OP_SHR

Definition at line 28 of file shr.c.

◆ r

s& uint32_t r = (s == 0u) ? a : (a >> s)

Definition at line 34 of file shr.c.

◆ s

uint32_t s = (vs.type == VAL_INT) ? (uint32_t)vs.i : 0u

Definition at line 32 of file shr.c.

◆ va

Value va = pop_value(vm)

Definition at line 30 of file shr.c.