* src/hc08/gen.c (transferAopAop): aop forced to stack was not restored,
[fw/sdcc] / support / regression / tests / shifts.c
index 2cab46ac6b3145fd7fdb96f4e57bbdc78b939192..200caffba63141e040a32c2b86209e2e70abe1d0 100644 (file)
@@ -1,6 +1,7 @@
 /** Tests covering the shift operators.
 
-    type: char, int
+    sign: signed, unsigned
+    type: char, int, long
     storage: static, 
     attr: volatile
 
 */
 #include <testfwk.h>
 
-static void
+void
 testShiftClasses(void)
 {
-    {attr} {storage} {type} i, result;
+    {attr} {storage} {sign} {type} i, result;
 
     i = 30;
     ASSERT(i>>3 == 3);
@@ -28,30 +29,46 @@ testShiftClasses(void)
     ASSERT(result == 120);
 }
 
-/** PENDING: Disabled. */
+void
+testShiftRight(void)
+{
+    {attr} {storage} {type} i, result;
+
+    i = -120;
+    ASSERT(i>>1 == -60);
+    ASSERT(i>>2 == -30);
+    ASSERT(i>>3 == -15);
+    ASSERT(i>>4 == -8);
+    ASSERT(i>>5 == -4);
+    ASSERT(i>>6 == -2);
+    ASSERT(i>>7 == -1);
+    ASSERT(i>>8 == -1);
+    result = i;
+    result >>= 3;
+    ASSERT(result == -15); 
+}
+
 static void
 testShiftByteMultiples(void)
 {
-#if 0
     {attr} {storage} {type} i;
 
     i = ({type}){vals};
-    ASSERT(i>>8  == (({type}){vals} >> 8));
-    ASSERT(i>>16 == (({type}){vals} >> 16));
-    ASSERT(i>>24 == (({type}){vals} >> 24));
+    ASSERT(i>>8  == ({type})({vals} >> 8));
+    ASSERT(i>>16 == ({type})({vals} >> 16));
+    ASSERT(i>>24 == ({type})({vals} >> 24));
 
     i = ({type}){vals};
-    ASSERT(i<<8  == (({type}){vals} << 8));;
-    ASSERT(i<<16 == (({type}){vals} << 16));
-    ASSERT(i<<24 == (({type}){vals} << 24));
-#endif
+    ASSERT( ({type})(i<<8)  ==  ({type})({vals} << 8));;
+    ASSERT((({type}) i<<16) == (({type}) {vals} << 16));
+    ASSERT((({type}) i<<24) == (({type}) {vals} << 24));
 }
 
 static void
 testShiftOne(void)
 {
-    {attr} {storage} {type} i;
-    {type} result;
+    {attr} {storage} {sign} {type} i;
+    {sign} {type} result;
 
     i = ({type}){vals};
 
@@ -69,3 +86,24 @@ testShiftOne(void)
     result <<= 1;
     ASSERT(result == ({type})(({type}){vals} << 1));
 }
+
+static {type} ShiftLeftByParam ({type} count)
+{
+    {attr} {storage} {type} i;
+    i = ({type}){vals};
+    return (i << count);
+}
+
+static {type} ShiftRightByParam ({type} count)
+{
+    {attr} {storage} {type} i;
+    i = ({type}){vals};
+    return (i >> count);
+}
+
+void
+testShiftByParam(void)
+{
+    ASSERT(ShiftLeftByParam(2)  == ({type})({vals} << 2));
+    ASSERT(ShiftRightByParam(2) == ({type})({vals} >> 2));
+}