summaryrefslogtreecommitdiff
path: root/system/base/1.7.5/src/bits
blob: e9e84e769f4049ab367247f213313798e674aef0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

PACKET bits DEFINES

    AND ,
    OR ,
    XOR ,
    bit ,
    lowest reset ,
    lowest set ,
    reset bit ,
    rotate ,
    set bit :

LET bits per int = 16 ;

ROW bits per int INT VAR bit mask := ROW bits per int INT:
    (1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,-32767-1) ;

PROC rotate (INT VAR bits, INT CONST number of bits) :
  EXTERNAL 83
ENDPROC rotate ;

INT OP AND (INT CONST left, right) :
  EXTERNAL 124
ENDOP AND ;

INT OP OR (INT CONST left, right) :
  EXTERNAL 125
ENDOP OR ;

INT OP XOR (INT CONST left, right) :
  EXTERNAL 121
ENDOP XOR ;

BOOL PROC bit (INT CONST bits, bit no) :

  (bits AND bit mask (bit no+1)) <> 0

ENDPROC bit ;

PROC set bit (INT VAR bits, INT CONST bit no) :

  bits := bits OR bit mask (bit no+1)

ENDPROC set bit ;

PROC reset bit (INT VAR bits,INT CONST bit no) :

  bits := bits XOR (bits AND bit mask (bit no+1))

ENDPROC reset bit ;

INT PROC lowest set (INT CONST bits) :

  INT VAR mask index ;
  FOR mask index FROM 1 UPTO 16 REP
    IF (bits AND bit mask (mask index)) <> 0
      THEN LEAVE lowest set WITH mask index - 1
    FI
  PER ;
  -1

ENDPROC lowest set ;

INT PROC lowest reset (INT CONST bits) :

  INT VAR mask index ;
  FOR mask index FROM 1 UPTO bits per int REP
    IF (bits AND bit mask (mask index)) = 0
      THEN LEAVE lowest reset WITH mask index - 1
    FI
  PER ;
  -1

ENDPROC lowest reset ;

ENDPACKET bits ;