4 /* The FLOGR insn reads from register R2 and writes to register R1 and
5 R1 + 1. So we need to distinguish three cases:
7 (1) All three registers R1, R1 + 1, and R2 are distinct
11 These are tested by flogr1, flogr2, and flogr3, respectively. */
13 /* Call FLOGR on INPUT. The results are returned through the parms. */
15 /* R2 != R1 && R2 != R1 + 1 */
17 flogr1(unsigned long input
, unsigned long *bitpos
, unsigned long *modval
,
21 register unsigned long value
asm("4") = input
;
23 asm volatile ( FLOGR(2,4)
25 "stg 2, %[bitpos]\n\t"
26 "stg 3, %[modval]\n\t"
27 : [bitpos
]"=T"(*bitpos
), [modval
]"=T"(*modval
),
34 printf("value = %lx, bitpos = %lu, modval = %lx, cc = %d\n",
35 value
, *bitpos
, *modval
, *cc
);
41 flogr2(unsigned long input
, unsigned long *bitpos
, unsigned long *modval
,
45 register unsigned long value
asm("2") = input
;
47 asm volatile ( FLOGR(2,2)
49 "stg 2, %[bitpos]\n\t"
50 "stg 3, %[modval]\n\t"
51 : [bitpos
]"=T"(*bitpos
), [modval
]"=T"(*modval
),
52 [psw
]"=&d"(psw
), [val
] "+d"(value
)
58 printf("value = %lx, bitpos = %lu, modval = %lx, cc = %d\n",
59 value
, *bitpos
, *modval
, *cc
);
65 flogr3(unsigned long input
, unsigned long *bitpos
, unsigned long *modval
,
69 register unsigned long value
asm("3") = input
;
71 asm volatile ( FLOGR(2,3)
73 "stg 2, %[bitpos]\n\t"
74 "stg 3, %[modval]\n\t"
75 : [bitpos
]"=T"(*bitpos
), [modval
]"=T"(*modval
),
76 [psw
]"=&d"(psw
), [val
] "+d"(value
)
82 printf("value = %lx, bitpos = %lu, modval = %lx, cc = %d\n",
83 value
, *bitpos
, *modval
, *cc
);
88 runtest(void (*func
)(unsigned long, unsigned long *, unsigned long *,
91 unsigned long bitpos
, modval
, value
;
95 /* Value 0 is special */
97 func(value
, &bitpos
, &modval
, &cc
);
98 if (modval
!= 0) fprintf(stderr
, "modval is wrong for %lx\n", value
);
99 if (bitpos
!= 64) fprintf(stderr
, "bitpos is wrong for %lx\n", value
);
100 if (cc
!= 0) fprintf(stderr
, "cc is wrong for %lx\n", value
);
102 /* Test with exactly 1 bit set */
103 for (i
= 0; i
< 64; ++i
) {
105 func(value
, &bitpos
, &modval
, &cc
);
106 if (modval
!= 0) fprintf(stderr
, "modval is wrong for %lx\n", value
);
107 if (bitpos
!= 63 - i
) fprintf(stderr
, "bitpos is wrong for %lx\n", value
);
108 if (cc
!= 2) fprintf(stderr
, "cc is wrong for %lx\n", value
);
111 /* Test with all bits 1 right from first 1 bit */
112 for (i
= 1; i
< 64; ++i
) {
114 value
= value
| (value
- 1);
115 func(value
, &bitpos
, &modval
, &cc
);
116 if (modval
!= (value
>> 1)) fprintf(stderr
, "modval is wrong for %lx\n", value
);
117 if (bitpos
!= 63 - i
) fprintf(stderr
, "bitpos is wrong for %lx\n", value
);
118 if (cc
!= 2) fprintf(stderr
, "cc is wrong for %lx\n", value
);