Skip to content

Commit

Permalink
update for zig master
Browse files Browse the repository at this point in the history
  • Loading branch information
leecannon committed Jun 26, 2023
1 parent e70fba9 commit 644210c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 38 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ The `Bitfield`, `Bit` & `Boolean` types are taken pretty much verbatim from [Flo

## How to get

### Gyro

`gyro add leecannon/bitjuggle`

### Zigmod

`zigmod aq add 1/leecannon/bitjuggle`

### Git

#### Submodule

`git submodule add https://github.com/leecannon/zig-bitjuggle zig-bitjuggle`
Expand Down
13 changes: 6 additions & 7 deletions bitjuggle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ test "getBit - comptime_int" {
/// ```
pub fn getBits(target: anytype, comptime start_bit: comptime_int, comptime number_of_bits: comptime_int) std.meta.Int(.unsigned, number_of_bits) {
const TargetType = @TypeOf(target);
const ReturnType = std.meta.Int(.unsigned, number_of_bits);

comptime {
if (number_of_bits == 0) @compileError("non-zero number_of_bits must be provided");
Expand All @@ -144,7 +143,7 @@ pub fn getBits(target: anytype, comptime start_bit: comptime_int, comptime numbe
}
}

return @truncate(ReturnType, target >> start_bit);
return @truncate(target >> start_bit);
}

test "getBits" {
Expand Down Expand Up @@ -305,17 +304,17 @@ pub fn Bitfield(comptime FieldType: type, comptime shift_amount: usize, comptime

// This function uses `anytype` inorder to support both const and non-const pointers
inline fn field(self: anytype) PtrCastPreserveCV(Self, @TypeOf(self), FieldType) {
return @ptrCast(PtrCastPreserveCV(Self, @TypeOf(self), FieldType), self);
return @ptrCast(self);
}

pub fn write(self: *Self, val: ValueType) void {
self.field().* &= ~self_mask;
self.field().* |= @intCast(FieldType, val) << shift_amount;
self.field().* |= @as(FieldType, @intCast(val)) << shift_amount;
}

pub fn read(self: Self) ValueType {
const val: FieldType = self.field().*;
return @intCast(ValueType, (val & self_mask) >> shift_amount);
return @intCast((val & self_mask) >> shift_amount);
}
};
}
Expand Down Expand Up @@ -358,13 +357,13 @@ fn BitType(comptime FieldType: type, comptime shift_amount: usize, comptime Valu
}

pub fn read(self: Self) ValueType {
return @bitCast(ValueType, @truncate(u1, self.bits.field().* >> shift_amount));
return @bitCast(@as(u1, @truncate(self.bits.field().* >> shift_amount)));
}

// Since these are mostly used with MMIO, I want to avoid
// reading the memory just to write it again, also races
pub fn write(self: *Self, val: ValueType) void {
if (@bitCast(bool, val)) {
if (@as(bool, @bitCast(val))) {
self.set();
} else {
self.unset();
Expand Down
15 changes: 0 additions & 15 deletions gyro.zzz

This file was deleted.

6 changes: 0 additions & 6 deletions zig.mod

This file was deleted.

0 comments on commit 644210c

Please sign in to comment.