Forum Discussion
5 Replies
- Altera_Forum
Honored Contributor
A custom instruction can only process two 32bit input values [1] and generate a single 32bit output value. It can change local state - provided it is a multi-cycle custom instruction and not a combinatorial one.
Combinatorial custom instructions are passed input data for EVERY instruction cycle, the output value will be used if the instruction decode indicates that it is required (this is how all the ALU instructions work). So it isn't clear how you intend doing 128bit arithmetic! You could do 64bit arithmetic using an external accumulator, passing the input values in rA and rB, and the opcode in C (with readrc = 0). You'd then need some way of reading the result, either a 2nd (combinatorial) custom instruction, or (maybe) if readrc = 1, use A (or B) (the 5 bit number) to determine which part of the result to read. Maybe you could do 128bit in a similar way - but you'd need to use two instructions to set a 128bit input value. [1] It actually has all of the 32bit instruction (ie the register numbers and the ra/rb/rc fields) and the two source register values as inputs. The register file is very likely to always be read for the 'A' and 'B' register numbers, and I strongly suspect that the readra/readrb fields are not used to disable a pipeline stall (ie they have no effect on the system logic). - Altera_Forum
Honored Contributor
--- Quote Start --- Combinatorial custom instructions are passed input data for EVERY instruction cycle, the output value will be used if the instruction decode indicates that it is required (this is how all the ALU instructions work). --- Quote End --- I'm not very understand... As i pass my 32-bit input to the combinatorial custom instruction, the result will be retrieve after a clock cycle and the program will proceed. Isn't that so? Why you saying that "input data for EVERY instruction cycle"? Thanks.. - Altera_Forum
Honored Contributor
Because the instruction processing only has a multiplexor that selects between the OUTPUT of all the combinatorial instructions.
There are no 'enables' on the inputs. - Altera_Forum
Honored Contributor
i see.. thanks for your help.. now i have clearer picture.
btw.. i have another question regarding the c code programming in nios II. As if i send a char type or any other type of data to the custom instruction, how will it be inteperate? ASCII or original data itself? thanks... - Altera_Forum
Honored Contributor
Everything is just a number!
The C 'char' type is just a 8-bit number, you can think of the input/output as using base 256 where some of the values are impossible to type! In C all arithmetic on types smaller than 'int' is done by converting the value to 'int', doing the maths, then masking off the high bits if the value is saved to a char variable. char is usually signed. (This is probably because the pdp11 only had a sign-extending byte read!) This means that 'unsigned char' gets promoted to 'int' (not 'unsigned int') unless 'sizeof (int) == 1'.