Only XOR gate synthesizing Yosys - xor

I want to synthesize a circuit with Yosys, but I want the synthesized circuit to consist only of XOR gates. how should I do?

synth; abc -g XOR
(this will actually map to XOR gates and inverters, which can easily be implemented using XOR gates. If you need a netlist of only XORs them techmap can be used to convert an inverter to a XOR with constant 1).

Related

Implementation of arithmetic shift in C/C++

Is there a way to implement the Left Arithmetic Shift and Right Arithmetic Shift, using only operations AND, OR, NOT, XOR?
In each of the operations AND, OR, NOT, and XOR, each bit in the result is solely a function of the one (OT) or two (AND, OR, XOR) bits in the same position in the operands. In a shift by any amount other than zero, each bit in the result is a function of a bit in a different position in the operand being shifted. Therefore, it is not possible to compute a shift solely from AND, OR, NOT, and XOR.
Consider a = 0b0011.
Then we have ~a = 0b1100.
We also have a | ~a = 0b1111.
And also a & ~a = 0b0000.
You can manually check all possible combinations of &, ^, ~, and | to see that we can't make anything more than those four binary values. None of which are 0b0110 (what we want from left shift) or 0b0001 (what we want from right shift).
Since we found a number for which it can't be done, then we know in general it can't be done.
IT IS POSSIBLE
Basically, the main logic of shifting is using shifters (barrel shifter and barrel shifter with multiplexers) which in turn can be created using multiplexers. And you can create multiplexers easily using the logical operations that you mentioned. Here is 2-to-1 MUX created with NAND gates: Mux with NAND

LTO CM CRC Function

I'm looking for some advice on writing a C function to calculate a 16 bit CRC for an LTO RFID chip.
The spec says:
For commands and data that are protected by the 16-bit CRC, the
generator polynomial shall be G(x) = x16 + x12 + x5 + 1 The CRC bytes
shall be generated by processing all bytes through a generator
circuit. See figure F.11. Registers R0 to R15 shall be 1 bit wide
where R0 shall be the least significant bit and R15 the most
significant bit. These registers shall be set to (6363) prior to the
beginning of processing. The bytes shall be fed sequentially into the
encoder, least significant bit first. After the bytes have been
processed, the content of R0 is CRC0 and shall be the least
significant bit. The content of R15 is CRC15 and shall be the most
significant bit.
But I've just a humble self taught C programmer and that means nothing to me.
Can anybody help me with some code, or an explanation of the formula?
The diagram in the ECMA 319 Standard shows what to do:
though it contains an error. The exclusive-or between R11 and R10 should have another input tapped off the wire going to R15.
The bits from the input come in the wire at the top, starting with the least significant bit from the first input byte. At each clock, each register is set to its input. The plus signs in circles are exclusive-or gates.
You can implement this in C with the bit-wise operations ^, &, and >>. Enjoy!

Bit shift using instruction add and nor in LC-2K

I'm trying to do logical shift right and logical shift left by just using LC-2K instructions only! In ARM ISA, assembly language, there are LSR and LSL for writing bit shifting in assembly language but LC-2K does not have such options.
The only options that's available in LC-2K are:
Lw, sw, beq, jalr, add, nor, noop, halt.
I can't seem to find a way to do any bit shifting by just using these few instructions possible in LC-2K assembly language.
Please give me some advices.
Thank you in advance!
You can shift left 1 by adding a register to itself. You can shift left by more than one using a loop.
Right shift can be done with a loop that copies all of the bits except the bottom one to a scratch register, then copies the scratch register back to the source. I'm not familiar with LC-2K, but nor should be enough to let you mask off bits, beq will let you test whether the masked bit is set, and add will let you copy the bit to the destination register as well as shifting the working bit one left before looping. The easiest way I can think of uses two counters, one starting at 1 (for writing) and the other starting at 2 (for reading). There's probably other ways to do it, but that one occurs to me.

In ARM Processor, How to determine if a shift is right or left shift?

I am working on a software-based implementation of ARM processor in C.
Given an ARM data processing instruction:
instruction = 0xE3A01808; 1110 0 0 1 1101 0 0000 0001 1000 00001000
Which translates to: MOV r0,#8; shifted by 8 bits.
How to check whether the 8 bit shift is right or left shift?
With ARM 12-bit modified immediate constants, there is no shift, in any direction - it's a rotation, specifically, <7:0> rotated right by 2*<11:8>. Thus the encoding 0x808 represents 8 ROR (2*8), meaning 0xE3A01808 disassembles to mov, r1, #0x80000.
(Note that the canonical encoding of a modified immediate constant is the one with the smallest rotation, so mov, r1, #0x80000 would assemble to 0xE3A01702, i.e. 2 ROR 14, rather than 8 ROR 161).
As for implementing bitwise rotation in C, to solve that there's either compiler intrinsics or the standard shift-part-in-each-direction idiom x>>n | x<<(32-n).
[1] To get a specific encoding, UAL assembly allows an immediate syntax with the constant and rotation specified separately, i.e. mov r1, #8, 16. For full detail, this is all spelled out in the ARM ARM (section A5.2.4 in the v7 issue C I have here) - essentially, the choice of encodings permits a little funny business with flags in certain situations.
I'm not sure if this is what you're referring to, but here's some documentation that seems relevant:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0040d/ch05s05s01.html
The 'WITHDRAWN' pasted over the docs doesn't inspire much confidence.
It would seem to suggest a rotate right. Which plays with how I remember the barrel shifter being addressed on arm more generally (There's a ROR operation for instance, see http://www.davespace.co.uk/arm/introduction-to-arm/barrel-shifter.html)

Most efficient way to xor byte array in vb.net

I am making making an application in vb.net that will read files using a byte array as buffer, and create parity files for them by xoring the data... What would be the most efficient way of xoring a byte array? I have though of convertinbg the byte array to a bitarray and then run it trough an xor operation and turn it back to a byte array, but that sounds like a very processing expensive task, and i am worried that it might impact read/write speed... is there a better way to do this? thanks...
To avoid confusion:
What the application does is read half the file to location 1, the other half to location 2, then a parity (xor of the two parts) to location 3...
To Xor two byte arrays simply use a for loop and the Xor operator.
VB.Net's Xor will compile to a the CIL Xor opcode which should be subsequently JIT compiled to the very fast x86 XOR processor instruction.
The cost of the Xor operation is likely to be negligible in comparison to the cost of file I/O.
Depending on what you mean by "efficient" I think you can do better than a simple loop. My initial though is to break the processing into multiple threads. so it will complete faster. You know the size of the input array and therefore the output array so it would be easy to divide load and let each thread fill the appropriate part of the result.
There is a C# article on code project that does similar. Binary operations on byte arrays withparallelism

Resources