Skip to content

Commit

Permalink
Simplified Scalar Args to better support int32s
Browse files Browse the repository at this point in the history
Improved cg_test_runner.cpp to use ArgT union type
  • Loading branch information
jrk committed Sep 2, 2011
1 parent 1edf4fb commit c04a6f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/brightness.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let sadd(a, b) =

let prgm =
Vectorize.vectorize_stmt
(Map("i", IntImm(0), Cast(i32, Arg(i64, "w")) *~ Cast(i32, Arg(i64, "h")) *~ Cast(i32, Arg(i64, "c")),
(Map("i", IntImm(0), Arg(i32, "w") *~ Arg(i32, "h") *~ Arg(i32, "c"),
store (
sadd(load, brightness)
)
Expand All @@ -35,5 +35,5 @@ let prgm =
16

let () =
Cg_llvm.codegen_to_file "brightness.bc" ([ Buffer "in"; Buffer "out"; Scalar("w", i64); Scalar("h", i64); Scalar("c", i64)], prgm)
Cg_llvm.codegen_to_file "brightness.bc" ([ Buffer "in"; Buffer "out"; Scalar("w", i32); Scalar("h", i32); Scalar("c", i32)], prgm)
(*Test_runner.main prgm "brightness"*)
7 changes: 1 addition & 6 deletions src/cg_llvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,7 @@ let codegen_c_wrapper c m f =
let args_array = param wrapper 0 in
let arg_ptr = build_gep args_array [| const_int i32_t i |] "" b in
(* deref arg pointer *)
let arg = build_load arg_ptr "" b in
(* cast to target buffer or int type for passing into im function *)
if t = buffer_t then
build_pointercast arg t "" b
else
build_intcast (build_ptrtoint arg i64_t "" b) t "" b
build_load (build_pointercast arg_ptr (pointer_type t) "" b) "" b
in

(* build inner function argument list from args array *)
Expand Down
15 changes: 13 additions & 2 deletions src/cg_test_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
#include <assert.h>
#include <png.h>

typedef union {
void* ptr;
int64_t i64;
int32_t i32;
} ArgT;

extern "C" {
void _im_main_runner(char* args[]);
void _im_main_runner(ArgT args[]);
}

#ifndef PATH_MAX
Expand Down Expand Up @@ -57,7 +63,12 @@ int main(int argc, const char* argv[]) {
out = (unsigned char*)malloc_aligned(width*height*channels);

printf("running...\n");
char* args[] = {(char*)in, (char*)out, (char*)width, (char*)height, (char*)channels};
ArgT args[5];
args[0].ptr = in;
args[1].ptr = out;
args[2].i32 = width;
args[3].i32 = height;
args[4].i32 = channels;
_im_main_runner(args);

save_png(outpath, width, height, channels, out);
Expand Down

0 comments on commit c04a6f0

Please sign in to comment.