Skip to content

Commit

Permalink
add to bittwiddling test
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Apr 3, 2018
1 parent 0ac5b4c commit 7a7c4f5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/test/scala/ExamplesNoCompressed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class ExamplesNoCompressed extends FreeSpec with PropertyChecks with Matchers {
"""
|5, 0, 5
|0, 20, 57, 77
|20, 57
""".trim.stripMargin
}

Expand Down
13 changes: 13 additions & 0 deletions tests/bittwiddling.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ printn( int n ) {
int
abs( int x ) {
const int bit31 = x >> 31;

return (x ^ bit31) - bit31;
}

Expand All @@ -63,6 +64,13 @@ modifyBit( int x, unsigned char position, int newState ) {
return (x & ~mask) | (-state & mask);
}

int
flipBit( int x, unsigned char position ) {
int mask = 1 << position;

return x ^ mask;
}

void
main() {
printn( abs(5) );
Expand All @@ -80,4 +88,9 @@ main() {
print( ", " );
printn( modifyBit(0x77, 5, 1) );//0x77
println();

printn( flipBit(0, 5) );//20
print( ", " );
printn( flipBit(0x77, 5) );//57
println();
}
50 changes: 30 additions & 20 deletions tests/bittwiddling.hex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Hex dump of section '.text':
0x00010080 37010100 ef00c033 73500000 00000000 7......3sP......
0x00010080 37010100 ef000039 73500000 00000000 7......9sP......
0x00010090 00000000 00000000 00000000 00000000 ................
0x000100a0 00000000 00000000 00000000 00000000 ................
0x000100b0 00000000 00000000 00000000 00000000 ................
Expand All @@ -17,8 +17,8 @@ Hex dump of section '.text':
0x00010160 03340100 13010101 67800000 130101fc .4......g.......
0x00010170 233c8102 13040104 93070500 13870500 #<..............
0x00010180 2330c4fc 2326f4fc 93070700 2324f4fc #0..#&......#$..
0x00010190 b7070100 03b7074b 2338e4fc 1387074b .......K#8.....K
0x000101a0 03378700 233ce4fc 9387074b 83c70701 .7..#<.....K....
0x00010190 b7070100 03b78754 2338e4fc 13878754 .......T#8.....T
0x000101a0 03378700 233ce4fc 93878754 83c70701 .7..#<.....T....
0x000101b0 2300f4fe 833704fc 93871702 2334f4fe #....7......#4..
0x000101c0 8327c4fc 2322f4fe 8327c4fc 9b870700 .'..#"...'......
0x000101d0 63d80700 832744fe bb07f040 2322f4fe c....'D....@#"..
Expand Down Expand Up @@ -52,24 +52,34 @@ Hex dump of section '.text':
0x00010390 832784fe bb07f040 9b860700 8327c4fe .'.....@.....'..
0x000103a0 b3f7f600 9b870700 b367f700 9b870700 .........g......
0x000103b0 13850700 03348102 13010103 67800000 .....4......g...
0x000103c0 130101ff 23341100 23308100 13040101 ....#4..#0......
0x000103d0 13055000 eff01fec b7070100 1385874c ..P............L
0x000103e0 eff01fd1 13050000 eff0dfea b7070100 ................
0x000103f0 1385874c eff0dfcf 13055000 eff09fe9 ...L......P.....
0x00010400 eff01fd4 13060000 93055000 13050000 ..........P.....
0x00010410 eff01ff2 93070500 13850700 eff09fe7 ................
0x00010420 b7070100 1385874c eff09fcc 13061000 .......L........
0x00010430 93055000 13050000 eff09fef 93070500 ..P.............
0x00010440 13850700 eff01fe5 b7070100 1385874c ...............L
0x00010450 eff01fca 13060000 93055000 13057007 ..........P...p.
0x00010460 eff01fed 93070500 13850700 eff09fe2 ................
0x00010470 b7070100 1385874c eff09fc7 13061000 .......L........
0x00010480 93055000 13057007 eff09fea 93070500 ..P...p.........
0x00010490 13850700 eff01fe0 eff09fca 13000000 ................
0x000104a0 83308100 03340100 13010101 67800000 .0...4......g...
0x000103c0 130101fd 23348102 13040103 93070500 ....#4..........
0x000103d0 13870500 232ef4fc 93070700 a30df4fc ....#...........
0x000103e0 8347b4fd 9b870700 13071000 bb17f700 .G..............
0x000103f0 2326f4fe 0327c4fd 8327c4fe b347f700 #&...'...'...G..
0x00010400 9b870700 13850700 03348102 13010103 .........4......
0x00010410 67800000 130101ff 23341100 23308100 g.......#4..#0..
0x00010420 13040101 13055000 eff0dfe6 b7070100 ......P.........
0x00010430 13850756 eff0dfcb 13050000 eff09fe5 ...V............
0x00010440 b7070100 13850756 eff09fca 13055000 .......V......P.
0x00010450 eff05fe4 eff0dfce 13060000 93055000 .._...........P.
0x00010460 13050000 eff0dfec 93070500 13850700 ................
0x00010470 eff05fe2 b7070100 13850756 eff05fc7 .._........V.._.
0x00010480 13061000 93055000 13050000 eff05fea ......P......._.
0x00010490 93070500 13850700 eff0dfdf b7070100 ................
0x000104a0 13850756 eff0dfc4 13060000 93055000 ...V..........P.
0x000104b0 13057007 eff0dfe7 93070500 13850700 ..p.............
0x000104c0 eff05fdd b7070100 13850756 eff05fc2 .._........V.._.
0x000104d0 13061000 93055000 13057007 eff05fe5 ......P...p..._.
0x000104e0 93070500 13850700 eff0dfda eff05fc5 .............._.
0x000104f0 93055000 13050000 eff09fec 93070500 ..P.............
0x00010500 13850700 eff01fd9 b7070100 13850756 ...............V
0x00010510 eff01fbe 93055000 13057007 eff05fea ......P...p..._.
0x00010520 93070500 13850700 eff0dfd6 eff05fc1 .............._.
0x00010530 13000000 83308100 03340100 13010101 .....0...4......
0x00010540 67800000 g...


Hex dump of section '.rodata':
0x000104b0 30313233 34353637 38394142 43444546 0123456789ABCDEF
0x000104c0 00000000 00000000 2c2000 ........, .
0x00010548 30313233 34353637 38394142 43444546 0123456789ABCDEF
0x00010558 00000000 00000000 2c2000 ........, .

0 comments on commit 7a7c4f5

Please sign in to comment.