Shop OBEX P1 Docs P2 Docs Learn Events
carry bit after max instruction — Parallax Forums

carry bit after max instruction

ersmithersmith Posts: 6,068
edited 2013-03-20 13:48 in Propeller 2
Has the behavior of the carry bit been changed for the max and min instructions? It sure seems that way, unless I'm missing something. I tried this simple program:
#include <stdio.h>
#include <propeller.h>

// returns the carry bit after max a,b
extern _NATIVE int testmax(int a, int b);

__asm__(
"   .section .kernel    \n"
"    .global _testmax    \n"
"_testmax               \n"
"    maxs  r0,r1 wc      \n"
"    mov      r0,#0         \n"
"    muxc  r0,#1         \n"
"_testmax_ret           \n"
"    ret                 \n"
    );

void runtest(int a, int b) {
    int c = testmax(a, b);
    printf("testmax(%d, %d)=%d\n", a, b, c);
}

void main() {
    runtest(1, 2);
    runtest(1, 1);
    runtest(2, 1);
 }

On P1 I get as output:
testmax(1, 2)=1
testmax(1, 1)=0
testmax(2, 1)=0

but on P2 I get:
testmax(1, 2)=0
testmax(1, 1)=0
testmax(2, 1)=1

Comments

  • cgraceycgracey Posts: 14,206
    edited 2013-03-20 08:53
    It HAS changed. I believe I made the MINx/MAXx instructions return 1 in C when D had to be changed. I haven't documented this yet, so I'll need to investigate, myself. I looked at the Verilog, but it wasn't clear to me, as the main adder is the most convoluted of all sections.
  • ersmithersmith Posts: 6,068
    edited 2013-03-20 13:48
    cgracey wrote: »
    It HAS changed. I believe I made the MINx/MAXx instructions return 1 in C when D had to be changed. I haven't documented this yet, so I'll need to investigate, myself. I looked at the Verilog, but it wasn't clear to me, as the main adder is the most convoluted of all sections.

    Thanks for the reply! We were using the old behavior in the PropGCC float code. It's not a big deal to change it (it just means adding a "cmp" instruction) but it did kind of surprise me :-).

    I guess there's an argument to be made for either behavior. The P1 one was convenient for some things (carry was set if at the end the output D is different from S) but the P2 way is logical too (carry is set if D had to change). At any rate I'm sure it's too late to make any changes, except to the documentation to point out the difference.

    Eric
Sign In or Register to comment.