CARDIAC › rust-cardiac › Message codes › RCW0001
RCW0001warning
An expensive operation.
warning[RCW0001]: expensive operation, consider an alternative: {ops}
The program uses a bit operation, which on CARDIAC is a long routine or a loop over the bits.
A cell holds a decimal number, not bits. &, | and ^ between two values, << and >> by a variable, and the bit methods (count_ones, leading_zeros, trailing_zeros, rotate_left, rotate_right) each walk a value's bits one at a time. The routines for &, | and ^ are 50 to 70 instructions each, put in once, and take about 200 steps a call; the bit methods are 20 to 40 cells where each is called. A program that uses one has far less of its 96 cells left. The program is right; it is just big and slow.
The warning comes once a program, naming each bit operation it uses. Multiplying and dividing two variables also call routines, and aren't warned about: they are what arithmetic costs on CARDIAC.
Decimal arithmetic is usually the alternative: / and % by a power of ten are shifts, digit() takes one digit, and x & m by a mask one below a power of two is a remainder, which needs no routine.
// flags packed in bits: a routine for &, and a shift by a variable
if flags & (1 << k) != 0 {
out(k);
}
// flags packed in digits (k is 0, 1 or 2): one shift
if digit(flags, k) == 1 {
out(k);
}
In a terminal: cargo cardiac help RCW0001.