compute offset in a cross-platform way