Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libISA/runtime_ac.ml
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,9 @@ module Runtime : RT.RuntimeLib = struct
RT.pp_expr x

let zero_extend_bits (fmt : PP.formatter) (m : int) (n : int) (x : RT.rt_expr) : unit =
PP.fprintf fmt "((%a)%a)"
PP.fprintf fmt "((%a)(%a)%a)"
ty_bits n
ty_bits m
RT.pp_expr x

let sign_extend_bits (fmt : PP.formatter) (m : int) (n : int) (x : RT.rt_expr) : unit =
Expand Down
3 changes: 2 additions & 1 deletion libISA/runtime_c23.ml
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,9 @@ module Runtime : RT.RuntimeLib = struct
RT.pp_expr y

let zero_extend_bits (fmt : PP.formatter) (m : int) (n : int) (x : RT.rt_expr) : unit =
PP.fprintf fmt "((%a)%a)"
PP.fprintf fmt "((%a)(%a)%a)"
ty_uint n
ty_uint m

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to skip this cast when n = m, to reduce the size of generated code.

RT.pp_expr x

let sign_extend_bits (fmt : PP.formatter) (m : int) (n : int) (x : RT.rt_expr) : unit =
Expand Down
15 changes: 15 additions & 0 deletions tests/backends/bits_zext_01.isa
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %aslrun %s | filecheck %s
// Copyright (C) 2023-2026 Intel Corporation

// This reproduces an actual bug found in a spec
function Test(x : Bits(8)) -> Bits(64)
begin
return Std::Bits::Zero_Extend(not x, 64);
end

function main() -> Builtin::Foreign::CInt
begin
Std::Print::Bits::Hex(Test(0x87)); Print("\n");
// CHECK: 64'x78
return Builtin::Foreign::CInt::From_Integer(0);
end