Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
19660 Discussions

Flex 10k LPM_ADD_SUB issue

Altera_Forum
Honored Contributor II
834 Views

Hi There! 

 

Not sure if this has been addressed but instantiating an lpm_add_sub function with carry in- and out under 9.0sp2 (IIRC) for Flex 10K seems to have some peculiar behavior. The add / adc works as advertised whereas the sub/sbc seems to have... problems. For instance, using unsigned 8-bit, subtracting one from 128 (0x80) results in 0x7e *with* a carry, which obviously is wrong.. 

 

The reason I've been going for LPM functions for some of these is that they're more resource friendly as the synthesis isn't all that great in recognizing counters, adders, etc. 

 

I'll poke around tonight and isolate it but without carry in/out, I've never had issues IIRC. 

 

-Mux 

 

Edit: Isolating the addsub function and running the same values as the waveforms seems to give the correct result, so I guess I need to double check what's wrong.. Will let you folks know for completeness!
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
99 Views

Alright, figured it out.. While I blindly duplicated the waveform figures it appears that the carry needs to be inverted for subtraction. This makes total sense when you think about it being two's complement and using the adder, but it's not documented anywhere, as far as I can see.. 

 

So yeah, RTFM and watch those waveforms! 

 

-Mux
Reply